mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-04 05:27:40 +00:00
fix(code-editor): clamp diff nav index after chunk recompute
`editorToolbarPanel` keeps `currentIndex` as local state while diff chunks are recomputed from `getChunks(view.state)` on each `updatePanel()` call. When the diff shrank (for example after resolving edits), `currentIndex` could remain greater than `chunkCount - 1`. That caused two user-facing issues: - The counter could render impossible values like `4/2 changes`. - Prev/next handlers could read `chunks[currentIndex]` as `undefined`, so navigation would fail to scroll to a valid chunk. Repro in UI: 1. Open a file with multiple diff chunks. 2. Navigate to a high chunk index using Next. 3. Edit content so the number of chunks decreases. 4. Observe stale index in the counter and broken nav behavior. Fix: - After recomputing chunks, clamp the index immediately: `currentIndex = Math.max(0, Math.min(currentIndex, Math.max(0, chunkCount - 1)))` - Keep all downstream uses (counter rendering and prev/next logic) based on the clamped index. Result: - Counter always stays within valid bounds. - Navigation never references an out-of-range chunk. - Zero-chunk behavior remains intact (counter and disabled buttons). File: - src/components/code-editor/utils/editorToolbarPanel.ts
This commit is contained in:
@@ -65,6 +65,8 @@ export const createEditorToolbarPanelExtension = ({
|
||||
const chunksData = hasDiff ? getChunks(view.state) : null;
|
||||
const chunks = chunksData?.chunks || [];
|
||||
const chunkCount = chunks.length;
|
||||
const maxChunkIndex = Math.max(0, chunkCount - 1);
|
||||
currentIndex = Math.max(0, Math.min(currentIndex, maxChunkIndex));
|
||||
|
||||
let toolbarHtml = '<div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">';
|
||||
toolbarHtml += '<div style="display: flex; align-items: center; gap: 8px;">';
|
||||
|
||||
Reference in New Issue
Block a user