mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
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:
@@ -227,10 +227,17 @@ export function format_text(textarea, type) {
|
|||||||
let is_selected_text_italic = false;
|
let is_selected_text_italic = false;
|
||||||
let is_inner_text_italic = false;
|
let is_inner_text_italic = false;
|
||||||
const field = textarea.get(0);
|
const field = textarea.get(0);
|
||||||
const range = textarea.range();
|
let range = textarea.range();
|
||||||
let text = textarea.val();
|
let text = textarea.val();
|
||||||
const selected_text = range.text;
|
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 = () =>
|
const is_selection_bold = () =>
|
||||||
// First check if there are enough characters before/after selection.
|
// First check if there are enough characters before/after selection.
|
||||||
range.start >= bold_syntax.length &&
|
range.start >= bold_syntax.length &&
|
||||||
|
|||||||
Reference in New Issue
Block a user