Repository navigation
fix(agent-manager): preserve worktree list scroll on deletion #13429
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 | ||
| --- | ||
|
|
||
| Preserve the Agent Manager sidebar scroll position when worktrees are deleted. |
110 changes: 110 additions & 0 deletions
110
packages/kilo-vscode/tests/unit/agent-manager-sidebar-scroll.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,110 @@ | ||
| import { afterEach, describe, expect, it } from "bun:test" | ||
| import { Window } from "happy-dom" | ||
| import { createSidebarScrollPreserver } from "../../webview-ui/agent-manager/sidebar-scroll" | ||
|
|
||
| const window = new Window() | ||
| const frames = new Map<number, FrameRequestCallback>() | ||
| let id = 0 | ||
|
|
||
| function schedule(fn: FrameRequestCallback) { | ||
| const next = ++id | ||
| frames.set(next, fn) | ||
| return next | ||
| } | ||
|
|
||
| function cancel(id: number) { | ||
| frames.delete(id) | ||
| } | ||
|
|
||
| function preserver() { | ||
| return createSidebarScrollPreserver(window.document, schedule, cancel) | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| window.document.body.innerHTML = "" | ||
| frames.clear() | ||
| id = 0 | ||
| }) | ||
|
|
||
| function list(cls = "am-worktree-list") { | ||
| const el = window.document.createElement("div") | ||
| el.className = cls | ||
| Object.defineProperty(el, "scrollTop", { configurable: true, value: 0, writable: true }) | ||
| window.document.body.append(el) | ||
| return el | ||
| } | ||
|
|
||
| function flush() { | ||
| for (let i = 0; i < 2; i++) { | ||
| const next = frames.entries().next().value | ||
| if (!next) return | ||
| frames.delete(next[0]) | ||
| next[1](0) | ||
| } | ||
| } | ||
|
|
||
| describe("Agent Manager sidebar scroll preservation", () => { | ||
| it("restores the scroll offset after the state update has rendered", () => { | ||
| const el = list() | ||
| el.scrollTop = 240 | ||
| const preserve = preserver() | ||
|
|
||
| preserve(() => { | ||
| el.scrollTop = 0 | ||
| }) | ||
|
|
||
| expect(el.scrollTop).toBe(0) | ||
| flush() | ||
| expect(el.scrollTop).toBe(240) | ||
| }) | ||
|
|
||
| it("tracks project and worktree scroll owners independently", () => { | ||
| const projects = list("am-projects-list") | ||
| const worktrees = list() | ||
| projects.scrollTop = 120 | ||
| worktrees.scrollTop = 80 | ||
| const preserve = preserver() | ||
|
|
||
| preserve(() => { | ||
| projects.scrollTop = 0 | ||
| worktrees.scrollTop = 0 | ||
| }) | ||
| flush() | ||
|
|
||
| expect(projects.scrollTop).toBe(120) | ||
| expect(worktrees.scrollTop).toBe(80) | ||
| }) | ||
|
|
||
| it("cancels stale restores when a newer state arrives", () => { | ||
| const el = list() | ||
| const preserve = preserver() | ||
| el.scrollTop = 120 | ||
|
|
||
| preserve(() => { | ||
| el.scrollTop = 0 | ||
| }) | ||
| el.scrollTop = 210 | ||
| preserve(() => { | ||
| el.scrollTop = 0 | ||
| }) | ||
| flush() | ||
|
|
||
| expect(el.scrollTop).toBe(210) | ||
| expect(frames.size).toBe(0) | ||
| }) | ||
|
|
||
| it("does not restore a container that was removed by the update", () => { | ||
| const el = list() | ||
| el.scrollTop = 160 | ||
| const preserve = preserver() | ||
|
|
||
| preserve(() => { | ||
| el.remove() | ||
| el.scrollTop = 0 | ||
| }) | ||
| flush() | ||
|
|
||
| expect(el.isConnected).toBe(false) | ||
| expect(el.scrollTop).toBe(0) | ||
| }) | ||
| }) |
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
35 changes: 35 additions & 0 deletions
35
packages/kilo-vscode/webview-ui/agent-manager/sidebar-scroll.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,35 @@ | ||
| type Entry = { | ||
| el: HTMLElement | ||
| top: number | ||
| } | ||
|
|
||
| export function createSidebarScrollPreserver( | ||
| root: ParentNode = document, | ||
| schedule: typeof requestAnimationFrame = requestAnimationFrame, | ||
| cancel: typeof cancelAnimationFrame = cancelAnimationFrame, | ||
| ) { | ||
| let frame: number | undefined | ||
| let inner: number | undefined | ||
|
|
||
| return (fn: () => void): void => { | ||
| if (frame !== undefined) cancel(frame) | ||
| if (inner !== undefined) cancel(inner) | ||
|
|
||
| const scrolls: Entry[] = [...root.querySelectorAll<HTMLElement>(".am-worktree-list, .am-projects-list")].map( | ||
| (el) => ({ | ||
| el, | ||
| top: el.scrollTop, | ||
| }), | ||
| ) | ||
| fn() | ||
| frame = schedule(() => { | ||
| frame = undefined | ||
| inner = schedule(() => { | ||
| inner = undefined | ||
| for (const item of scrolls) { | ||
| if (item.el.isConnected) item.el.scrollTop = item.top | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
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.