Skip to content

Commit 770433e

Browse files
aomarksmarijnh
authored andcommitted
Use shadow DOM aware activeElement in contenteditable mode
Fixes cursor position reset bug when using contenteditable mode where the CodeMirror element is within a shadow root.
1 parent 8abe468 commit 770433e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/input/ContentEditableInput.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { simpleSelection } from "../model/selection.js"
1010
import { setSelection } from "../model/selection_updates.js"
1111
import { getBidiPartAt, getOrder } from "../util/bidi.js"
1212
import { android, chrome, gecko, ie_version } from "../util/browser.js"
13-
import { contains, range, removeChildrenAndAdd, selectInput } from "../util/dom.js"
13+
import { activeElt, contains, range, removeChildrenAndAdd, selectInput } from "../util/dom.js"
1414
import { on, signalDOMEvent } from "../util/event.js"
1515
import { Delayed, lst, sel_dontScroll } from "../util/misc.js"
1616

@@ -96,7 +96,7 @@ export default class ContentEditableInput {
9696
let kludge = hiddenTextarea(), te = kludge.firstChild
9797
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
9898
te.value = lastCopied.text.join("\n")
99-
let hadFocus = document.activeElement
99+
let hadFocus = activeElt()
100100
selectInput(te)
101101
setTimeout(() => {
102102
cm.display.lineSpace.removeChild(kludge)
@@ -119,7 +119,7 @@ export default class ContentEditableInput {
119119

120120
prepareSelection() {
121121
let result = prepareSelection(this.cm, false)
122-
result.focus = document.activeElement == this.div
122+
result.focus = activeElt() == this.div
123123
return result
124124
}
125125

@@ -213,7 +213,7 @@ export default class ContentEditableInput {
213213

214214
focus() {
215215
if (this.cm.options.readOnly != "nocursor") {
216-
if (!this.selectionInEditor() || document.activeElement != this.div)
216+
if (!this.selectionInEditor() || activeElt() != this.div)
217217
this.showSelection(this.prepareSelection(), true)
218218
this.div.focus()
219219
}

0 commit comments

Comments
 (0)