mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
feat: configurable keybindings for all editor and app actions
All keybindings configurable via ~/.pi/agent/keybindings.json
Editor actions:
- cursorUp, cursorDown, cursorLeft, cursorRight
- cursorWordLeft, cursorWordRight, cursorLineStart, cursorLineEnd
- deleteCharBackward, deleteCharForward, deleteWordBackward
- deleteToLineStart, deleteToLineEnd
- newLine, submit, tab
- selectUp, selectDown, selectConfirm, selectCancel
App actions:
- interrupt, clear, exit, suspend
- cycleThinkingLevel, cycleModelForward, cycleModelBackward
- selectModel, expandTools, toggleThinking, externalEditor
Also adds support for numpad Enter key (Kitty protocol codepoint 57414
and SS3 M sequence)
Example emacs-style keybindings.json:
{
"cursorUp": ["up", "ctrl+p"],
"cursorDown": ["down", "ctrl+n"],
"cursorLeft": ["left", "ctrl+b"],
"cursorRight": ["right", "ctrl+f"],
"deleteCharForward": ["delete", "ctrl+d"],
"cycleModelForward": "ctrl+o"
}
This commit is contained in:
@@ -7,7 +7,7 @@ import { spawnSync } from "node:child_process";
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { Container, Editor, isCtrlC, isCtrlG, isEscape, Spacer, Text, type TUI } from "@mariozechner/pi-tui";
|
||||
import { Container, Editor, matchesKey, Spacer, Text, type TUI } from "@mariozechner/pi-tui";
|
||||
import { getEditorTheme, theme } from "../theme/theme.js";
|
||||
import { DynamicBorder } from "./dynamic-border.js";
|
||||
|
||||
@@ -68,13 +68,13 @@ export class HookEditorComponent extends Container {
|
||||
}
|
||||
|
||||
// Escape or Ctrl+C to cancel
|
||||
if (isEscape(keyData) || isCtrlC(keyData)) {
|
||||
if (matchesKey(keyData, "escape") || matchesKey(keyData, "ctrl+c")) {
|
||||
this.onCancelCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ctrl+G for external editor
|
||||
if (isCtrlG(keyData)) {
|
||||
if (matchesKey(keyData, "ctrl+g")) {
|
||||
this.openExternalEditor();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user