Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt key should force selection #816

Merged
merged 8 commits into from Jul 28, 2017
Merged

Conversation

joaomoreno
Copy link
Contributor

@joaomoreno joaomoreno commented Jul 24, 2017

@joaomoreno
Copy link
Contributor Author

@Tyriar This is not yet done, still a WIP.

I've changed what enable() and disable() do in the SelectionManager and made them more lightweight. That way, the Alt can still force the SelectionManager to do his business, even though it is disabled. We probably need different analogy other than enabled/disabled...

I'll still need to address these questions:

  • Does this work the same on Linux?
  • What happens if alt is dropped half way through the selection?
  • Does shift+alt click expand the selection?
  • Should it be an option?

As for an option, I'd say no. I couldn't find one for iTerm.

src/xterm.js Outdated
@@ -517,7 +517,7 @@ Terminal.prototype.initGlobal = function() {
on(this.element, 'copy', event => {
// If mouse events are active it means the selection manager is disabled and
// copy should be handled by the host program.
if (this.mouseEvents) {
if (!this.selectionManager.hasSelection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either guard this call or use this.hasSelection() because this.selectionManager might not yet be available at this stage (it is only available after term.open was called).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you say this, Terminal.hasSelection should probably have a null check in it as consumers could call the API before Terminal.open.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has since #797 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps, was looking at the code from GitHub and I guess it wasn't master 😕

@Tyriar Tyriar self-requested a review July 24, 2017 17:06
@Tyriar Tyriar self-assigned this Jul 24, 2017
@Tyriar Tyriar added the work-in-progress Do not merge label Jul 24, 2017
@joaomoreno
Copy link
Contributor Author

Fixed the NPE.

Answering the questions:

  • Does this work the same on Linux?

In the Gnome terminal, the Shift key is used to escape this Mouse mode. We should make this platform dependent since in many Linux systems it seems Alt moves the window.

  • What happens if alt is dropped half way through the selection?

In the Gnome terminal, nothing really happens, the selection continues to be modified as the mouse moves. Seems like we are OK there.

  • Does shift+alt click expand the selection?

In the Gnome terminal, in such a mode, Shift no longer allows to extend a selection; every selection is a new one. This is fine by me and I propose to implement this.

  • Should it be an option?

I wouldn't make it an option.

@Tyriar @mofux OK to go ahead with these assumptions?

@joaomoreno
Copy link
Contributor Author

Also, sorry about the auto formatting. Let me know if you prefer a clean commit which doesn't format untouched code.

@mofux
Copy link
Contributor

mofux commented Jul 25, 2017

Your assumptions sound reasonable. My only slight concern is if we implement an 'altIsMeta' option in the future, this might conflict with the alt key being used for selection... but since it's only mouse interaction that shouldn't really be a problem...

@joaomoreno
Copy link
Contributor Author

Alright guys. I've pushed more changes. Tests should go green soon. Feel free to properly review and/or merge. 👍

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 69.826% when pulling 9e80a12 on joaomoreno:alt-selection into 2e9177a on sourcelair:master.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.01%) to 70.386% when pulling 9e80a12 on joaomoreno:alt-selection into 2e9177a on sourcelair:master.

} else {

// Don't send the mouse down event to the current process
event.stopPropagation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break the context menu on right click? Maybe the enabled check should be below the primary button check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

@@ -314,6 +317,17 @@ export class SelectionManager extends EventEmitter {
* @param event The mousedown event.
*/
private _onMouseDown(event: MouseEvent) {
// Ignore this event when selection is disabled
if (!this._enabled) {
if (!(Browser.isLinux ? event.shiftKey : event.altKey)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be isMac? Also the inverted ternary is pretty hard to read

@joaomoreno
Copy link
Contributor Author

Refactored a bit to accommodate for the fact that we always want the context menu to show up when there is a selection in the editor.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 70.332% when pulling 6a3b39b on joaomoreno:alt-selection into 2e9177a on sourcelair:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 70.332% when pulling 6a3b39b on joaomoreno:alt-selection into 2e9177a on sourcelair:master.

@joaomoreno
Copy link
Contributor Author

Pushed!

@Tyriar
Copy link
Member

Tyriar commented Jul 28, 2017

Looks good, I made a minor change to disable it on Linux/Windows as it will probably lead to weird behavior being on shift a that performs an incremental not a single click.

@coveralls
Copy link

coveralls commented Jul 28, 2017

Coverage Status

Coverage decreased (-0.07%) to 70.469% when pulling 3f7fec8 on joaomoreno:alt-selection into 34f075a on sourcelair:master.

@coveralls
Copy link

coveralls commented Jul 28, 2017

Coverage Status

Coverage decreased (-0.07%) to 70.469% when pulling 3f7fec8 on joaomoreno:alt-selection into 34f075a on sourcelair:master.

@Tyriar Tyriar merged commit bcff69b into xtermjs:master Jul 28, 2017
@Tyriar Tyriar removed the work-in-progress Do not merge label Jul 28, 2017
@Tyriar Tyriar added this to the 2.9.0 milestone Jul 28, 2017
@joaomoreno joaomoreno deleted the alt-selection branch August 8, 2017 07:27
@joaomoreno
Copy link
Contributor Author

@Tyriar I started selfhosting on Linux last month. Without that change, I still won't be able to select text in the terminal. 😢

Note that the shift key hijacking would only happen in a program which enabled mouse mode, thus disabling selection.

@Tyriar
Copy link
Member

Tyriar commented Aug 8, 2017

After checking now this is how it works on gnome-terminal, we should bring it back with shift for the next version. I don't think I had a Linux box with me when I was merging, sorry 🙁. Tracking in #869

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants