Skip to content

refactor: cursor-based sidebar expansion for comments and tracked changes#244

Merged
jedrazb merged 6 commits intomainfrom
fix/cursor-driven-sidebar-expansion
Apr 2, 2026
Merged

refactor: cursor-based sidebar expansion for comments and tracked changes#244
jedrazb merged 6 commits intomainfrom
fix/cursor-driven-sidebar-expansion

Conversation

@jedrazb
Copy link
Copy Markdown
Contributor

@jedrazb jedrazb commented Apr 2, 2026

Summary

  • Replace the DOM click handler in UnifiedSidebar with ProseMirror cursor-driven mark detection in DocxEditor
  • When cursor lands on a comment, insertion, or deletion mark, the matching sidebar card expands automatically
  • Also works with keyboard navigation (arrow keys into a mark), not just mouse clicks
  • Removes ~46 lines of DOM event handling, replaces revisionIdAliases prop with simpler activeItemId controlled prop

Test plan

  • Click on a comment highlight → sidebar card expands
  • Click on a tracked change (insertion/deletion) → sidebar card expands
  • Click on a replacement tracked change (insertion side) → correct card expands
  • Click on normal text → sidebar card collapses
  • Use keyboard to navigate into a comment/tracked change → card expands
  • Click sidebar card toggle to collapse → stays collapsed until cursor moves

🤖 Generated with Claude Code

jedrazb and others added 2 commits April 2, 2026 11:43
Replace the DOM click handler in UnifiedSidebar with ProseMirror
cursor-driven detection in DocxEditor. When the cursor lands on a
comment, insertion, or deletion mark, the matching sidebar card
expands automatically. This also works with keyboard navigation,
not just clicks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docx-editor Ready Ready Preview, Comment Apr 2, 2026 3:14pm

Request Review

Two fixes:

1. Mark detection: $from.marks() misses inclusive:false marks at
   cursor boundaries. Now checks nodeAfter/nodeBefore marks first
   for reliable comment and tracked change detection.

2. Sidebar crash: Remove bidirectional state sync (activeItemId →
   internal state → onExpandedItemChange → parent) that caused
   max update depth. Make sidebar fully controlled — parent owns
   expansion state, sidebar just reads activeItemId prop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Empty mark arrays are truthy in JS, so the OR chain
(storedMarks || nodeAfter?.marks || nodeBefore?.marks)
short-circuited on the first source with any node, even if
that node had no comment/tracked-change marks. Now spreads
all sources into a single array so we always find the mark.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The sidebar items only exist in allSidebarItems when
showCommentsSidebar is true, but commentSidebarItems always
has them. Search commentSidebarItems for mark matching, and
auto-set showCommentsSidebar=true when a match is found so
clicking on a comment or tracked change opens the sidebar.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Merge near-duplicate insertion and deletion mark handling into
   a single block with shared prefix-search and alias-resolution logic.

2. Stabilize toggleExpand callback with a ref so it doesn't recreate
   on every expandedItem change, avoiding unnecessary card re-renders
   on each cursor move.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jedrazb jedrazb merged commit bd1c468 into main Apr 2, 2026
4 checks passed
@jedrazb jedrazb deleted the fix/cursor-driven-sidebar-expansion branch April 2, 2026 15:37
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.

1 participant