From e15558690f5c072eb9817eeada89c96face3f6b3 Mon Sep 17 00:00:00 2001 From: sawka Date: Thu, 16 Nov 2023 23:40:20 -0800 Subject: [PATCH] make ctrl-shift-v work in the terminal (paste text) --- src/model/model.ts | 17 +++++++++++++++-- src/plugins/terminal/term.ts | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/model/model.ts b/src/model/model.ts index 35ae51d1..df654b42 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -762,6 +762,15 @@ class Screen { navigator.clipboard.writeText(sel); return false; } + if (e.type == "keypress" && e.code == "KeyV" && e.shiftKey && e.ctrlKey) { + e.stopPropagation(); + e.preventDefault(); + let p = navigator.clipboard.readText(); + p.then((text) => { + termWrap.dataHandler?.(text); + }); + return false; + } if (termWrap.isRunning) { return true; } @@ -3630,11 +3639,15 @@ class Model { } getCmd(line: LineType): Cmd { - let slines = this.getScreenLinesById(line.screenid); + return this.getCmdByScreenLine(line.screenid, line.lineid); + } + + getCmdByScreenLine(screenId: string, lineId: string): Cmd { + let slines = this.getScreenLinesById(screenId); if (slines == null) { return null; } - return slines.getCmd(line.lineid); + return slines.getCmd(lineId); } getActiveLine(screenId: string, lineid: string): SWLinePtr { diff --git a/src/plugins/terminal/term.ts b/src/plugins/terminal/term.ts index 38e0571c..446fb24f 100644 --- a/src/plugins/terminal/term.ts +++ b/src/plugins/terminal/term.ts @@ -61,6 +61,7 @@ class TermWrap { onUpdateContentHeight: (termContext: RendererContext, height: number) => void; ptyDataSource: (termContext: TermContextUnion) => Promise; initializing: boolean; + dataHandler?: (data: string, termWrap: TermWrap) => void; constructor(elem: Element, opts: TermWrapOpts) { opts = opts ?? ({} as any); @@ -104,6 +105,7 @@ class TermWrap { this.terminal.onKey((e) => opts.keyHandler(e, this)); } if (opts.dataHandler != null) { + this.dataHandler = opts.dataHandler; this.terminal.onData((e) => opts.dataHandler(e, this)); } this.terminal.textarea.addEventListener("focus", () => {