提交 65f38893 编写于 作者: A Adrian Wilkins

Implement a selection paste action in terminal

上级 04b92758
......@@ -423,6 +423,11 @@ export interface ITerminalInstance {
*/
paste(): Promise<void>;
/**
* Focuses and pastes the contents of the selection clipboard into the terminal instance.
*/
pasteSelection(): Promise<void>;
/**
* Send text to the terminal instance. The text is written to the stdin of the underlying pty
* process (shell) of the terminal instance.
......
......@@ -291,6 +291,24 @@ export class TerminalPasteAction extends Action {
}
}
export class TerminalPasteSelectionAction extends Action {
public static readonly ID = TERMINAL_COMMAND_ID.PASTE_SELECTION;
public static readonly LABEL = localize(TerminalPasteSelectionAction.ID, "Paste selection into Active Terminal");
public static readonly SHORT_LABEL = localize(`${TerminalPasteSelectionAction.ID}.short`, "Paste Selection")
constructor(
id: string, label: string,
@ITerminalService private readonly _terminalService: ITerminalService
) {
super(id, label);
}
async run () {
this._terminalService.getActiveOrCreateInstance()?.pasteSelection();
}
}
export class SelectDefaultShellWindowsTerminalAction extends Action {
public static readonly ID = TERMINAL_COMMAND_ID.SELECT_DEFAULT_SHELL;
......
......@@ -798,6 +798,14 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._xterm.paste(await this._clipboardService.readText());
}
public async pasteSelection(): Promise<void> {
if (!this._xterm) {
return;
}
this.focus();
this._xterm.paste(await this._clipboardService.readText("selection"));
}
public async sendText(text: string, addNewLine: boolean): Promise<void> {
// Normalize line endings to 'enter' press.
text = text.replace(TerminalInstance.EOL_REGEX, '\r');
......
......@@ -474,6 +474,7 @@ export const enum TERMINAL_COMMAND_ID {
FOCUS_NEXT = 'workbench.action.terminal.focusNext',
FOCUS_PREVIOUS = 'workbench.action.terminal.focusPrevious',
PASTE = 'workbench.action.terminal.paste',
PASTE_SELECTION = 'workbench.action.terminal.pasteSelection',
SELECT_DEFAULT_SHELL = 'workbench.action.terminal.selectDefaultShell',
RUN_SELECTED_TEXT = 'workbench.action.terminal.runSelectedText',
RUN_ACTIVE_FILE = 'workbench.action.terminal.runActiveFile',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册