Skip to content

Commit

Permalink
Use shadow DOM aware activeElement in contenteditable mode
Browse files Browse the repository at this point in the history
Fixes cursor position reset bug when using contenteditable mode where the
CodeMirror element is within a shadow root.
  • Loading branch information
aomarks authored and marijnh committed Apr 10, 2021
1 parent 8abe468 commit 770433e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/input/ContentEditableInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { simpleSelection } from "../model/selection.js"
import { setSelection } from "../model/selection_updates.js"
import { getBidiPartAt, getOrder } from "../util/bidi.js"
import { android, chrome, gecko, ie_version } from "../util/browser.js"
import { contains, range, removeChildrenAndAdd, selectInput } from "../util/dom.js"
import { activeElt, contains, range, removeChildrenAndAdd, selectInput } from "../util/dom.js"
import { on, signalDOMEvent } from "../util/event.js"
import { Delayed, lst, sel_dontScroll } from "../util/misc.js"

Expand Down Expand Up @@ -96,7 +96,7 @@ export default class ContentEditableInput {
let kludge = hiddenTextarea(), te = kludge.firstChild
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
te.value = lastCopied.text.join("\n")
let hadFocus = document.activeElement
let hadFocus = activeElt()
selectInput(te)
setTimeout(() => {
cm.display.lineSpace.removeChild(kludge)
Expand All @@ -119,7 +119,7 @@ export default class ContentEditableInput {

prepareSelection() {
let result = prepareSelection(this.cm, false)
result.focus = document.activeElement == this.div
result.focus = activeElt() == this.div
return result
}

Expand Down Expand Up @@ -213,7 +213,7 @@ export default class ContentEditableInput {

focus() {
if (this.cm.options.readOnly != "nocursor") {
if (!this.selectionInEditor() || document.activeElement != this.div)
if (!this.selectionInEditor() || activeElt() != this.div)
this.showSelection(this.prepareSelection(), true)
this.div.focus()
}
Expand Down

0 comments on commit 770433e

Please sign in to comment.