-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Conversation
Hi @hun1ahpu, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! 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, |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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': { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
@hun1ahpu thanks for looking into this 😃 |
@@ -165,6 +165,9 @@ suite('Workbench - TerminalConfigHelper', () => { | |||
}, | |||
shellArgs: { | |||
linux: [] | |||
}, | |||
rightClickAction: { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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."), |
There was a problem hiding this comment.
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.
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 🎆 |
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.