make ctrl-shift-v work in the terminal (paste text)

This commit is contained in:
sawka 2023-11-16 23:40:20 -08:00
parent bf03ff2591
commit e15558690f
2 changed files with 17 additions and 2 deletions

View File

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

View File

@ -61,6 +61,7 @@ class TermWrap {
onUpdateContentHeight: (termContext: RendererContext, height: number) => void;
ptyDataSource: (termContext: TermContextUnion) => Promise<PtyDataType>;
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", () => {