Spaces:
Paused
Paused
File size: 1,538 Bytes
fb4d8fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import { Editor, Key, matchesKey } from "@mariozechner/pi-tui";
export class CustomEditor extends Editor {
onEscape?: () => void;
onCtrlC?: () => void;
onCtrlD?: () => void;
onCtrlG?: () => void;
onCtrlL?: () => void;
onCtrlO?: () => void;
onCtrlP?: () => void;
onCtrlT?: () => void;
onShiftTab?: () => void;
onAltEnter?: () => void;
handleInput(data: string): void {
if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) {
this.onAltEnter();
return;
}
if (matchesKey(data, Key.ctrl("l")) && this.onCtrlL) {
this.onCtrlL();
return;
}
if (matchesKey(data, Key.ctrl("o")) && this.onCtrlO) {
this.onCtrlO();
return;
}
if (matchesKey(data, Key.ctrl("p")) && this.onCtrlP) {
this.onCtrlP();
return;
}
if (matchesKey(data, Key.ctrl("g")) && this.onCtrlG) {
this.onCtrlG();
return;
}
if (matchesKey(data, Key.ctrl("t")) && this.onCtrlT) {
this.onCtrlT();
return;
}
if (matchesKey(data, Key.shift("tab")) && this.onShiftTab) {
this.onShiftTab();
return;
}
if (matchesKey(data, Key.escape) && this.onEscape && !this.isShowingAutocomplete()) {
this.onEscape();
return;
}
if (matchesKey(data, Key.ctrl("c")) && this.onCtrlC) {
this.onCtrlC();
return;
}
if (matchesKey(data, Key.ctrl("d"))) {
if (this.getText().length === 0 && this.onCtrlD) {
this.onCtrlD();
}
return;
}
super.handleInput(data);
}
}
|