From f3def3a7edfa6a3ca72a4300aa50f5d7afd8fd3a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 1 Sep 2015 12:58:34 -0600 Subject: [PATCH] Terminate drag on any buffer change Not just text insertion. --- spec/text-editor-component-spec.coffee | 21 ++++++++++++++++----- src/text-editor-component.coffee | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 3feb70da7..d5bc97beb 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -1898,16 +1898,13 @@ describe "TextEditorComponent", -> expect(nextAnimationFrame).toBe noAnimationFrame expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [6, 8]] - it "stops selecting if a textInput event occurs during the drag", -> + it "stops selecting before the buffer is modified during the drag", -> linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([2, 4]), which: 1)) linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([6, 8]), which: 1)) nextAnimationFrame() expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [6, 8]] - inputEvent = new Event('textInput') - inputEvent.data = 'x' - Object.defineProperty(inputEvent, 'target', get: -> componentNode.querySelector('.hidden-input')) - componentNode.dispatchEvent(inputEvent) + editor.insertText('x') nextAnimationFrame() expect(editor.getSelectedScreenRange()).toEqual [[2, 5], [2, 5]] @@ -1916,6 +1913,20 @@ describe "TextEditorComponent", -> expect(nextAnimationFrame).toBe noAnimationFrame expect(editor.getSelectedScreenRange()).toEqual [[2, 5], [2, 5]] + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([2, 4]), which: 1)) + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([5, 4]), which: 1)) + nextAnimationFrame() + expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [5, 4]] + + editor.delete() + nextAnimationFrame() + + expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [2, 4]] + + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([8, 0]), which: 1)) + expect(nextAnimationFrame).toBe noAnimationFrame + expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [2, 4]] + describe "when the command key is held down", -> it "adds a new selection and selects to the nearest screen position, then merges intersecting selections when the mouse button is released", -> editor.setSelectedScreenRange([[4, 4], [4, 9]]) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index fce46f35c..2604b5d0d 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -578,7 +578,7 @@ class TextEditorComponent window.addEventListener('mousemove', onMouseMove) window.addEventListener('mouseup', onMouseUp) disposables = new CompositeDisposable - disposables.add(@editor.onWillInsertText(onMouseUp)) + disposables.add(@editor.getBuffer().onWillChange(onMouseUp)) disposables.add(@editor.onDidDestroy(stopDragging)) isVisible: ->