From a9bcf88bfa8caba48edc03fdabb85cd6b3778afd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 5 Jan 2026 13:55:43 +0000 Subject: [PATCH] refactor(tui): use key helper predicates --- src/tui/components/custom-editor.ts | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/tui/components/custom-editor.ts b/src/tui/components/custom-editor.ts index 526584498..f9036080a 100644 --- a/src/tui/components/custom-editor.ts +++ b/src/tui/components/custom-editor.ts @@ -1,4 +1,15 @@ -import { Editor, Key, matchesKey } from "@mariozechner/pi-tui"; +import { + Editor, + isAltEnter, + isCtrlC, + isCtrlD, + isCtrlL, + isCtrlO, + isCtrlP, + isCtrlT, + isEscape, + isShiftTab, +} from "@mariozechner/pi-tui"; export class CustomEditor extends Editor { onEscape?: () => void; @@ -12,43 +23,39 @@ export class CustomEditor extends Editor { onAltEnter?: () => void; handleInput(data: string): void { - if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) { + if (isAltEnter(data) && this.onAltEnter) { this.onAltEnter(); return; } - if (matchesKey(data, Key.ctrl("l")) && this.onCtrlL) { + if (isCtrlL(data) && this.onCtrlL) { this.onCtrlL(); return; } - if (matchesKey(data, Key.ctrl("o")) && this.onCtrlO) { + if (isCtrlO(data) && this.onCtrlO) { this.onCtrlO(); return; } - if (matchesKey(data, Key.ctrl("p")) && this.onCtrlP) { + if (isCtrlP(data) && this.onCtrlP) { this.onCtrlP(); return; } - if (matchesKey(data, Key.ctrl("t")) && this.onCtrlT) { + if (isCtrlT(data) && this.onCtrlT) { this.onCtrlT(); return; } - if (matchesKey(data, Key.shift("tab")) && this.onShiftTab) { + if (isShiftTab(data) && this.onShiftTab) { this.onShiftTab(); return; } - if ( - matchesKey(data, Key.escape) && - this.onEscape && - !this.isShowingAutocomplete() - ) { + if (isEscape(data) && this.onEscape && !this.isShowingAutocomplete()) { this.onEscape(); return; } - if (matchesKey(data, Key.ctrl("c")) && this.onCtrlC) { + if (isCtrlC(data) && this.onCtrlC) { this.onCtrlC(); return; } - if (matchesKey(data, Key.ctrl("d"))) { + if (isCtrlD(data)) { if (this.getText().length === 0 && this.onCtrlD) { this.onCtrlD(); }