fix(diff-comments): scroll diff to clicked note, drop sidebar pencil (#1605)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Brennan Benson
2026-05-08 23:00:50 -07:00
committed by GitHub
co-authored by Orca
parent 318e2b4c2c
commit 3dc5708eb3
6 changed files with 281 additions and 133 deletions
@@ -21,12 +21,6 @@ type Props = {
// grows, so the parent decorator passes a callback we fire on resize and
// it re-syncs the zone height. Without this the editor inputs would clip.
onContentResize?: () => void
// Why: the SourceControl sidebar can request that a specific card open
// its editor. The decorator forwards that pending id; when it matches,
// we enter edit mode on the next render and acknowledge so the request
// doesn't fire repeatedly.
pendingEdit?: boolean
onPendingEditConsumed?: () => void
onSubmitEdit?: (body: string) => Promise<boolean>
}
@@ -35,8 +29,6 @@ export function DiffCommentCard({
body,
onDelete,
onContentResize,
pendingEdit,
onPendingEditConsumed,
onSubmitEdit
}: Props): React.JSX.Element {
const [editing, setEditing] = useState(false)
@@ -44,40 +36,6 @@ export function DiffCommentCard({
const [submitting, setSubmitting] = useState(false)
const textareaRef = useRef<HTMLTextAreaElement | null>(null)
// Why: stash the consumed callback in a ref so the effect below doesn't
// re-run every parent render (the decorator passes a fresh arrow each time).
// Without this, an unrelated re-render with `pendingEdit=true` still in props
// would re-fire the effect after `editing` flipped to false from Cancel,
// re-entering edit mode against the user's intent.
const onPendingEditConsumedRef = useRef(onPendingEditConsumed)
onPendingEditConsumedRef.current = onPendingEditConsumed
// Why: ack each `pendingEdit` activation exactly once. The effect's
// `editing` and `body` deps cause re-entry after `setEditing(true)` lands or
// when an external edit lands mid-request; without this guard ack would fire
// multiple times per request, producing redundant `setEditingDiffCommentId`
// store writes and re-render churn.
const ackedPendingEditRef = useRef(false)
// Why: enter edit mode when the sidebar requests it via the UI slice. The
// ack callback clears the pending id so re-clicking after cancel works. Ack
// also fires when the card is already editing — otherwise a same-id re-
// request from the sidebar would leave the global state stuck.
useEffect(() => {
if (!pendingEdit) {
ackedPendingEditRef.current = false
return
}
if (ackedPendingEditRef.current) {
return
}
ackedPendingEditRef.current = true
if (!editing) {
setEditing(true)
setDraft(body)
}
onPendingEditConsumedRef.current?.()
}, [pendingEdit, editing, body])
// Why: keep the draft in sync with external body changes when not actively
// editing, so a concurrent agent edit (or a delete + recreate) is visible
// the next time the user opens the editor.
@@ -25,12 +25,12 @@ type DecoratorArgs = {
// diffs persisted to WorktreeMeta). GitHub PR review surfaces don't pass
// this — their notes are remote and can't be edited via this slice.
onUpdateComment?: (commentId: string, body: string) => Promise<boolean>
// Why: pending-edit request from the SourceControl sidebar. When this id
// matches a card the card auto-enters its inline editor on the next render.
// The decorator forwards it through; the card calls the ack callback so we
// know to stop forcing the editor open on subsequent renders.
pendingEditCommentId?: string | null
onPendingEditConsumed?: () => void
// Why: pending-scroll request from the SourceControl sidebar. When this id
// matches a comment in this surface the decorator reveals that line in the
// editor and calls the ack callback so the same id can be requested again
// later without the surface seeing a stale value.
pendingScrollCommentId?: string | null
onPendingScrollConsumed?: () => void
}
type ZoneEntry = {
@@ -43,12 +43,13 @@ type ZoneEntry = {
delegate: monacoEditor.IViewZone
root: Root
lastBody: string
// Why: track the last `pendingEdit` prop we rendered so the patch loop
// re-renders whenever it transitions. Without this, after the card acks the
// pending request (clearing the global to null), the decorator's next pass
// would skip the re-render — the card keeps `pendingEdit=true` in props, and
// a later `editing=false` toggle would re-trigger its open-editor effect.
lastPendingEdit: boolean
// Why: Monaco invokes IViewZone.onDomNodeTop on every render once the zone
// is in the layout. The first invocation is our deterministic "this zone is
// now part of the editor's vertical layout" signal — equivalent in role to
// VS Code's commentsController._computeAndSetPromise resolving before
// revealCommentThread runs. We use it to gate scroll-to-note instead of
// polling getTopForLineNumber until the value changes.
laidOut: boolean
}
// Why: card chrome (header/meta/border/padding) plus per-line body height. Used
@@ -67,8 +68,8 @@ export function useDiffCommentDecorator({
onAddCommentClick,
onDeleteComment,
onUpdateComment,
pendingEditCommentId,
onPendingEditConsumed
pendingScrollCommentId,
onPendingScrollConsumed
}: DecoratorArgs): void {
const hoverLineRef = useRef<number | null>(null)
// Why: one React root per view zone. Body updates re-render into the
@@ -77,6 +78,21 @@ export function useDiffCommentDecorator({
// hand-built DOM implementation.
const zonesRef = useRef<Map<string, ZoneEntry>>(new Map())
const disposablesRef = useRef<IDisposable[]>([])
// Why: holds the comment id the sidebar last asked us to scroll to. We
// resolve it in two places — when the zone is created and Monaco's
// onDomNodeTop fires, and when the request arrives after the zone is
// already laid out — and clear it both times via the resolver. Using a
// ref (instead of a state-driven effect that re-runs) means the request
// survives across the renders that happen while we wait for layout, and
// the resolver is the only place that produces the scroll + ack.
const pendingScrollRef = useRef<string | null>(null)
// Why: the diff-zones effect builds a `scrollToZone(commentId)` closure
// that has access to `editor` and the live zones Map. The request-effect
// (further below) needs to invoke it when a request arrives after the
// zone is already laid out. Stashing the closure in a ref lets the
// request-effect call the latest version without restructuring the
// diff-zones effect into a hook-level helper.
const scrollToZoneRef = useRef<((commentId: string) => void) | null>(null)
// Why: stash the consumer callbacks in refs so the decorator effect's
// cleanup does not run on every parent render. The parent passes inline
// arrow functions; without this, each render would tear down and re-attach
@@ -84,11 +100,11 @@ export function useDiffCommentDecorator({
const onAddCommentClickRef = useRef(onAddCommentClick)
const onDeleteCommentRef = useRef(onDeleteComment)
const onUpdateCommentRef = useRef(onUpdateComment)
const onPendingEditConsumedRef = useRef(onPendingEditConsumed)
const onPendingScrollConsumedRef = useRef(onPendingScrollConsumed)
onAddCommentClickRef.current = onAddCommentClick
onDeleteCommentRef.current = onDeleteComment
onUpdateCommentRef.current = onUpdateComment
onPendingEditConsumedRef.current = onPendingEditConsumed
onPendingScrollConsumedRef.current = onPendingScrollConsumed
useEffect(() => {
if (!editor) {
@@ -275,6 +291,10 @@ export function useDiffCommentDecorator({
entry.root.unmount()
}
zones.clear()
// Why: editor went away — drop both the in-flight scroll request and
// the resolver closure (which captured the now-disposed editor).
pendingScrollRef.current = null
scrollToZoneRef.current = null
}
}, [addButtonLabel, editor])
@@ -319,6 +339,39 @@ export function useDiffCommentDecorator({
})
}
// Why: one-shot scroll resolver. Called by both the request-arrives-late
// path and the layout-settles-late path, so the math + ack live in one
// place. Reads `getTopForLineNumber(line, /* includeZones */ true)` so the
// viewport centers on the line+card pair (the card sits in a view zone
// above the line). VS Code's commentThreadZoneWidget._goToComment uses
// `false` because it then adds (commentCoords.top - threadCoords.top) to
// pick a specific comment within a multi-comment thread; our notes are
// single-comment threads and we want the card visible, so centering on
// the zones-aware offset is the correct equivalent.
//
// The rAF defer is intentional: DiffViewer.handleMount schedules
// `restoreViewState` via rAF on a fresh mount, and that runs in the same
// frame this resolver could fire from onDomNodeTop. Deferring one frame
// guarantees we run after restoreViewState, so its cached scroll doesn't
// snap the editor back from the requested note.
const scrollToZone = (commentId: string): void => {
requestAnimationFrame(() => {
const entry = zones.get(commentId)
if (!entry || !editor.getModel()) {
return
}
if (pendingScrollRef.current !== commentId) {
return
}
const top = editor.getTopForLineNumber(entry.delegate.afterLineNumber, true)
const editorHeight = editor.getLayoutInfo().height
editor.setScrollTop(Math.max(0, top - editorHeight / 2))
pendingScrollRef.current = null
onPendingScrollConsumedRef.current?.()
})
}
scrollToZoneRef.current = scrollToZone
// Why: render helper used by BOTH the new-zone branch and the patch-
// existing-zone branch so the card's prop wiring stays in lockstep — any
// future prop is added once.
@@ -340,8 +393,6 @@ export function useDiffCommentDecorator({
: undefined
}
onContentResize={() => resizeZone(comment.id)}
pendingEdit={pendingEditCommentId === comment.id}
onPendingEditConsumed={() => onPendingEditConsumedRef.current?.()}
/>
)
}
@@ -355,6 +406,12 @@ export function useDiffCommentDecorator({
accessor.removeZone(entry.zoneId)
rootsToUnmount.push(entry.root)
zones.delete(commentId)
// Why: if the user requested a scroll-to-note on a comment that
// was just deleted, drop the request so a future zone with the
// same id (unlikely but possible) doesn't pick up a stale request.
if (pendingScrollRef.current === commentId) {
pendingScrollRef.current = null
}
}
}
@@ -389,11 +446,30 @@ export function useDiffCommentDecorator({
// mousedown and routes it to the editor, so the Delete button never
// fires. The delete/body mousedown listeners stopPropagation so the
// editor still doesn't steal focus on interaction.
const commentId = c.id
const delegate: monacoEditor.IViewZone = {
afterLineNumber: c.lineNumber,
heightInPx,
domNode: dom,
suppressMouseDown: false
suppressMouseDown: false,
// Why: Monaco invokes onDomNodeTop on every render once the zone is
// part of the layout (see vscode viewZones.ts render()). The first
// call is our deterministic "this zone is now placed" signal. If a
// sidebar scroll-to-note request was waiting on this comment, we
// resolve it here. We also flip `laidOut` so the request-effect
// path can scroll synchronously when the request arrives after the
// zone is already laid out.
onDomNodeTop: () => {
const entry = zones.get(commentId)
if (!entry) {
return
}
const wasLaidOut = entry.laidOut
entry.laidOut = true
if (!wasLaidOut && pendingScrollRef.current === commentId) {
scrollToZone(commentId)
}
}
}
const zoneId = accessor.addZone(delegate)
zones.set(c.id, {
@@ -402,7 +478,7 @@ export function useDiffCommentDecorator({
delegate,
root,
lastBody: c.body,
lastPendingEdit: pendingEditCommentId === c.id
laidOut: false
})
}
@@ -413,17 +489,11 @@ export function useDiffCommentDecorator({
if (!entry) {
continue
}
const nextPendingEdit = pendingEditCommentId === c.id
// Why: re-render when body OR pending-edit state changed. Skipping on
// the body alone left a stale `pendingEdit=true` in the card's props
// after ack, which then re-triggered the open-editor effect on the
// next `editing` toggle (Cancel re-entered edit mode).
if (entry.lastBody === c.body && entry.lastPendingEdit === nextPendingEdit) {
if (entry.lastBody === c.body) {
continue
}
renderCard(entry.root, c)
entry.lastBody = c.body
entry.lastPendingEdit = nextPendingEdit
}
})
@@ -441,5 +511,44 @@ export function useDiffCommentDecorator({
// forcing a full rebuild — exactly the flicker this diff-based pass is
// meant to avoid. Zone teardown lives in the editor-scoped effect above,
// which only fires when the editor itself is replaced/unmounted.
}, [editor, filePath, worktreeId, comments, pendingEditCommentId])
}, [editor, filePath, worktreeId, comments])
// Why: route a sidebar scroll-to-note request into the decorator. We mirror
// VS Code's commentsController.revealCommentThread (which awaits
// `_computeAndSetPromise` before scrolling) by splitting resolution between
// two places: this effect for requests that arrive after the zone is laid
// out, and the zone's `onDomNodeTop` callback for requests that arrive
// before. `pendingScrollRef` carries the id between them; whoever resolves
// first scrolls and clears the ref via `scrollToZoneRef.current(id)`.
useEffect(() => {
if (!editor) {
return
}
// Why: a null request (parent cleared the global, or routed away from
// diff) must drop any in-flight pending id so a late onDomNodeTop on a
// previously-requested zone doesn't snap-scroll the user.
if (!pendingScrollCommentId) {
pendingScrollRef.current = null
return
}
const target = comments.find(
(c) =>
c.id === pendingScrollCommentId && c.filePath === filePath && c.worktreeId === worktreeId
)
if (!target) {
// Why: the request is for a comment this decorator doesn't own (different
// file/worktree). Drop any prior pending id so a late onDomNodeTop on a
// previously-requested zone in this decorator can't fire scrollToZone and
// ack — which would clear the global request meant for the owning surface.
pendingScrollRef.current = null
return
}
pendingScrollRef.current = pendingScrollCommentId
const entry = zonesRef.current.get(pendingScrollCommentId)
if (entry?.laidOut) {
scrollToZoneRef.current?.(pendingScrollCommentId)
}
// If !laidOut we wait — onDomNodeTop on the zone will pick the request
// up and call scrollToZone once Monaco's render pass places the zone.
}, [editor, comments, pendingScrollCommentId, filePath, worktreeId])
}
@@ -78,8 +78,8 @@ export function DiffSectionItem({
const addDiffComment = useAppStore((s) => s.addDiffComment)
const deleteDiffComment = useAppStore((s) => s.deleteDiffComment)
const updateDiffComment = useAppStore((s) => s.updateDiffComment)
const editingDiffCommentId = useAppStore((s) => s.editingDiffCommentId)
const setEditingDiffCommentId = useAppStore((s) => s.setEditingDiffCommentId)
const scrollToDiffCommentId = useAppStore((s) => s.scrollToDiffCommentId)
const setScrollToDiffCommentId = useAppStore((s) => s.setScrollToDiffCommentId)
// Why: subscribe to the raw comments array on the worktree (reference-
// stable across unrelated store updates) and filter by filePath inside a
// memo. Selecting a fresh `.filter(...)` result would invalidate on every
@@ -128,15 +128,15 @@ export function DiffSectionItem({
useEffect(() => () => disposeDiffModels(), [disposeDiffModels])
// Why: only forward the pending edit id when it matches a comment in this
// Why: only forward the pending scroll id when it matches a comment in this
// section so unrelated sections don't keep re-rendering their decorator
// every time the sidebar requests an edit elsewhere.
const pendingEditForThisSection = useMemo(() => {
if (!editingDiffCommentId) {
// every time the sidebar requests a scroll elsewhere.
const pendingScrollForThisSection = useMemo(() => {
if (!scrollToDiffCommentId) {
return null
}
return diffComments.some((c) => c.id === editingDiffCommentId) ? editingDiffCommentId : null
}, [editingDiffCommentId, diffComments])
return diffComments.some((c) => c.id === scrollToDiffCommentId) ? scrollToDiffCommentId : null
}, [scrollToDiffCommentId, diffComments])
useDiffCommentDecorator({
editor: modifiedEditor,
@@ -146,8 +146,8 @@ export function DiffSectionItem({
onAddCommentClick: ({ lineNumber, top }) => setPopover({ lineNumber, top }),
onDeleteComment: (id) => void deleteDiffComment(worktreeId, id),
onUpdateComment: (id, body) => updateDiffComment(worktreeId, id, body),
pendingEditCommentId: pendingEditForThisSection,
onPendingEditConsumed: () => setEditingDiffCommentId(null)
pendingScrollCommentId: pendingScrollForThisSection,
onPendingScrollConsumed: () => setScrollToDiffCommentId(null)
})
useEffect(() => {
@@ -61,8 +61,8 @@ export default function DiffViewer({
const addDiffComment = useAppStore((s) => s.addDiffComment)
const deleteDiffComment = useAppStore((s) => s.deleteDiffComment)
const updateDiffComment = useAppStore((s) => s.updateDiffComment)
const editingDiffCommentId = useAppStore((s) => s.editingDiffCommentId)
const setEditingDiffCommentId = useAppStore((s) => s.setEditingDiffCommentId)
const scrollToDiffCommentId = useAppStore((s) => s.scrollToDiffCommentId)
const setScrollToDiffCommentId = useAppStore((s) => s.setScrollToDiffCommentId)
// Why: subscribe to the raw comments array on the worktree so selector
// identity only changes when diffComments actually changes on this worktree.
// Filtering by relativePath happens in a memo below.
@@ -92,15 +92,15 @@ export default function DiffViewer({
const hasLineCommentAction = Boolean(worktreeId || onAddLineComment)
// Why: only forward the pending edit id when this viewer owns the matching
// Why: only forward the pending scroll id when this viewer owns the matching
// comment (worktree+path). Otherwise unrelated viewers would also try to
// open the editor and ack the request first, racing the intended viewer.
const pendingEditForThisViewer = useMemo(() => {
if (!worktreeId || !editingDiffCommentId) {
// scroll and ack the request first, racing the intended viewer.
const pendingScrollForThisViewer = useMemo(() => {
if (!worktreeId || !scrollToDiffCommentId) {
return null
}
return diffComments.some((c) => c.id === editingDiffCommentId) ? editingDiffCommentId : null
}, [editingDiffCommentId, diffComments, worktreeId])
return diffComments.some((c) => c.id === scrollToDiffCommentId) ? scrollToDiffCommentId : null
}, [scrollToDiffCommentId, diffComments, worktreeId])
// Why: gate the decorator on having a comment target. Local diffs persist
// notes to worktree metadata; GitHub PR diffs post line comments remotely.
@@ -119,8 +119,8 @@ export default function DiffViewer({
}
},
onUpdateComment: worktreeId ? (id, body) => updateDiffComment(worktreeId, id, body) : undefined,
pendingEditCommentId: pendingEditForThisViewer,
onPendingEditConsumed: () => setEditingDiffCommentId(null)
pendingScrollCommentId: pendingScrollForThisViewer,
onPendingScrollConsumed: () => setScrollToDiffCommentId(null)
})
useEffect(() => {
@@ -228,9 +228,14 @@ export default function DiffViewer({
diffEditor.focus()
}
// Why: clear modifiedEditor on dispose so decorator effects (scroll-to-note,
// popover position) don't invoke methods on a disposed Monaco editor.
diffEditor.onDidDispose(() => {
lineNumberOptionsSubRef.current?.dispose()
lineNumberOptionsSubRef.current = null
diffEditorRef.current = null
setModifiedEditor(null)
setPopover(null)
})
},
[editable, setupCopy, modelKey, filePath, sideBySide]
@@ -22,7 +22,6 @@ import {
GitMerge,
GitPullRequestArrow,
MessageSquare,
Pencil,
Send,
Trash,
TriangleAlert,
@@ -217,7 +216,7 @@ function SourceControlInner(): React.JSX.Element {
const openAllDiffs = useAppStore((s) => s.openAllDiffs)
const openBranchAllDiffs = useAppStore((s) => s.openBranchAllDiffs)
const deleteDiffComment = useAppStore((s) => s.deleteDiffComment)
const setEditingDiffCommentId = useAppStore((s) => s.setEditingDiffCommentId)
const setScrollToDiffCommentId = useAppStore((s) => s.setScrollToDiffCommentId)
// Why: pass activeWorktreeId directly (even when null/undefined) so the
// slice's getDiffComments returns its stable EMPTY_COMMENTS sentinel. An
// inline `[]` fallback would allocate a new array each store update, break
@@ -1035,6 +1034,80 @@ function SourceControlInner(): React.JSX.Element {
[activeWorktreeId, branchSummary, openBranchDiff, worktreePath]
)
// Why: a note's filePath is the same relative path used by GitStatusEntry /
// GitBranchChangeEntry, so we can route the click to whichever diff surface
// currently owns that file. Prefer the `unstaged` entry when a path is also
// staged — diff comments are authored against the working-tree (unstaged)
// diff card. Fall back to the branch compare, and finally just open the
// file as a normal editor tab so the user still gets navigation when
// neither side has the path anymore. When `commentId` is supplied and the
// route lands on a diff surface, also stamp scrollToDiffCommentId so the
// diff decorator scrolls that note into view; we clear any prior request
// first, so the editor-tab fallback then leaves the global null and a
// future DiffViewer mount can't accidentally consume a stale id.
const handleOpenComment = useCallback(
(filePath: string, commentId?: string) => {
if (!activeWorktreeId || !worktreePath) {
return
}
// Defensively clear any dangling prior scroll request before routing
// this click; only the diff branches below will re-stamp it.
setScrollToDiffCommentId(null)
const matches = entries.filter((e) => e.path === filePath)
const uncommitted =
matches.find((e) => e.area === 'unstaged') ??
matches.find((e) => e.area === 'untracked') ??
matches[0]
if (uncommitted) {
handleOpenDiff(uncommitted)
if (commentId) {
setScrollToDiffCommentId(commentId)
}
return
}
const branchEntry = branchEntries.find((e) => e.path === filePath)
if (branchEntry && branchSummary?.status === 'ready') {
openCommittedDiff(branchEntry)
if (commentId) {
setScrollToDiffCommentId(commentId)
}
return
}
// Why: fall through to a normal editor tab when neither the working-tree
// nor branch-compare diff has the file (e.g. the change has since been
// committed and merged, but the note still references the file). Force
// the editor tab into 'changes' mode and stamp scrollToDiffCommentId so
// the DiffViewer that EditorContent renders in changes mode picks up
// the scroll request — same surface the user can flip into manually
// via the editor's Edit/Changes toggle.
const absPath = joinPath(worktreePath, filePath)
const language = detectLanguage(filePath)
openFile({
filePath: absPath,
relativePath: filePath,
worktreeId: activeWorktreeId,
language,
mode: 'edit'
})
if (commentId) {
setEditorViewMode(absPath, 'changes')
setScrollToDiffCommentId(commentId)
}
},
[
activeWorktreeId,
branchEntries,
branchSummary,
entries,
handleOpenDiff,
openCommittedDiff,
openFile,
setEditorViewMode,
setScrollToDiffCommentId,
worktreePath
]
)
const handleStage = useCallback(
async (filePath: string) => {
if (!worktreePath) {
@@ -1334,7 +1407,7 @@ function SourceControlInner(): React.JSX.Element {
<DiffCommentsInlineList
comments={diffCommentsForActive}
onDelete={(id) => void deleteDiffComment(activeWorktreeId, id)}
onEdit={(id) => setEditingDiffCommentId(id)}
onOpen={(filePath, commentId) => handleOpenComment(filePath, commentId)}
/>
)}
</div>
@@ -2024,14 +2097,14 @@ function SectionHeader({
function DiffCommentsInlineList({
comments,
onDelete,
onEdit
onOpen
}: {
comments: DiffComment[]
onDelete: (commentId: string) => void
// Why: clicking edit doesn't open an editor inline in the sidebar — the user
// chose "edit in the diff card" so the parent routes the click through the
// UI slice, which the diff card consumes to enter its own editor.
onEdit: (commentId: string) => void
// Why: clicking the note row navigates the user to that file's diff (or
// editor as a fallback) and, when a `commentId` is supplied, scrolls the
// diff to that specific note via the scrollToDiffCommentId UI slice.
onOpen: (filePath: string, commentId?: string) => void
}): React.JSX.Element {
// Why: group by filePath so the inline list mirrors the structure in the
// Notes tab — a compact section per file with line-number prefixes.
@@ -2082,50 +2155,53 @@ function DiffCommentsInlineList({
<div className="bg-muted/20">
{groups.map(([filePath, list]) => (
<div key={filePath} className="px-3 py-1.5">
<div className="truncate text-[10px] font-medium text-muted-foreground">{filePath}</div>
<button
type="button"
className="block w-full truncate text-left text-[10px] font-medium text-muted-foreground hover:text-foreground"
onClick={() => onOpen(filePath)}
title={`Open ${filePath}`}
>
{filePath}
</button>
<ul className="mt-1 space-y-1">
{list.map((c) => (
<li
key={c.id}
className="group flex items-center gap-1.5 rounded px-1 py-0.5 hover:bg-accent/40"
>
<span className="shrink-0 rounded bg-muted px-1 py-0.5 text-[10px] leading-none tabular-nums text-muted-foreground">
L{c.lineNumber}
</span>
<div className="min-w-0 flex-1 whitespace-pre-wrap break-words text-[11px] leading-snug text-foreground">
{c.body}
</div>
<button
type="button"
// Why: a single inner button is the click/keyboard target so
// the row's action buttons (copy/delete) can stay as
// siblings without nesting interactive elements — that
// pattern violates ARIA's no-interactive-descendants rule
// for buttons and lets bubbled key events from the children
// fire the row's open handler.
className="flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded text-left"
onClick={() => onOpen(c.filePath, c.id)}
title={`Open ${c.filePath} (line ${c.lineNumber})`}
aria-label={`Open note on line ${c.lineNumber}`}
>
<span className="shrink-0 rounded bg-muted px-1 py-0.5 text-[10px] leading-none tabular-nums text-muted-foreground">
L{c.lineNumber}
</span>
<span className="block min-w-0 flex-1 whitespace-pre-wrap break-words text-[11px] leading-snug text-foreground">
{c.body}
</span>
</button>
<button
type="button"
className="shrink-0 rounded p-0.5 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100"
onClick={(ev) => {
ev.stopPropagation()
void handleCopyOne(c)
}}
onClick={() => void handleCopyOne(c)}
title="Copy note"
aria-label={`Copy note on line ${c.lineNumber}`}
>
{copiedId === c.id ? <Check className="size-3" /> : <Copy className="size-3" />}
</button>
<button
type="button"
className="shrink-0 rounded p-0.5 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100"
onClick={(ev) => {
ev.stopPropagation()
onEdit(c.id)
}}
title="Edit note in diff"
aria-label={`Edit note on line ${c.lineNumber}`}
>
<Pencil className="size-3" />
</button>
<button
type="button"
className="shrink-0 rounded p-0.5 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100"
onClick={(ev) => {
ev.stopPropagation()
onDelete(c.id)
}}
onClick={() => onDelete(c.id)}
title="Delete note"
aria-label={`Delete note on line ${c.lineNumber}`}
>
+8 -8
View File
@@ -282,12 +282,12 @@ export type UISlice = {
pendingRevealWorktreeId: string | null
revealWorktreeInSidebar: (worktreeId: string) => void
clearPendingRevealWorktreeId: () => void
// Why: lets the SourceControl sidebar request that a specific diff-comment
// card open its inline editor. Cleared by the card after it consumes the
// request (or when the user cancels), so the same id can be requested again
// later without the card seeing a stale value.
editingDiffCommentId: string | null
setEditingDiffCommentId: (id: string | null) => void
// Why: lets the SourceControl sidebar request that the diff editor scroll
// to a specific note. Cleared by the diff decorator after it reveals the
// line, so the same id can be requested again later without the surface
// seeing a stale value.
scrollToDiffCommentId: string | null
setScrollToDiffCommentId: (id: string | null) => void
persistedUIReady: boolean
uiZoomLevel: number
setUIZoomLevel: (level: number) => void
@@ -656,8 +656,8 @@ export const createUISlice: StateCreator<AppState, [], [], UISlice> = (set, get)
pendingRevealWorktreeId: null,
revealWorktreeInSidebar: (worktreeId) => set({ pendingRevealWorktreeId: worktreeId }),
clearPendingRevealWorktreeId: () => set({ pendingRevealWorktreeId: null }),
editingDiffCommentId: null,
setEditingDiffCommentId: (id) => set({ editingDiffCommentId: id }),
scrollToDiffCommentId: null,
setScrollToDiffCommentId: (id) => set({ scrollToDiffCommentId: id }),
persistedUIReady: false,
uiZoomLevel: 0,
setUIZoomLevel: (level) => set({ uiZoomLevel: level }),