Skip to content

Commit 9d54c7e

Browse files
committed
fix(ui): use shared keybinding manager in repo session picker
1 parent 7da340a commit 9d54c7e

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

  • pi-extensions/repo-shared-sessions

‎pi-extensions/repo-shared-sessions/index.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { ExtensionAPI, ExtensionCommandContext, SessionInfo, Theme } from "@mariozechner/pi-coding-agent";
1+
import type { ExtensionAPI, ExtensionCommandContext, KeybindingsManager, SessionInfo, Theme } from "@mariozechner/pi-coding-agent";
22
import { SessionManager } from "@mariozechner/pi-coding-agent";
3-
import { Input, getEditorKeybindings, truncateToWidth, visibleWidth, type Component, type Focusable } from "@mariozechner/pi-tui";
3+
import { Input, truncateToWidth, visibleWidth, type Component, type Focusable } from "@mariozechner/pi-tui";
44
import { basename, resolve } from "node:path";
55

66
type RepoIdentity = {
@@ -184,6 +184,7 @@ class RepoSessionSelectorComponent implements Component, Focusable {
184184
private readonly heading: string,
185185
sessions: SessionInfo[],
186186
private readonly theme: Theme,
187+
private readonly keybindings: KeybindingsManager,
187188
private readonly onSelect: (session: SessionInfo) => void,
188189
private readonly onCancel: () => void,
189190
) {
@@ -259,39 +260,37 @@ class RepoSessionSelectorComponent implements Component, Focusable {
259260
}
260261

261262
handleInput(keyData: string): void {
262-
const kb = getEditorKeybindings();
263-
264-
if (kb.matches(keyData, "selectUp")) {
263+
if (this.keybindings.matches(keyData, "tui.select.up")) {
265264
if (this.filteredCandidates.length === 0) return;
266265
this.selectedIndex = this.selectedIndex === 0 ? this.filteredCandidates.length - 1 : this.selectedIndex - 1;
267266
return;
268267
}
269268

270-
if (kb.matches(keyData, "selectDown")) {
269+
if (this.keybindings.matches(keyData, "tui.select.down")) {
271270
if (this.filteredCandidates.length === 0) return;
272271
this.selectedIndex = this.selectedIndex === this.filteredCandidates.length - 1 ? 0 : this.selectedIndex + 1;
273272
return;
274273
}
275274

276-
if (kb.matches(keyData, "selectPageUp")) {
275+
if (this.keybindings.matches(keyData, "tui.select.pageUp")) {
277276
if (this.filteredCandidates.length === 0) return;
278277
this.selectedIndex = Math.max(0, this.selectedIndex - SELECTOR_MAX_VISIBLE);
279278
return;
280279
}
281280

282-
if (kb.matches(keyData, "selectPageDown")) {
281+
if (this.keybindings.matches(keyData, "tui.select.pageDown")) {
283282
if (this.filteredCandidates.length === 0) return;
284283
this.selectedIndex = Math.min(this.filteredCandidates.length - 1, this.selectedIndex + SELECTOR_MAX_VISIBLE);
285284
return;
286285
}
287286

288-
if (kb.matches(keyData, "selectConfirm")) {
287+
if (this.keybindings.matches(keyData, "tui.select.confirm")) {
289288
const selected = this.filteredCandidates[this.selectedIndex];
290289
if (selected) this.onSelect(selected.session);
291290
return;
292291
}
293292

294-
if (kb.matches(keyData, "selectCancel")) {
293+
if (this.keybindings.matches(keyData, "tui.select.cancel")) {
295294
this.onCancel();
296295
return;
297296
}
@@ -318,11 +317,12 @@ async function pickSession(
318317
repo: RepoIdentity,
319318
sessions: SessionInfo[],
320319
): Promise<SessionInfo | undefined> {
321-
const selectedPath = await ctx.ui.custom<string | undefined>((_tui, theme, _keybindings, done) => {
320+
const selectedPath = await ctx.ui.custom<string | undefined>((_tui, theme, keybindings, done) => {
322321
return new RepoSessionSelectorComponent(
323322
`Shared sessions (${repo.display})`,
324323
sessions,
325324
theme,
325+
keybindings,
326326
(session) => done(session.path),
327327
() => done(undefined),
328328
);

0 commit comments

Comments
 (0)