// On Escape clear the editor and store the text in the history instead of doing nothing. import { CustomEditor, type ExtensionAPI, type ExtensionContext, type KeybindingsManager, } from "@earendil-works/pi-coding-agent"; import type { EditorTheme, TUI } from "@earendil-works/pi-tui"; class StashOnEscapeEditor extends CustomEditor { constructor( tui: TUI, theme: EditorTheme, private readonly keys: KeybindingsManager, private readonly ctx: ExtensionContext, ) { super(tui, theme, keys); } handleInput(data: string): void { const text = this.getExpandedText?.() ?? this.getText(); if ( this.ctx.isIdle() && text.trim() && this.keys.matches(data, "app.interrupt") ) { this.addToHistory(text); this.setText(""); return; } super.handleInput(data); } } export default function (pi: ExtensionAPI) { pi.on("session_start", (_event, ctx) => { if (ctx.mode !== "tui") return; ctx.ui.setEditorComponent( (tui, theme, keybindings) => new StashOnEscapeEditor(tui, theme, keybindings, ctx), ); }); }