Skip to content

Commit 042d981

Browse files
niikmarijnh
authored andcommitted
Cancel mouse selection before swapping document
To avoid the mouse handling code getting confused
1 parent e6427cd commit 042d981

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/edit/methods.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ export default function(CodeMirror) {
423423
swapDoc: methodOp(function(doc) {
424424
let old = this.doc
425425
old.cm = null
426+
// Cancel the current text selection if any (#5821)
427+
if (this.state.selectingText) this.state.selectingText()
426428
attachDoc(this, doc)
427429
clearCaches(this)
428430
this.display.input.reset()

src/edit/mouse_events.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,13 @@ function leftButtonSelect(cm, event, start, behavior) {
305305
function done(e) {
306306
cm.state.selectingText = false
307307
counter = Infinity
308-
e_preventDefault(e)
309-
display.input.focus()
308+
// If e is null or undefined we interpret this as someone trying
309+
// to explicitly cancel the selection rather than the user
310+
// letting go of the mouse button.
311+
if (e) {
312+
e_preventDefault(e)
313+
display.input.focus()
314+
}
310315
off(display.wrapper.ownerDocument, "mousemove", move)
311316
off(display.wrapper.ownerDocument, "mouseup", up)
312317
doc.history.lastSelOrigin = null

0 commit comments

Comments
 (0)