From 3569a11574260dc5609face8752327080fcae68c Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 15 Nov 2017 12:42:27 +0100 Subject: [PATCH] Rework didMouseDownOnContent to always position cursor --- src/text-editor-component.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 82ca7b676..da6ec452d 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1756,33 +1756,28 @@ class TextEditorComponent { } } - // On Linux, position the cursor on middle mouse button click. A - // textInput event with the contents of the selection clipboard will be - // dispatched by the browser automatically on mouseup. - if (platform === 'linux' && button === 1) { - const selection = clipboard.readText('selection') - const screenPosition = this.screenPositionForMouseEvent(event) + const screenPosition = this.screenPositionForMouseEvent(event) + + // All clicks should set the cursor position, but only left-clicks should + // have additional logic. + // On macOS, ctrl-click brings up the context menu so also handle that case. + if (button !== 0 || (platform === 'darwin' && ctrlKey)) { model.setCursorScreenPosition(screenPosition, {autoscroll: false}) - model.insertText(selection) + + // On Linux, pasting happens on middle click. A textInput event with the + // contents of the selection clipboard will be dispatched by the browser + // automatically on mouseup. + if (platform === 'linux' && button === 1) model.insertText(clipboard.readText('selection')) return } - // Only handle mousedown events for left mouse button (or the middle mouse - // button on Linux where it pastes the selection clipboard). - if (button !== 0) return - - // Ctrl-click brings up the context menu on macOS - if (platform === 'darwin' && ctrlKey) return - - const screenPosition = this.screenPositionForMouseEvent(event) - if (target && target.matches('.fold-marker')) { const bufferPosition = model.bufferPositionForScreenPosition(screenPosition) model.destroyFoldsContainingBufferPositions([bufferPosition], false) return } - const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin') + const addOrRemoveSelection = metaKey || ctrlKey switch (detail) { case 1: