mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user