fix(tui): preserved b before /btw completion

Reserve the plain b shortcut only after /btw has a completed answer or a branch is already pending. Running, empty, aborted, and failed panels now leave the key for the composer, while completed-but-refused branches still consume it with an explanation.

Fixes #7474
This commit is contained in:
roboomp
2026-08-03 09:33:07 +00:00
parent 98f484bd2f
commit a54a2f79cb
6 changed files with 37 additions and 7 deletions
@@ -55,6 +55,19 @@ export class BtwController {
return this.#branchUnavailableReason() === undefined;
}
/** Whether plain `b` is currently reserved for a completed or pending branch action. */
handlesBranchKey(): boolean {
if (this.#branchInFlight) return true;
if (this.#activeRequest?.component.isBranchable() !== true) return false;
return (
this.#lastQuestion !== undefined &&
this.#lastReplyText !== undefined &&
this.#lastAssistantMessage !== undefined &&
this.#lastLeafId !== undefined &&
this.#lastSessionId !== undefined
);
}
#branchUnavailableReason(): string | undefined {
if (this.#branchInFlight) return "a branch is already in progress";
if (this.#activeRequest?.component.isBranchable() !== true) return "the answer is not ready";
@@ -250,7 +250,7 @@ export class InputController {
this.#btwBranchListenerInstalled = true;
this.ctx.ui.addInputListener(data => {
if (!matchesKey(data, "b")) return undefined;
if (!this.ctx.hasActiveBtw()) return undefined;
if (!this.ctx.handlesBtwBranchKey()) return undefined;
if (this.ctx.ui.getFocused() !== this.ctx.editor) return undefined;
if (this.ctx.editor.getText().trim()) return undefined;
void this.ctx.handleBtwBranchKey();
@@ -4844,6 +4844,11 @@ export class InteractiveMode implements InteractiveModeContext {
return this.#btwController.canBranch();
}
/** Reserves plain `b` only after /btw has a completed branch action to handle. */
handlesBtwBranchKey(): boolean {
return this.#btwController.handlesBranchKey();
}
handleBtwBranchKey(): Promise<boolean> {
return this.#btwController.handleBranch();
}
+1
View File
@@ -418,6 +418,7 @@ export interface InteractiveModeContext {
handleBtwEscape(): boolean;
handleBtwBranchKey(): Promise<boolean>;
canBranchBtw(): boolean;
handlesBtwBranchKey(): boolean;
canCopyBtw(): boolean;
handleBtwCopyKey(): Promise<boolean>;
handleBtwBranch(