Skip to content

Commit df4cc22

Browse files
Me1000marijnh
authored andcommitted
Fix for mouse events that get sent to the wrong document when the script is being run in a different frame than the editor.
1 parent 74a71c4 commit df4cc22

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/edit/mouse_events.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
149149
let dragEnd = operation(cm, e => {
150150
if (webkit) display.scroller.draggable = false
151151
cm.state.draggingText = false
152-
off(document, "mouseup", dragEnd)
153-
off(document, "mousemove", mouseMove)
152+
off(display.wrapper.ownerDocument, "mouseup", dragEnd)
153+
off(display.wrapper.ownerDocument, "mousemove", mouseMove)
154154
off(display.scroller, "dragstart", dragStart)
155155
off(display.scroller, "drop", dragEnd)
156156
if (!moved) {
@@ -159,7 +159,7 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
159159
extendSelection(cm.doc, pos, null, null, behavior.extend)
160160
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
161161
if (webkit || ie && ie_version == 9)
162-
setTimeout(() => {document.body.focus(); display.input.focus()}, 20)
162+
setTimeout(() => {display.wrapper.ownerDocument.body.focus(); display.input.focus()}, 20)
163163
else
164164
display.input.focus()
165165
}
@@ -174,8 +174,8 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
174174
dragEnd.copy = !behavior.moveOnDrag
175175
// IE's approach to draggable
176176
if (display.scroller.dragDrop) display.scroller.dragDrop()
177-
on(document, "mouseup", dragEnd)
178-
on(document, "mousemove", mouseMove)
177+
on(display.wrapper.ownerDocument, "mouseup", dragEnd)
178+
on(display.wrapper.ownerDocument, "mousemove", mouseMove)
179179
on(display.scroller, "dragstart", dragStart)
180180
on(display.scroller, "drop", dragEnd)
181181

@@ -307,8 +307,8 @@ function leftButtonSelect(cm, event, start, behavior) {
307307
counter = Infinity
308308
e_preventDefault(e)
309309
display.input.focus()
310-
off(document, "mousemove", move)
311-
off(document, "mouseup", up)
310+
off(display.wrapper.ownerDocument, "mousemove", move)
311+
off(display.wrapper.ownerDocument, "mouseup", up)
312312
doc.history.lastSelOrigin = null
313313
}
314314

@@ -318,8 +318,8 @@ function leftButtonSelect(cm, event, start, behavior) {
318318
})
319319
let up = operation(cm, done)
320320
cm.state.selectingText = up
321-
on(document, "mousemove", move)
322-
on(document, "mouseup", up)
321+
on(display.wrapper.ownerDocument, "mousemove", move)
322+
on(display.wrapper.ownerDocument, "mouseup", up)
323323
}
324324

325325
// Used when mouse-selecting to adjust the anchor to the proper side

0 commit comments

Comments
 (0)