mirror of https://github.com/zulip/zulip.git
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:
parent
58172fe21a
commit
c750d0e404
|
@ -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 &&
|
||||
|
|
Loading…
Reference in New Issue