compose: Trim selected text before formatting.

We remove new line and space characters around the selected
text and then apply the requested formatting.
This commit is contained in:
Aman Agrawal 2021-10-01 15:46:44 +05:30 committed by Tim Abbott
parent 58172fe21a
commit c750d0e404
1 changed files with 8 additions and 1 deletions

View File

@ -227,10 +227,17 @@ export function format_text(textarea, type) {
let is_selected_text_italic = false;
let is_inner_text_italic = false;
const field = textarea.get(0);
const range = textarea.range();
let range = textarea.range();
let text = textarea.val();
const selected_text = range.text;
// Remove new line and space around selected text.
const left_trim_length = range.text.length - range.text.trimStart().length;
const right_trim_length = range.text.length - range.text.trimEnd().length;
field.setSelectionRange(range.start + left_trim_length, range.end - right_trim_length);
range = textarea.range();
const is_selection_bold = () =>
// First check if there are enough characters before/after selection.
range.start >= bold_syntax.length &&