Skip to content

Commit

Permalink
Fix bug causing a deleted editor to continue believing it had focus
Browse files Browse the repository at this point in the history
Which kept the cursor blink and input poll intervals alive, leaking
memory.

Closes #6410
  • Loading branch information
marijnh committed Sep 11, 2020
1 parent 147a2f9 commit 2250b4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/display/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getLine } from "../line/utils_line.js"
import { charCoords, cursorCoords, displayWidth, paddingH, wrappedLineExtentChar } from "../measurement/position_measurement.js"
import { getOrder, iterateBidiSections } from "../util/bidi.js"
import { elt } from "../util/dom.js"
import { onBlur } from "./focus.js"

export function updateSelection(cm) {
cm.display.input.showSelection(cm.display.input.prepareSelection())
Expand Down Expand Up @@ -151,8 +152,10 @@ export function restartBlink(cm) {
let on = true
display.cursorDiv.style.visibility = ""
if (cm.options.cursorBlinkRate > 0)
display.blinker = setInterval(() => display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden",
cm.options.cursorBlinkRate)
display.blinker = setInterval(() => {
if (!cm.hasFocus()) onBlur(cm)
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"
}, cm.options.cursorBlinkRate)
else if (cm.options.cursorBlinkRate < 0)
display.cursorDiv.style.visibility = "hidden"
}
6 changes: 4 additions & 2 deletions src/edit/CodeMirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Range } from "../model/selection.js"
import { extendSelection } from "../model/selection_updates.js"
import { ie, ie_version, mobile, webkit } from "../util/browser.js"
import { e_preventDefault, e_stop, on, signal, signalDOMEvent } from "../util/event.js"
import { bind, copyObj, Delayed } from "../util/misc.js"
import { copyObj, Delayed } from "../util/misc.js"

import { clearDragCursor, onDragOver, onDragStart, onDrop } from "./drop_events.js"
import { ensureGlobalHandlers } from "./global_events.js"
Expand Down Expand Up @@ -76,7 +76,9 @@ export function CodeMirror(place, options) {
attachDoc(this, doc)

if ((options.autofocus && !mobile) || this.hasFocus())
setTimeout(bind(onFocus, this), 20)
setTimeout(() => {
if (this.hasFocus() && !this.state.focused) onFocus(this)
}, 20)
else
onBlur(this)

Expand Down

0 comments on commit 2250b4a

Please sign in to comment.