From 2996500d9027804358b8e1a0c746ee99425dabe2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 9 Mar 2017 19:31:29 -0700 Subject: [PATCH] Handle double and triple click on lines --- spec/text-editor-component-spec.js | 24 ++++++++++++++++++++++-- src/text-editor-component.js | 13 +++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index cb86207ea..1c2286c9e 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -594,9 +594,9 @@ describe('TextEditorComponent', () => { }) describe('mouse input', () => { - it('positions the cursor on single click', async () => { + it('positions the cursor on single-click', async () => { const {component, element, editor} = buildComponent() - const {lineHeight, baseCharacterWidth} = component.measurements + const {lineHeight} = component.measurements component.didMouseDownOnLines({ detail: 1, @@ -643,6 +643,26 @@ describe('TextEditorComponent', () => { }) expect(editor.getCursorScreenPosition()).toEqual([3, 16]) }) + + it('selects words on double-click', () => { + const {component, editor} = buildComponent() + const clientX = clientLeftForCharacter(component, 1, 16) + const clientY = clientTopForLine(component, 1) + + component.didMouseDownOnLines({detail: 1, clientX, clientY}) + component.didMouseDownOnLines({detail: 2, clientX, clientY}) + expect(editor.getSelectedScreenRange()).toEqual([[1, 13], [1, 21]]) + }) + + it('selects lines on triple-click', () => { + const {component, editor} = buildComponent() + const clientX = clientLeftForCharacter(component, 1, 16) + const clientY = clientTopForLine(component, 1) + + component.didMouseDownOnLines({detail: 1, clientX, clientY}) + component.didMouseDownOnLines({detail: 2, clientX, clientY}) + expect(editor.getSelectedScreenRange()).toEqual([[1, 0], [2, 0]]) + }) }) }) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 69e03c760..be3857b00 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -736,10 +736,19 @@ class TextEditorComponent { } didMouseDownOnLines (event) { + const {model} = this.props const screenPosition = this.screenPositionForMouseEvent(event) - if (event.detail === 1) { - this.props.model.setCursorScreenPosition(screenPosition) + switch (event.detail) { + case 1: + model.setCursorScreenPosition(screenPosition) + break + case 2: + model.getLastSelection().selectWord({autoscroll: false}) + break + case 3: + model.getLastSelection().selectLine(null, {autoscroll: false}) + break } }