-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(agent-manager): restore focus to question options and prompt on session switch #12795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
21cc7b4
fix(agent-manager): restore focus to question options and prompt on s…
marius-kilocode 61467b8
fix(agent-manager): preserve tab and question focus ownership
marius-kilocode 7aff07b
fix(agent-manager): guard deferred focus during async questions
marius-kilocode 4e5b1c2
merge: resolve main conflicts for Agent Manager focus
marius-kilocode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Restore keyboard focus to the prompt or pending question when switching Agent Manager worktrees and sessions. |
56 changes: 56 additions & 0 deletions
56
packages/kilo-vscode/tests/unit/agent-manager-focus.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, expect, it } from "bun:test" | ||
| import { Window } from "happy-dom" | ||
| import { focusQuestionOption, hasQuestionOption } from "../../webview-ui/agent-manager/focus" | ||
|
|
||
| describe("Agent Manager focus", () => { | ||
| it("focuses the first enabled question option", () => { | ||
| const window = new Window() | ||
| const root = window.document.createElement("div") | ||
| const dock = window.document.createElement("div") | ||
| const disabled = window.document.createElement("button") | ||
| const option = window.document.createElement("button") | ||
| disabled.setAttribute("data-slot", "question-option") | ||
| disabled.disabled = true | ||
| option.setAttribute("data-slot", "question-option") | ||
| dock.setAttribute("data-component", "question-dock") | ||
| dock.append(disabled, option) | ||
| root.append(dock) | ||
| window.document.body.append(root) | ||
|
|
||
| expect(focusQuestionOption(root)).toBe(true) | ||
| expect(root.ownerDocument.activeElement).toBe(option) | ||
| }) | ||
|
|
||
| it("ignores collapsed question bodies", () => { | ||
| const window = new Window() | ||
| const root = window.document.createElement("div") | ||
| const dock = window.document.createElement("div") | ||
| const body = window.document.createElement("div") | ||
| const option = window.document.createElement("button") | ||
| dock.setAttribute("data-component", "question-dock") | ||
| body.setAttribute("inert", "") | ||
| option.setAttribute("data-slot", "question-option") | ||
| body.append(option) | ||
| dock.append(body) | ||
| root.append(dock) | ||
| window.document.body.append(root) | ||
|
|
||
| expect(focusQuestionOption(root)).toBe(false) | ||
| expect(root.ownerDocument.activeElement).not.toBe(option) | ||
| }) | ||
|
|
||
| it("only reports enabled options outside inert bodies", () => { | ||
| const window = new Window() | ||
| const root = window.document.createElement("div") | ||
| const dock = window.document.createElement("div") | ||
| const option = window.document.createElement("button") | ||
| dock.setAttribute("data-component", "question-dock") | ||
| option.setAttribute("data-slot", "question-option") | ||
| dock.append(option) | ||
| root.append(dock) | ||
|
|
||
| expect(hasQuestionOption(root)).toBe(true) | ||
| dock.setAttribute("inert", "") | ||
| expect(hasQuestionOption(root)).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| const OPTION = '[data-component="question-dock"] button[data-slot="question-option"]' | ||
|
|
||
| export function createChatFocus(deps: { | ||
| term: () => string | undefined | ||
| history: () => boolean | ||
| review: () => boolean | ||
| }) { | ||
| const focus = (force: boolean) => { | ||
| if ((!force && !document.hasFocus()) || deps.term() || deps.history() || deps.review()) return | ||
| if (!force && document.activeElement?.matches('[role="tab"]')) return | ||
| if (!force && document.activeElement?.closest('[data-component="question-dock"]')) return | ||
| if (focusQuestionOption()) return | ||
| const defer = hasQuestionOption() | ||
| window.dispatchEvent( | ||
| new CustomEvent("focusPrompt", { | ||
| detail: { restore: !defer, deferFocusToQuestion: defer }, | ||
| }), | ||
| ) | ||
| } | ||
| return (force = false) => { | ||
| queueMicrotask(() => focus(force)) | ||
| requestAnimationFrame(() => { | ||
| focus(force) | ||
| requestAnimationFrame(() => { | ||
| focus(force) | ||
| requestAnimationFrame(() => focus(force)) | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /** Return whether the visible question dock has an enabled option to focus. */ | ||
| export function hasQuestionOption(root: ParentNode = document): boolean { | ||
| for (const option of root.querySelectorAll<HTMLButtonElement>(OPTION)) { | ||
| if (!option.disabled && !option.closest("[inert]")) return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** Focus the first enabled option in the visible question dock, if one exists. */ | ||
| export function focusQuestionOption(root: ParentNode = document): boolean { | ||
| for (const option of root.querySelectorAll<HTMLButtonElement>(OPTION)) { | ||
| if (option.disabled || option.closest("[inert]")) continue | ||
| option.focus({ preventScroll: true }) | ||
| return true | ||
| } | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.