Skip to content

Right click to copy selection and paste on Windows - #17496

Merged
Daniel Imms (Tyriar) merged 5 commits into
microsoft:masterfrom
hun1ahpu:i14202
Dec 21, 2016
Merged

Daniel Imms (Tyriar) merged 5 commits into
microsoft:masterfrom
hun1ahpu:i14202

Conversation

@hun1ahpu

Copy link
Copy Markdown
Contributor

Proposal fix for #14202.
Added config setting 'rightClickAction' for all the platforms set to 'copyPaste' by default only on windows. Let me know if it makes sense at all to have this setting on other platforms or not.
Tested on Windows 10 only.

@msftclas

Hi Anton Vildyaev (@hun1ahpu), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

}

/**
* Copies the terminal selection. Note that since the command palette takes focus from the terminal,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This comment seems obsolete to me. Let me know if i'm missing something.

anchor = { x: standardEvent.posx, y: standardEvent.posy };
}
let rightClickAction: string = this._terminalService.configHelper.getRightClickAction();
if (rightClickAction === 'copyPaste') {

@hun1ahpu Anton Vildyaev (hun1ahpu) Dec 18, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of adding enum for rightClickAction but not sure it's worth it.

/**
* Copies the terminal selection. Note that since the command palette takes focus from the terminal,
* this can only be triggered via a keybinding.
* Copies the terminal selection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment is still relevant as you can't trigger it through the command palette. This is what it should probably say though:

/**
 * Copies the terminal selection. Note that since the command palette takes focus from the terminal,
 * this cannot be triggered through the command palette.
 */

},
'default': []
},
'terminal.integrated.rightClickAction.windows': {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm thinking instead of having 3 settings for each platform and using strings, instead having a single setting for all platforms that just turns on rightClickCopy/Paste. Maybe terminal.integrated.rightClickCopyPaste? Then the default could be true when platform.isWindows (put the default in terminal.ts and import it into this file).

}
} else if (rightClickAction === 'contextMenu') {
let anchor: HTMLElement | { x: number, y: number } = this._parentDomElement;
if (event instanceof MouseEvent) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't event guaranteed to be a MouseEvent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like. Didn't dare to touch this part of the code. Will remove unnecessary check. Thanks.

terminal.paste();
}
} else if (rightClickAction === 'contextMenu') {
let anchor: HTMLElement | { x: number, y: number } = this._parentDomElement;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would prefer if these were 2 different variables (if you need to store this._parentDomElement at all)

@Tyriar

Copy link
Copy Markdown
Contributor

Anton Vildyaev (@hun1ahpu) thanks for looking into this 😃

shellArgs: {
linux: []
},
rightClickAction: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These can be removed now that the setting changed.

getFont(): ITerminalFont;
getFontLigaturesEnabled(): boolean;
getCursorBlink(): boolean;
isRightClickCopyPaste(): boolean;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change this to get... like getCursorBlink

} else if (event.which === 3) {
// Trigger the context menu on right click
let anchor: HTMLElement | { x: number, y: number } = this._parentDomElement;
if (event instanceof MouseEvent) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just realized that this is actually my code haha, as long as the context menu appears in the correct spot after this change (when rightClickCopyPaste is false) then this was fine to remove 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it still works with the change

'default': []
},
'terminal.integrated.rightClickCopyPaste': {
'description': nls.localize('terminal.integrated.rightClickCopyPaste', "Controls whether copy/paste happens on mouse right click in integrated terminal."),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the description needs to be more detailed, how about this?

When set, this will prevent the context menu from appearing on right clicking in the terminal, instead it will copy when there is a selection and paste when there is no selection.

@Tyriar

Copy link
Copy Markdown
Contributor

Works great! The build is failing due to an unrelated issue so this is good to go. Thanks a lot for taking the effort to implement this 🎆

@Tyriar
Daniel Imms (Tyriar) merged commit 651c27d into microsoft:master Dec 21, 2016
@Tyriar Daniel Imms (Tyriar) added this to the January 2017 milestone Dec 21, 2016
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants