fix(coding-agent): reload keybindings on /reload closes #2309

This commit is contained in:
Mario Zechner
2026-03-17 23:59:45 +01:00
parent 3dd63848a0
commit 7eb55b08cf
5 changed files with 45 additions and 22 deletions

View File

@@ -112,10 +112,12 @@ function isAppAction(action: string): action is AppAction {
*/
export class KeybindingsManager {
private config: KeybindingsConfig;
private configPath: string | undefined;
private appActionToKeys: Map<AppAction, KeyId[]>;
private constructor(config: KeybindingsConfig) {
private constructor(config: KeybindingsConfig, configPath?: string) {
this.config = config;
this.configPath = configPath;
this.appActionToKeys = new Map();
this.buildMaps();
}
@@ -126,18 +128,8 @@ export class KeybindingsManager {
static create(agentDir: string = getAgentDir()): KeybindingsManager {
const configPath = join(agentDir, "keybindings.json");
const config = KeybindingsManager.loadFromFile(configPath);
const manager = new KeybindingsManager(config);
// Set up editor keybindings globally
// Include both editor actions and expandTools (shared between app and editor)
const editorConfig: EditorKeybindingsConfig = {};
for (const [action, keys] of Object.entries(config)) {
if (!isAppAction(action) || action === "expandTools") {
editorConfig[action as EditorAction] = keys;
}
}
setEditorKeybindings(new EditorKeybindingsManager(editorConfig));
const manager = new KeybindingsManager(config, configPath);
manager.applyEditorKeybindings();
return manager;
}
@@ -148,6 +140,13 @@ export class KeybindingsManager {
return new KeybindingsManager(config);
}
reload(): void {
if (!this.configPath) return;
this.config = KeybindingsManager.loadFromFile(this.configPath);
this.buildMaps();
this.applyEditorKeybindings();
}
private static loadFromFile(path: string): KeybindingsConfig {
if (!existsSync(path)) return {};
try {
@@ -174,6 +173,16 @@ export class KeybindingsManager {
}
}
private applyEditorKeybindings(): void {
const editorConfig: EditorKeybindingsConfig = {};
for (const [action, keys] of Object.entries(this.config)) {
if (!isAppAction(action) || action === "expandTools") {
editorConfig[action as EditorAction] = keys;
}
}
setEditorKeybindings(new EditorKeybindingsManager(editorConfig));
}
/**
* Check if input matches an app action.
*/

View File

@@ -33,6 +33,6 @@ export const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [
{ name: "new", description: "Start a new session" },
{ name: "compact", description: "Manually compact the session context" },
{ name: "resume", description: "Resume a different session" },
{ name: "reload", description: "Reload extensions, skills, prompts, and themes" },
{ name: "reload", description: "Reload keybindings, extensions, skills, prompts, and themes" },
{ name: "quit", description: "Quit pi" },
];