DEV: Create wrapper API for getCaretPosition() jQuery (#23194)

This commit is contained in:
Keegan George
2023-08-23 10:17:21 -07:00
committed by GitHub
parent d0e369946c
commit 92b2e10ee8

View File

@@ -596,3 +596,19 @@ export function mergeSortedLists(list1, list2, comparator) {
}
return merged;
}
export function getCaretPosition(element, options) {
const jqueryElement = $(element);
const position = jqueryElement.caretPosition(options);
// Get the position of the textarea on the page
const textareaRect = element.getBoundingClientRect();
// Calculate the x and y coordinates by adding the element's position
const adjustedPosition = {
x: position.left + textareaRect.left,
y: position.top + textareaRect.top,
};
return adjustedPosition;
}