mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Create wrapper API for getCaretPosition() jQuery (#23194)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user