From 2204571ef5deceb0ae81595743c089a20ed83227 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 7 Apr 2014 11:10:14 -0600 Subject: [PATCH] Select words on double-click --- spec/editor-component-spec.coffee | 8 ++++++++ src/editor-component.coffee | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index e83b2f298..901db3da0 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -198,6 +198,14 @@ describe "EditorComponent", -> linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 6]), metaKey: true)) expect(editor.getSelectedScreenRanges()).toEqual [[[3, 4], [3, 4]], [[5, 6], [5, 6]]] + describe "when a non-folded line is double-clicked", -> + it "selects the word containing the nearest screen position", -> + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 2)) + expect(editor.getSelectedScreenRange()).toEqual [[5, 6], [5, 13]] + + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([6, 6]), detail: 1)) + expect(editor.getSelectedScreenRange()).toEqual [[6, 6], [6, 6]] + describe "when the mouse is clicked and dragged", -> it "selects to the nearest screen position until the mouse button is released", -> linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([2, 4]), which: 1)) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 4ae9815df..116552ffa 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -271,7 +271,7 @@ EditorCompont = React.createClass onMouseDown: (event) -> {editor} = @props - {shiftKey, metaKey} = event + {detail, shiftKey, metaKey} = event screenPosition = @screenPositionForMouseEvent(event) if shiftKey @@ -280,6 +280,8 @@ EditorCompont = React.createClass editor.addCursorAtScreenPosition(screenPosition) else editor.setCursorScreenPosition(screenPosition) + if detail is 2 + editor.selectWord() @selectToMousePositionUntilMouseUp(event)