mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(app): restore sideways scrolling and sticky change badges in the file tree (#58117)
This commit is contained in:
committed by
GitHub
Unverified
parent
622c74d530
commit
6214451724
@@ -472,6 +472,12 @@ test("file tree expands Windows paths and scrolls long names in both directions"
|
||||
return [
|
||||
{ ...fileNode(directory, "frontend/app.ts"), path: "frontend\\app.ts" },
|
||||
{ ...fileNode(directory, longPath), path: `frontend\\${longFilename}` },
|
||||
// Short rows below the long one, so it can scroll out of view.
|
||||
...Array.from({ length: 80 }, (_, index) => {
|
||||
const name = `file-${String(index).padStart(2, "0")}.ts`
|
||||
|
||||
return { ...fileNode(directory, `frontend/${name}`), path: `frontend\\${name}` }
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -506,13 +512,40 @@ test("file tree expands Windows paths and scrolls long names in both directions"
|
||||
const status = longRow.locator('[data-item-section="git"]')
|
||||
await expect(longRow).toBeVisible()
|
||||
await expect(content).toHaveAttribute("title", longFilename)
|
||||
await expect.poll(() => content.evaluate((element) => element.scrollWidth - element.clientWidth)).toBeGreaterThan(0)
|
||||
// The name is never clipped: the tree scrolls sideways and the change letter sticks to the pane's edge.
|
||||
await expect
|
||||
.poll(() => longRow.evaluate((element) => element.scrollWidth - element.clientWidth))
|
||||
.poll(() => content.evaluate((element) => element.scrollWidth - element.clientWidth))
|
||||
.toBeLessThanOrEqual(0)
|
||||
await expect(content).toHaveCSS("text-overflow", "clip")
|
||||
await expect
|
||||
.poll(() =>
|
||||
longRow.evaluate((element) => {
|
||||
const scroll = element.closest("[data-file-tree-virtualized-scroll]")!
|
||||
|
||||
return scroll.scrollWidth - scroll.clientWidth
|
||||
}),
|
||||
)
|
||||
.toBeGreaterThan(0)
|
||||
await expect(status).toHaveText("A")
|
||||
await expect.poll(() => statusInset(status, "right")).toBeLessThanOrEqual(24)
|
||||
const treeScroll = panel.locator(".opencode-pierre-file-tree")
|
||||
const scrollTree = (position: { left?: number; top?: number }) =>
|
||||
treeScroll.evaluate((element, position) => {
|
||||
const scroll = element.shadowRoot!.querySelector<HTMLElement>("[data-file-tree-virtualized-scroll]")!
|
||||
|
||||
if (position.left !== undefined) scroll.scrollLeft = position.left
|
||||
|
||||
if (position.top !== undefined) scroll.scrollTop = position.top
|
||||
|
||||
return { left: scroll.scrollLeft, overflow: scroll.scrollWidth - scroll.clientWidth }
|
||||
}, position)
|
||||
await scrollTree({ left: 1_000_000 })
|
||||
await expect.poll(() => statusInset(status, "right")).toBeLessThanOrEqual(24)
|
||||
// The tree keeps the long row's width after it scrolls out of view, so the sideways position holds.
|
||||
await scrollTree({ top: 1_000_000 })
|
||||
await expect(longRow).toHaveCount(0)
|
||||
await expect.poll(async () => (await scrollTree({})).overflow).toBeGreaterThan(0)
|
||||
await expect.poll(async () => (await scrollTree({})).left).toBeGreaterThan(0)
|
||||
await scrollTree({ left: 0, top: 0 })
|
||||
await viewport.evaluate((element) => element.setAttribute("dir", "rtl"))
|
||||
await expect.poll(() => statusInset(status, "left")).toBeLessThanOrEqual(24)
|
||||
await frontend.focus()
|
||||
|
||||
@@ -321,6 +321,8 @@ export function OpenInAppContextMenuV2(
|
||||
props: ParentProps<{
|
||||
state?: OpenInAppState
|
||||
resolvePath: (event: MouseEvent) => string | undefined
|
||||
/** Keeps the trigger within its container, for content that clips its own rows rather than scrolling sideways. */
|
||||
fit?: boolean
|
||||
}>,
|
||||
) {
|
||||
const state = props.state
|
||||
@@ -355,7 +357,8 @@ export function OpenInAppContextMenuV2(
|
||||
>
|
||||
<Menu.Context.Trigger
|
||||
as="div"
|
||||
class="h-full w-full min-w-max flex flex-col min-h-0 flex-1"
|
||||
class="h-full w-full flex flex-col min-h-0 flex-1"
|
||||
classList={{ "min-w-max": !props.fit, "min-w-0": props.fit }}
|
||||
data-slot="file-tree-v2-context-trigger"
|
||||
data-context-menu-open={open() ? "" : undefined}
|
||||
on:contextmenu={{
|
||||
|
||||
@@ -34,7 +34,10 @@ const TREE_UNSAFE_CSS = `
|
||||
--trees-padding-inline: 8px; --trees-item-margin-x: 0px;
|
||||
}
|
||||
[data-file-tree-virtualized-root="true"] { padding-block-start: 4px; }
|
||||
[data-file-tree-virtualized-scroll="true"] { padding-block: 0; padding-inline: 8px; overflow-x: hidden; }
|
||||
/* The patched scroll limit counts this padding and the horizontal scrollbar, so neither fights the wheel. */
|
||||
[data-file-tree-virtualized-scroll="true"] { padding-block: 0 8px; padding-inline: 8px; overflow-x: auto; }
|
||||
/* Long rows scroll sideways rather than clip; every row is as wide as the widest one seen in this row set. */
|
||||
[data-file-tree-virtualized-list="true"] { width: max-content; min-width: max(100%, var(--file-tree-min-width, 0px)); }
|
||||
[data-item-section="spacing"] {
|
||||
margin-left: 0; margin-right: 0;
|
||||
margin-inline-start: calc(var(--trees-spacing-unit) * 0.5 + 1px);
|
||||
@@ -54,31 +57,62 @@ const TREE_UNSAFE_CSS = `
|
||||
:host(:dir(rtl)) [data-type="item"][aria-expanded="false"] [data-item-section="icon"] > svg:first-child {
|
||||
transform: translateY(var(--trees-icon-nudge)) rotate(180deg);
|
||||
}
|
||||
button[data-type="item"] { box-shadow: none !important; cursor: inherit; font-weight: 500; }
|
||||
button[data-type="item"] {
|
||||
--row-overlay: transparent;
|
||||
box-shadow: none !important; cursor: inherit; font-weight: 500;
|
||||
}
|
||||
button[data-type="item"]:hover, button[data-type="item"][data-item-context-hover="true"] {
|
||||
background-color: var(--v2-overlay-simple-overlay-hover) !important;
|
||||
--row-overlay: var(--v2-overlay-simple-overlay-hover);
|
||||
background-color: var(--row-overlay) !important;
|
||||
}
|
||||
button[data-type="item"][data-item-selected="true"], button[data-type="item"][data-item-selected="true"]:hover {
|
||||
color: var(--v2-text-text-base) !important; background-color: var(--v2-overlay-simple-overlay-pressed) !important;
|
||||
--row-overlay: var(--v2-overlay-simple-overlay-pressed);
|
||||
color: var(--v2-text-text-base) !important; background-color: var(--row-overlay) !important;
|
||||
}
|
||||
button[data-type="item"]:focus-visible, button[data-type="item"][data-item-focused="true"] {
|
||||
outline: none !important; box-shadow: none !important;
|
||||
}
|
||||
button[data-type="item"]::before,
|
||||
[data-item-contains-git-change="true"]:not([data-item-git-status]) > [data-item-section="git"],
|
||||
[data-item-section="decoration"]:empty { display: none !important; }
|
||||
/* A folder holding changes keeps its lane, so the row still ends in the sticky end, but shows no dot. */
|
||||
[data-item-contains-git-change="true"]:not([data-item-git-status]) > [data-item-section="git"] > * { visibility: hidden; }
|
||||
[data-type="item"]:not([data-item-selected="true"]) > [data-item-section="icon"] > * { color: var(--v2-icon-icon-muted) !important; }
|
||||
[data-item-git-status]:not([data-item-git-status="ignored"]) > [data-item-section="content"] { color: inherit; }
|
||||
[data-item-section="content"] {
|
||||
flex: 1 1 0; min-width: 0; overflow: clip; text-overflow: clip; white-space: nowrap;
|
||||
mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
|
||||
}
|
||||
:host(:dir(rtl)) [data-item-section="content"] { mask-image: linear-gradient(to left, #000 calc(100% - 16px), transparent); }
|
||||
[data-item-section="content"] { flex: 1 0 auto; max-width: none; overflow: visible; white-space: nowrap; }
|
||||
[data-item-section="decoration"] { flex: 0 0 auto; color: var(--v2-text-text-weak, var(--v2-text-text-muted)); font-size: 12px; font-weight: 400; }
|
||||
[data-item-section="git"] {
|
||||
font-size: 11px; font-weight: 530; line-height: 1; letter-spacing: -0.04px;
|
||||
font-variant-numeric: tabular-nums lining-nums; font-feature-settings: "tnum" on, "lnum" on;
|
||||
}
|
||||
/* Every row ends in its change letter or an empty lane that sticks inside the pane while long rows scroll. It fades
|
||||
the name out over 16px and redraws the row's rounded end, so a row that runs past the pane looks like one that
|
||||
fits. */
|
||||
[data-item-section="git"] {
|
||||
position: sticky; inset-inline-end: var(--trees-item-padding-x);
|
||||
z-index: 1; align-self: stretch;
|
||||
}
|
||||
[data-item-section="git"]::before, [data-item-section="git"]::after {
|
||||
content: ""; position: absolute; inset-block: 0; z-index: -1; pointer-events: none;
|
||||
}
|
||||
/* The pane from the lane to the scroller's 8px edge, under the rounded end's corners. It stays within the row, as rows
|
||||
touch and a taller cover would paint over their neighbours. */
|
||||
[data-item-section="git"]::before {
|
||||
inset-inline: 0 calc(-1 * (var(--trees-item-padding-x) + 8px));
|
||||
background: var(--trees-bg);
|
||||
}
|
||||
/* The row from the 16px fade over the name through its rounded end. */
|
||||
[data-item-section="git"]::after {
|
||||
inset-inline: -16px calc(-1 * var(--trees-item-padding-x));
|
||||
border-start-end-radius: var(--trees-border-radius); border-end-end-radius: var(--trees-border-radius);
|
||||
background:
|
||||
linear-gradient(to right, transparent, var(--row-overlay) 16px),
|
||||
linear-gradient(to right, transparent, var(--trees-bg) 16px);
|
||||
}
|
||||
:host(:dir(rtl)) [data-item-section="git"]::after {
|
||||
background:
|
||||
linear-gradient(to left, transparent, var(--row-overlay) 16px),
|
||||
linear-gradient(to left, transparent, var(--trees-bg) 16px);
|
||||
}
|
||||
`
|
||||
|
||||
function sameStringMap(a: ReadonlyMap<string, string> | undefined, b: ReadonlyMap<string, string> | undefined) {
|
||||
@@ -164,6 +198,14 @@ export default function PierreFileTree(props: {
|
||||
let renderedKinds: ReadonlyMap<string, ChangeKind> | undefined
|
||||
let renderedIgnored: ReadonlySet<string> | undefined
|
||||
let renderedRoot = file.root
|
||||
let widthHost: HTMLElement | undefined
|
||||
let widest = 0
|
||||
|
||||
// A new row set measures from the pane's width again.
|
||||
const resetWidth = () => {
|
||||
widest = 0
|
||||
widthHost?.style.removeProperty("--file-tree-min-width")
|
||||
}
|
||||
|
||||
const originalPath = (rawPath: string) => {
|
||||
const norm = normalizeFileTreeV2Path(rawPath)
|
||||
@@ -273,6 +315,8 @@ export default function PierreFileTree(props: {
|
||||
return label ? { text: label } : null
|
||||
},
|
||||
onExpansionChange(change) {
|
||||
resetWidth()
|
||||
|
||||
if (syncingExpansion) return
|
||||
const original = originalPath(change.path)
|
||||
|
||||
@@ -285,6 +329,26 @@ export default function PierreFileTree(props: {
|
||||
if (!isLive && initialAllowed) applyAllowedCollapsed(initialAllowed)
|
||||
tree.render({ containerWrapper: wrapper })
|
||||
tree.getFileTreeContainer()?.classList.add("opencode-pierre-file-tree")
|
||||
widthHost = tree.getFileTreeContainer()
|
||||
const list = widthHost?.shadowRoot?.querySelector<HTMLElement>("[data-file-tree-virtualized-list]")
|
||||
const scroller = list?.closest<HTMLElement>("[data-file-tree-virtualized-scroll]")
|
||||
|
||||
// Only some rows render, so the list's own width follows the rows on screen. Rows wider than the pane widen the
|
||||
// tree, which keeps that width while they scroll out of view; otherwise the scroll position would snap back.
|
||||
if (list && scroller) {
|
||||
const widen = new ResizeObserver(() => {
|
||||
if (scroller.scrollWidth <= scroller.clientWidth) return
|
||||
const width = list.getBoundingClientRect().width
|
||||
|
||||
if (width <= widest) return
|
||||
widest = width
|
||||
widthHost?.style.setProperty("--file-tree-min-width", `${width}px`)
|
||||
})
|
||||
|
||||
widen.observe(list)
|
||||
onCleanup(() => widen.disconnect())
|
||||
}
|
||||
|
||||
setReady(true)
|
||||
onCleanup(() => {
|
||||
tree?.cleanUp()
|
||||
@@ -310,6 +374,7 @@ export default function PierreFileTree(props: {
|
||||
if (!tree || model === renderedAllowed) return
|
||||
renderedAllowed = model
|
||||
syncSelection("")
|
||||
resetWidth()
|
||||
tree.resetPaths(model.paths)
|
||||
applyAllowedCollapsed(model)
|
||||
syncSelection(active())
|
||||
@@ -361,7 +426,11 @@ export default function PierreFileTree(props: {
|
||||
ops.push({ type: "add", path: item })
|
||||
}
|
||||
|
||||
if (ops.length > 0) tree.batch(ops)
|
||||
if (ops.length > 0) {
|
||||
resetWidth()
|
||||
tree.batch(ops)
|
||||
}
|
||||
|
||||
syncingExpansion = true
|
||||
|
||||
for (const dir of current.model.expandedDirs) {
|
||||
@@ -449,7 +518,7 @@ export default function PierreFileTree(props: {
|
||||
}
|
||||
|
||||
return (
|
||||
<OpenInAppContextMenuV2 state={openIn} resolvePath={resolveContextPath}>
|
||||
<OpenInAppContextMenuV2 state={openIn} resolvePath={resolveContextPath} fit>
|
||||
<div
|
||||
ref={wrapper}
|
||||
data-component="file-tree-v2"
|
||||
|
||||
@@ -123,7 +123,7 @@ index 305714319d9d988bfc025ecaaca662562a3a0ff7..8ab6a7b9b7734b1fa2e17c96743eeb01
|
||||
stickyFolders: this.#viewOptions.stickyFolders
|
||||
};
|
||||
diff --git a/dist/render/FileTreeView.js b/dist/render/FileTreeView.js
|
||||
index 7d3b818c43a7621ab9170da32b180232ed3c9472..0a9a88135f89e4a5c4448964ef08dc8de26b0447 100644
|
||||
index 7d3b818c43a7621ab9170da32b180232ed3c9472..222e49fe7130452d028f4204fde57b0398ce2d34 100644
|
||||
--- a/dist/render/FileTreeView.js
|
||||
+++ b/dist/render/FileTreeView.js
|
||||
@@ -360,7 +360,7 @@ function focusFirstMenuElement(menuElement) {
|
||||
@@ -176,6 +176,24 @@ index 7d3b818c43a7621ab9170da32b180232ed3c9472..0a9a88135f89e4a5c4448964ef08dc8d
|
||||
"use no memo";
|
||||
const contextMenuAnchorRef = useRef(null);
|
||||
const contextMenuTriggerRef = useRef(null);
|
||||
@@ -653,7 +655,7 @@ function FileTreeView({ composition, controller, gitStatusByPath, ignoredGitDire
|
||||
const getTriggerAnchorButton = useCallback((path) => {
|
||||
return getContextMenuAnchorButton(path, stickyRowButtonRefs.current, rowButtonRefs.current);
|
||||
}, []);
|
||||
- const gitLaneActive = gitStatusByPath != null || ignoredGitDirectories != null || directoriesWithGitChanges != null;
|
||||
+ const gitLaneActive = true;
|
||||
const { resolveIcon } = useMemo(() => createFileTreeIconResolver(icons), [icons]);
|
||||
const renameView = controller[FILE_TREE_RENAME_VIEW]();
|
||||
const renamingPath = renameView.getPath();
|
||||
@@ -1272,7 +1274,7 @@ function FileTreeView({ composition, controller, gitStatusByPath, ignoredGitDire
|
||||
const update = () => {
|
||||
const nextItemCount = controller.getVisibleCount();
|
||||
const nextViewportHeight = getCachedViewportHeight(measuredViewportHeightRef.current, initialViewportHeight);
|
||||
- const maxScrollTop = Math.max(0, nextItemCount * itemHeight - nextViewportHeight);
|
||||
+ const maxScrollTop = Math.max(0, nextItemCount * itemHeight - nextViewportHeight, scrollElement.scrollHeight - scrollElement.clientHeight);
|
||||
if (scrollElement.scrollTop > maxScrollTop) scrollElement.scrollTop = maxScrollTop;
|
||||
setLayoutState(computeFileTreeViewLayoutState({
|
||||
controller,
|
||||
@@ -1752,6 +1754,7 @@ function FileTreeView({ composition, controller, gitStatusByPath, ignoredGitDire
|
||||
ignoredInheritanceCache,
|
||||
instanceId,
|
||||
|
||||
Reference in New Issue
Block a user