Skip to content

Commit 245726c

Browse files
authored
Fix cursor jumping to bottom when editor is nested inside a shadow root (#112)
This is a more robust fix for when the editor is inside the shadow dom possibly nested with other nodes between it and the root. Sorry for the @ts-ignore but TS doesn't know that document fragments have `getSelection()` See #46, #47
1 parent 2587dc3 commit 245726c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

codejar.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,8 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: P
534534
}
535535

536536
function getSelection() {
537-
if (editor.parentNode?.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
538-
return (editor.parentNode as Document).getSelection()!
539-
}
540-
return window.getSelection()!
537+
// @ts-ignore
538+
return editor.getRootNode().getSelection() as Selection
541539
}
542540

543541
return {

0 commit comments

Comments
 (0)