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

Right click to copy selection and paste on Windows #17496

Merged
merged 5 commits into from
Dec 21, 2016

Conversation

hun1ahpu
Copy link
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
Copy link

Hi @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;

@@ -56,8 +56,7 @@ export class KillTerminalAction extends Action {
}

/**
* Copies the terminal selection. Note that since the command palette takes focus from the terminal,
Copy link
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') {
Copy link
Contributor Author

@hun1ahpu hun1ahpu Dec 18, 2016

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.

@@ -56,8 +56,7 @@ export class KillTerminalAction extends Action {
}

/**
* 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
Member

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.
 */

@@ -72,6 +84,12 @@ configurationRegistry.registerConfiguration({
},
'default': []
},
'terminal.integrated.rightClickAction.windows': {
Copy link
Member

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
Member

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
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
Member

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
Member

Tyriar commented Dec 19, 2016

@hun1ahpu thanks for looking into this 😃

@@ -165,6 +165,9 @@ suite('Workbench - TerminalConfigHelper', () => {
},
shellArgs: {
linux: []
},
rightClickAction: {
Copy link
Member

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.

@@ -62,6 +65,7 @@ export interface ITerminalConfigHelper {
getFont(): ITerminalFont;
getFontLigaturesEnabled(): boolean;
getCursorBlink(): boolean;
isRightClickCopyPaste(): boolean;
Copy link
Member

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

@@ -149,25 +149,30 @@ export class TerminalPanel extends Panel {
// occurs on the selection itself.
this._terminalService.getActiveInstance().focus();
} 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
Member

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
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

@@ -72,6 +72,11 @@ configurationRegistry.registerConfiguration({
},
'default': []
},
'terminal.integrated.rightClickCopyPaste': {
'description': nls.localize('terminal.integrated.rightClickCopyPaste', "Controls whether copy/paste happens on mouse right click in integrated terminal."),
Copy link
Member

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
Member

Tyriar commented Dec 21, 2016

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 Tyriar merged commit 651c27d into microsoft:master Dec 21, 2016
@Tyriar Tyriar added this to the January 2017 milestone Dec 21, 2016
@hun1ahpu hun1ahpu deleted the i14202 branch December 24, 2016 13:28
@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.

None yet

3 participants