update
This commit is contained in:
@ -122,9 +122,24 @@ export class WysiwygSelection {
|
||||
range.selectNodeContents(element);
|
||||
|
||||
// Handle case where selection is in a text node that's a child of the element
|
||||
if (element.contains(selectionInfo.startContainer)) {
|
||||
// Use our Shadow DOM-aware contains method
|
||||
const isContained = this.containsAcrossShadowDOM(element, selectionInfo.startContainer);
|
||||
|
||||
console.log('getCursorPositionInElement debug:', {
|
||||
element: element.tagName,
|
||||
elementText: element.textContent,
|
||||
selectionContainer: selectionInfo.startContainer,
|
||||
selectionOffset: selectionInfo.startOffset,
|
||||
isContained,
|
||||
elementShadowRoot: element.getRootNode(),
|
||||
selectionShadowRoot: selectionInfo.startContainer.getRootNode()
|
||||
});
|
||||
|
||||
if (isContained) {
|
||||
range.setEnd(selectionInfo.startContainer, selectionInfo.startOffset);
|
||||
return range.toString().length;
|
||||
const position = range.toString().length;
|
||||
console.log('Cursor position calculated:', position);
|
||||
return position;
|
||||
} else {
|
||||
// Selection might be in shadow DOM or different context
|
||||
// Try to find the equivalent position in the element
|
||||
@ -133,8 +148,10 @@ export class WysiwygSelection {
|
||||
|
||||
// If the selection is at the beginning or end, handle those cases
|
||||
if (selectionInfo.startOffset === 0) {
|
||||
console.log('Fallback: returning 0 (beginning)');
|
||||
return 0;
|
||||
} else if (selectionInfo.startOffset === selectionText.length) {
|
||||
console.log('Fallback: returning text length:', text.length);
|
||||
return text.length;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user