import { Editor } from "@earendil-works/pi-tui";
//#region src/tui/components/custom-editor.ts
/**
* Editor with pi coding-agent–style app keybindings (KeybindingsManager + onAction).
*/
var CustomEditor = class extends Editor {
	keybindings;
	actionHandlers = /* @__PURE__ */ new Map();
	onEscape;
	onCtrlD;
	onCtrlC;
	onPasteImage;
	constructor(tui, theme, keybindings, options) {
		super(tui, theme, options);
		this.keybindings = keybindings;
	}
	onAction(action, handler) {
		this.actionHandlers.set(action, handler);
	}
	handleInput(data) {
		if (this.keybindings.matches(data, "app.clipboard.pasteImage")) {
			this.onPasteImage?.();
			return;
		}
		if (this.keybindings.matches(data, "app.interrupt")) {
			if (!this.isShowingAutocomplete()) {
				const handler = this.onEscape ?? this.actionHandlers.get("app.interrupt");
				if (handler) {
					handler();
					return;
				}
			}
			super.handleInput(data);
			return;
		}
		if (this.keybindings.matches(data, "app.exit")) {
			if (this.getText().length === 0) {
				const handler = this.onCtrlD ?? this.actionHandlers.get("app.exit");
				if (handler) handler();
				return;
			}
		}
		for (const [action, handler] of this.actionHandlers) {
			if (action === "app.interrupt" || action === "app.exit") continue;
			if (this.keybindings.matches(data, action)) {
				(action === "app.clear" ? this.onCtrlC ?? handler : handler)();
				return;
			}
		}
		super.handleInput(data);
	}
};
//#endregion
export { CustomEditor };

//# sourceMappingURL=custom-editor.js.map