-
Notifications
You must be signed in to change notification settings - Fork 28.7k
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
Changes from 1 commit
dea01a9
fc5a3b5
f2c6556
b8c9d2c
ca0dd70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
*/ |
||
*/ | ||
export class CopyTerminalSelectionAction extends Action { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,25 +149,35 @@ 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) { | ||
const standardEvent = new StandardMouseEvent(event); | ||
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 commentThe 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. |
||
let terminal = this._terminalService.getActiveInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it still works with the change |
||
if (terminal.hasSelection()) { | ||
terminal.copySelection(); | ||
terminal.clearSelection(); | ||
} else { | ||
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 commentThe 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 |
||
if (event instanceof MouseEvent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const standardEvent = new StandardMouseEvent(event); | ||
anchor = { x: standardEvent.posx, y: standardEvent.posy }; | ||
} | ||
|
||
this._contextMenuService.showContextMenu({ | ||
getAnchor: () => anchor, | ||
getActions: () => TPromise.as(this._getContextMenuActions()), | ||
getActionsContext: () => this._parentDomElement, | ||
getKeyBinding: (action) => { | ||
const opts = this._keybindingService.lookupKeybindings(action.id); | ||
if (opts.length > 0) { | ||
return opts[0]; // only take the first one | ||
this._contextMenuService.showContextMenu({ | ||
getAnchor: () => anchor, | ||
getActions: () => TPromise.as(this._getContextMenuActions()), | ||
getActionsContext: () => this._parentDomElement, | ||
getKeyBinding: (action) => { | ||
const opts = this._keybindingService.lookupKeybindings(action.id); | ||
if (opts.length > 0) { | ||
return opts[0]; // only take the first one | ||
} | ||
return null; | ||
} | ||
return null; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
})); | ||
this._register(DOM.addDisposableListener(this._parentDomElement, 'click', (event) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,9 @@ suite('Workbench - TerminalConfigHelper', () => { | |
}, | ||
shellArgs: { | ||
linux: [] | ||
}, | ||
rightClickAction: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be removed now that the setting changed. |
||
linux: 'contextMenu' | ||
} | ||
} | ||
} | ||
|
@@ -181,6 +184,9 @@ suite('Workbench - TerminalConfigHelper', () => { | |
}, | ||
shellArgs: { | ||
osx: [] | ||
}, | ||
rightClickAction: { | ||
osx: 'contextMenu' | ||
} | ||
} | ||
} | ||
|
@@ -197,6 +203,9 @@ suite('Workbench - TerminalConfigHelper', () => { | |
}, | ||
shellArgs: { | ||
windows: [] | ||
}, | ||
rightClickAction: { | ||
windows: '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'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 whenplatform.isWindows
(put the default in terminal.ts and import it into this file).