Xterm.js: [SelectionManager] Select the word underneath the cursor on contextmenu

Created on 11 Jul 2017  路  8Comments  路  Source: xtermjs/xterm.js

If a user right clicks on a word or url in the terminal, the word should be automatically selected, so it can be copied without having to select it first. This would mimic the default behaviour of Terminal.app, Chrome and most other UIs that allow text selection. I can try to create a PR with this feature if desired.

areselection help wanted typenhancement

All 8 comments

I think it would be good to support this for macOS only, a PR would be awesome! One thing to keep in mind is that it generally doesn't seem to select whitespace in the programs I tested, currently SelectionManager._selectWordAt will select whitespace so you'll need to add an extra parameter to that function or something.

I was under the assumption that this would be the default behaviour for Windows and Linux too. How about making it platform dependant by default, but configurable through a config flag?

@mofux sounds good if it's default on macOS only. It would be cool to have opt-in support on other platforms.

This is currently blocked by #780

Is it really blocked? I would have thought you'd check MouseEvent for whether it was a right click and/or listen to contextmenu?

@Tyriar I thought I would just hook into the mousedown handler of the selection manager (the part that is changed by #780), check if options.rightClickSelectsWord is true, selection is currently empty and evt.button is 2 (right mouse button) and basically trigger the same action that is done for double-click (which should select the word underneath the cursor). Then, term.defaults.rightClickSelectsWord would only be true if Browser.isMac

Right now the right click logic is contained within Clipboard.ts which is called by listening to contextmenu or mousedown depending on the browser. This should probably go inside rightClickHandler which already has the SelectionManager passed in.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

circuitry2 picture circuitry2  路  4Comments

jestapinski picture jestapinski  路  3Comments

zhangjie2012 picture zhangjie2012  路  3Comments

travisobregon picture travisobregon  路  3Comments

7PH picture 7PH  路  4Comments