Skip to content

Edit CSV tables directly and remember column widths - #25442

Merged
nwparker merged 5 commits into
mainfrom
nwparker/csv-table-editing
Oct 5, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/csv-table-editing

Conversation

@nwparker

@nwparker nwparker commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1228 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1222
Prod 34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2014 $\color{#cf222e}{\Huge{\mathbf{−}}}$​144 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1870

ELI5

CSV tables currently let you resize columns, but editing still requires switching to Source. This adds cell editing, row and column operations, range copy/paste, and sorting/filtering for inspection. Column widths now survive view switches and app restarts.

What Changed

  • Extend the existing grid with cell selection, keyboard navigation, an in-place editor, and row/column menus. Keep virtualization on both axes, including keyboard access to cells outside the viewport.
  • Keep CSV text as the source of truth. Cell edits replace affected records; serialization retains the BOM, record endings, valid existing quoting, and final-newline behavior. Sorting/filtering maps displayed rows back to their original positions, so Save preserves file row order.
  • Join the existing draft/save lifecycle: pending input survives view switches, global Save and restart preparation flush it, failed writes keep drafts, and completing an earlier write cannot clear a newer pending edit. Separate panes of the same file retain their pending input registrations.
  • Reuse the existing per-file preference storage for widths, isolated by workspace and execution owner. Bound retained preferences and debounce resize writes. Widths follow inserted, deleted, and moved columns; large read-only previews also retain widths.
  • Reject table operations that would reach the existing 1 MiB large-file threshold before constructing an oversized result. Over-limit pending input remains recoverable through Source.

Why

A plain-text CSV model lets the table preserve file formatting and source row identity while reusing the existing virtualized grid and file-owner save paths. The Markdown table uses rich-document positions and transactions, which do not fit these CSV operations. This extends the existing components without adding a dependency or changing remote file commands.

Linked Issue

Fixes #12915 for editable CSV/TSV files. Large-file editing remains deferred as requested; files at least 1 MiB continue to use read-only paged previews.

Thanks to @hungrytech for #13223. Their draggable separators, aligned header/body widths, and retention of manual widths across remounts were the right direction. This follow-up adds persistence by file owner and the remaining table operations.

Visual Proof

Same CSV fixture in hidden Electron. Before renders the merged viewer from f873aaac5b25; after shows edited values and a sorted inspection view. The test separately asserts that saving retains the original file row order. Images are attachments, not repository files.

Before

CSV table before direct editing

After

Editable CSV table with inspection-only sorting

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

On macOS, 185 focused tests pass across 20 suites. pnpm tc, changed-code quality, localization catalog/extraction/coverage checks, and the Electron E2E build pass. All agent-launched app windows remain hidden.

Eight hidden Electron tests pass across csv-table-editing.spec.ts, csv-paged-preview.spec.ts, and csv-url-links.spec.ts: cell commit/cancel, Source/Table handoff, width retention, row/column mutations, column reordering, range clipboard events, sorted/filtered edits, exact saved bytes, clipped-cell typing, scrolling commits, autosave during typing, keyboard editing at the final cell of a 1,024-column table, bounded large previews, large-file save guards, and URL navigation. Unit regressions cover slow-save races, same-file panes, stale clipboard reads, failed saves, BOM/CRLF/ragged records, empty final records, and ambiguous delimiter guesses.

The standalone pnpm run typecheck:e2e currently reports errors in other specs and test tools; none of the changed CSV specs are reported. The application typecheck passes. Live SSH, Windows, and Linux were not exercised locally; editing uses their existing file-owner save path and platform-aware shortcuts.

Review

Reviewed serialization, draft ownership, cancellation, asynchronous clipboard reads, remote-write timing, pane cleanup, and width persistence. Fixed a newer cell edit being marked clean by an earlier save, same-file pane registrations replacing one another, closed tabs recreating drafts on detach, Auto changing separators during edits, and deletion losing a retained empty record. The bot follow-up fixes autosave closing active inputs, browser caret scrolling closing clipped inputs, and structural edits discarding rejected pending input. Cell commits, Save, and table commands now share a single mutation path; structural serialization no longer has an unused budget bypass. Delayed clipboard reads also reject newly started typing, and app-menu paste is cancelled if the initiating grid loses focus. Existing large-preview memory and save-safety checks still pass.

Agent skill upstream boundary

  • Not applicable; no skill-installation or sharing changes.

Notes

Large previews remain read-only. Table edits must stay below 1 MiB; Source can retain larger drafts. Paste outside the existing table is rejected atomically, with an instruction to add rows or columns first. Column reordering uses the Columns menu. Sorting/filtering is an inspection view and never rewrites source row order.

Checklist

  • This PR is small and focused — the requested CSV editor spans interaction, serialization, drafts, and persistence.
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Application typecheck, focused tests, changed-code quality, localization, and build pass; CI covers the full repository gates

@nwparker
nwparker requested a review from brennanb2025 as a code owner October 5, 2026 06:42
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2110556d-a28c-4a5e-967d-bf0f2c3d7e46
📥 Commits

Reviewing files that changed from the base of the PR and between 9097a78 and 0015e52.

📒 Files selected for processing (1)
  • src/renderer/src/components/editor/CsvViewer.editing.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The CSV table view now supports cell editing, selection, filtering, sorting, copying and pasting, and row and column operations. CSV mutations preserve eligible source formatting and enforce size and dimension limits. Column widths persist by file preference key. Editor save handling now flushes pending changes and accounts for pending edits when setting dirty state.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0015e

The delayed-paste test exercises a pending clipboard read and verifies that moving focus does not change either pane. No actionable current-head issue remains; routine checks can proceed.

Architecture Summary

Architecture risk: 🔵 Low · up to 0015e

The change affects 2 systems.

Changed systems: src, tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 41 changed files map to changed impact.
  • observed — tests (service) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/components/editor/CsvColumnResizeHandle.tsx: The component now imports and re-exports the column-width limits from csv-column-width-limits; the local definitions of both constants were removed.
  • observed — Modified behavior in src/renderer/src/components/editor/CsvPagedViewer.tsx: Imports the column-width hook and preference-key builder.
  • observed — Modified behavior in src/renderer/src/components/editor/CsvPagedViewer.tsx: CsvPagedViewer adds an optional preferenceKey prop.
  • observed — Modified behavior in src/renderer/src/components/editor/CsvPagedViewer.tsx: Passes preferenceKey from CsvPagedViewer to CsvPagedTable.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 51 functions across 43 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #12915 requests resizable columns with retained widths, direct cell editing, row and column operations, column reordering, range copy/paste, and sorting or filtering that preserves source row or…
Out of Scope Changes check ✅ Passed The grid, CSV document and serialization code, clipboard and preference handling, and tests support issue #12915. The pending-editor and save-queue changes support the CSV draft and save lifecycle. Th…
Title check ✅ Passed The title clearly summarizes the main change: direct CSV table editing and column-width persistence.
Description check ✅ Passed The description is mostly complete. It covers the user-facing change, implementation, rationale, linked issue, visual proof, testing, review, upstream-boundary status, notes, and checklist. The AI Dis…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2b249199-9fd4-477a-9b58-3732c3314586
📥 Commits

Reviewing files that changed from the base of the PR and between a154562 and 8d5f906.

📒 Files selected for processing (44)
  • src/renderer/src/components/editor/CsvColumnResizeHandle.tsx
  • src/renderer/src/components/editor/CsvGrid.tsx
  • src/renderer/src/components/editor/CsvGridCell.tsx
  • src/renderer/src/components/editor/CsvPagedViewer.tsx
  • src/renderer/src/components/editor/CsvTableToolbar.tsx
  • src/renderer/src/components/editor/CsvViewer.editing.test.tsx
  • src/renderer/src/components/editor/CsvViewer.tsx
  • src/renderer/src/components/editor/EditorEditFileSurface.tsx
  • src/renderer/src/components/editor/EditorViewToggle.tsx
  • src/renderer/src/components/editor/csv-cell-clipboard.ts
  • src/renderer/src/components/editor/csv-cell-selection.ts
  • src/renderer/src/components/editor/csv-column-width-limits.ts
  • src/renderer/src/components/editor/csv-column-width-preferences.test.ts
  • src/renderer/src/components/editor/csv-column-width-preferences.ts
  • src/renderer/src/components/editor/csv-file-limits.ts
  • src/renderer/src/components/editor/csv-grid-interaction.ts
  • src/renderer/src/components/editor/csv-grid-keyboard.ts
  • src/renderer/src/components/editor/csv-inspection.ts
  • src/renderer/src/components/editor/csv-parse.ts
  • src/renderer/src/components/editor/csv-pending-save.test.ts
  • src/renderer/src/components/editor/csv-serialization.ts
  • src/renderer/src/components/editor/csv-source-record.ts
  • src/renderer/src/components/editor/csv-table-edit-budget.ts
  • src/renderer/src/components/editor/csv-table-interactions.test.ts
  • src/renderer/src/components/editor/csv-text-cell-edits.ts
  • src/renderer/src/components/editor/csv-text-document.test.ts
  • src/renderer/src/components/editor/csv-text-document.ts
  • src/renderer/src/components/editor/editor-csv-file-content.ts
  • src/renderer/src/components/editor/editor-pending-flush.test.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/file-view-preference-storage.ts
  • src/renderer/src/components/editor/pdf-scale-preference-storage.ts
  • src/renderer/src/components/editor/use-editor-content-change-handler.test.tsx
  • src/renderer/src/components/editor/use-editor-content-change-handler.ts
  • src/renderer/src/components/editor/useCsvClipboard.ts
  • src/renderer/src/components/editor/useCsvColumnWidths.ts
  • src/renderer/src/components/editor/useCsvPendingCell.ts
  • src/renderer/src/components/editor/useCsvTableEditor.ts
  • src/renderer/src/components/ui/textarea.tsx
  • src/renderer/src/i18n/locales/en.json
  • tests/e2e/csv-paged-preview.spec.ts
  • tests/e2e/csv-table-editing.spec.ts
  • tests/e2e/csv-url-links.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Comment thread tests/e2e/csv-table-editing.spec.ts Resolved
@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Review fixes are in 1ce9c3ef5f5c.

  • Autosave saves committed CSV text while preserving the active input and dirty state; explicit Save commits the input. Timer failures are caught.
  • Clipped cells stay editable through browser caret scrolling. Scrolling the cell out of view commits it without jumping back.
  • A rejected pending edit blocks row/column operations and inspection changes. Cell commits, Save, and table commands share one mutation path, and rejected input remains recoverable in Source.
  • Removed the redundant structural record set and unused structural budget bypass. Delayed clipboard reads cannot overwrite typing started while the read was pending.

Validation: 184 focused tests, application typecheck, changed-code quality, formatting/lint, and eight hidden Electron tests pass. The screenshots show the active input after autosave; the test also checks the exact file contents before and after committing it.

Active CSV input retained after autosave

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Cancel app-menu paste if focus leaves the grid. · useCsvClipboard.ts:56-75

src/renderer/src/components/editor/useCsvClipboard.ts:56-75
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cancel app-menu paste if focus leaves the grid.

The app-menu handler checks the owner before readClipboardText() awaits. If the user focuses another grid before the read resolves, the first grid’s revision stays unchanged and pasteText() can still apply the clipboard data to that grid. Recheck focus for app-menu paste only; keep toolbar and keyboard paste behavior unchanged.

Suggested fix
-  const paste = async (): Promise<void> => {
+  const paste = async (requireOwnerFocus = false): Promise<void> => {
...
       if (initialRevision !== revision.current) {
         throw new Error('CSV changed before paste completed. Try again.')
       }
+      if (
+        requireOwnerFocus &&
+        globalThis.document.activeElement?.getAttribute('data-csv-owner') !== ownerId
+      ) {
+        return
+      }
       pasteText(text)
...
-        void paste()
+        void paste(true)

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab3a9baa-d167-4447-81f5-c8b3e726ab45
📥 Commits

Reviewing files that changed from the base of the PR and between 8d5f906 and 1ce9c3e.

📒 Files selected for processing (13)
  • src/renderer/src/components/editor/CsvGrid.tsx
  • src/renderer/src/components/editor/CsvGridCell.tsx
  • src/renderer/src/components/editor/CsvViewer.editing.test.tsx
  • src/renderer/src/components/editor/CsvViewer.tsx
  • src/renderer/src/components/editor/csv-pending-save.test.ts
  • src/renderer/src/components/editor/csv-text-cell-edits.ts
  • src/renderer/src/components/editor/csv-text-document.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/useCsvClipboard.ts
  • src/renderer/src/components/editor/useCsvPendingCell.ts
  • src/renderer/src/components/editor/useCsvTableEditor.ts
  • tests/e2e/csv-table-editing.spec.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/renderer/src/components/editor/csv-pending-save.test.ts
  • src/renderer/src/components/editor/CsvGridCell.tsx
  • tests/e2e/csv-table-editing.spec.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-save-queue.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the outside-diff clipboard finding in 9097a78b26de.

App-menu paste now rechecks the initiating grid after the clipboard read. Toolbar and keyboard paste retain their behavior. The new two-pane regression verifies that moving focus while a read is pending does not change either file. All 18 CSV editing tests, application typecheck, and changed-code quality pass.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/editor/CsvViewer.editing.test.tsx (1)

310-312: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that app-menu paste starts before focus moves.

If readClipboardText is never called, the pending promise does not paste anything, so both content-change assertions still pass. Spy on the read and assert one call after dispatch. This ensures the test checks cancellation of a paste that started before focus moved.

Suggested test change
     const pending = new Promise<string>((resolve) => {
       resolveRead = resolve
     })
+    const read = vi.fn(() => pending)
     Object.defineProperty(window, 'api', {
       configurable: true,
-      value: { ui: { readClipboardText: () => pending } }
+      value: { ui: { readClipboardText: read } }
     })
...
     act(() => {
       window.dispatchEvent(new Event(APP_MENU_PASTE_EVENT, { cancelable: true }))
     })
+    expect(read).toHaveBeenCalledTimes(1)
     act(() => {
       screen.getAllByRole('grid')[1]?.focus()
     })

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2b7aab9f-b223-4dc4-a821-cd2fde8b7870
📥 Commits

Reviewing files that changed from the base of the PR and between 1ce9c3e and 9097a78.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/CsvViewer.editing.test.tsx
  • src/renderer/src/components/editor/useCsvClipboard.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the final test nit in 0015e52: the delayed app-menu paste regression now asserts that the clipboard read started before focus moved. All 18 CSV editing tests and the application typecheck pass.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nwparker
nwparker merged commit c53b6f2 into main Oct 5, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Make CSV table view interactive and support column resizing

1 participant