2026-01-20 14:31:28 +00:00
|
|
|
import { Editor, type EditorTheme, Key, matchesKey } from "@mariozechner/pi-tui";
|
2026-01-03 06:22:20 +01:00
|
|
|
|
|
|
|
|
export class CustomEditor extends Editor {
|
|
|
|
|
onEscape?: () => void;
|
|
|
|
|
onCtrlC?: () => void;
|
|
|
|
|
onCtrlD?: () => void;
|
2026-01-09 00:53:11 +01:00
|
|
|
onCtrlG?: () => void;
|
2026-01-03 06:22:20 +01:00
|
|
|
onCtrlL?: () => void;
|
|
|
|
|
onCtrlO?: () => void;
|
|
|
|
|
onCtrlP?: () => void;
|
|
|
|
|
onCtrlT?: () => void;
|
|
|
|
|
onShiftTab?: () => void;
|
|
|
|
|
onAltEnter?: () => void;
|
|
|
|
|
|
2026-01-20 14:31:28 +00:00
|
|
|
constructor(theme: EditorTheme) {
|
|
|
|
|
super(theme);
|
2026-01-20 14:02:36 +00:00
|
|
|
}
|
2026-01-03 06:22:20 +01:00
|
|
|
handleInput(data: string): void {
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onAltEnter();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("l")) && this.onCtrlL) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onCtrlL();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("o")) && this.onCtrlO) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onCtrlO();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("p")) && this.onCtrlP) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onCtrlP();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-09 00:53:11 +01:00
|
|
|
if (matchesKey(data, Key.ctrl("g")) && this.onCtrlG) {
|
|
|
|
|
this.onCtrlG();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("t")) && this.onCtrlT) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onCtrlT();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.shift("tab")) && this.onShiftTab) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onShiftTab();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-14 14:31:43 +00:00
|
|
|
if (matchesKey(data, Key.escape) && this.onEscape && !this.isShowingAutocomplete()) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onEscape();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("c")) && this.onCtrlC) {
|
2026-01-03 06:22:20 +01:00
|
|
|
this.onCtrlC();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-05 13:59:50 +00:00
|
|
|
if (matchesKey(data, Key.ctrl("d"))) {
|
2026-01-03 06:22:20 +01:00
|
|
|
if (this.getText().length === 0 && this.onCtrlD) {
|
|
|
|
|
this.onCtrlD();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
super.handleInput(data);
|
|
|
|
|
}
|
|
|
|
|
}
|