MCPcopy Create free account
hub / github.com/UI5/webcomponents / getCaretPosition

Function getCaretPosition

packages/base/src/util/Caret.ts:5–14  ·  view source on GitHub ↗
(field: HTMLInputElement)

Source from the content-addressed store, hash-verified

3 * Return value range is 0-field.value.length.
4 */
5const getCaretPosition = (field: HTMLInputElement): number | null => {
6 // Initialize
7 let caretPos: number | null = 0;
8
9 if (field.selectionStart || field.selectionStart === 0) { // Firefox support
10 caretPos = field.selectionDirection === "backward" ? field.selectionStart : field.selectionEnd;
11 }
12
13 return caretPos;
14};
15
16const setCaretPosition = (field: HTMLInputElement, caretPos: number | null) => {
17 if (field.selectionStart) {

Callers 1

getCaretPositionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…