mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 04:12:02 +00:00
ui_util: Update place_caret_at_end to also work for input fields.
Previously, `place_caret_at_end` was only used for HTMLElement with contenteditable="true", updated it so it takes HTMLElement as argument and use logic to place cursor at end as per type of element passed(i.e HTMLElement or HTMLInputElement).
This commit is contained in:
committed by
Tim Abbott
parent
f0ef0f7157
commit
17ae99f436
@@ -9,13 +9,16 @@ import * as keydown_util from "./keydown_util";
|
||||
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
|
||||
export function place_caret_at_end(el: HTMLElement): void {
|
||||
el.focus();
|
||||
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.collapse(false);
|
||||
const sel = window.getSelection();
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
if (el instanceof HTMLInputElement) {
|
||||
el.setSelectionRange(el.value.length, el.value.length);
|
||||
} else {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.collapse(false);
|
||||
const sel = window.getSelection();
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
}
|
||||
}
|
||||
|
||||
export function blur_active_element(): void {
|
||||
|
||||
Reference in New Issue
Block a user