compose: Add parameter replace_all to insert_and_scroll_into_view.

We refactor the `insert_and_scroll_into_view` function to accept a new
parameter, `replace_all`, defaulting to false, that when set to `true`,
will replace all existing content of the textarea with the new content,
instead of inserting the new content at the current cursor position.

This is a prep commit for the next commit, which will set this new flag.
This commit is contained in:
N-Shar-ma
2024-03-05 05:09:41 +05:30
committed by Tim Abbott
parent ad2e176625
commit ef0be22899

View File

@@ -68,9 +68,15 @@ export function autosize_textarea($textarea: JQuery<HTMLTextAreaElement>): void
export function insert_and_scroll_into_view(
content: string,
$textarea: JQuery<HTMLTextAreaElement>,
replace_all = false,
): void {
insertTextIntoField($textarea[0], content);
// Blurring and refocusing ensures the cursor / selection is in view.
if (replace_all) {
setFieldText($textarea[0], content);
} else {
insertTextIntoField($textarea[0], content);
}
// Blurring and refocusing ensures the cursor / selection is in view
// in chromium browsers.
$textarea.trigger("blur");
$textarea.trigger("focus");
autosize_textarea($textarea);