Skip to content

Allow cursor to escape table when table is last block#125

Merged
hackerwins merged 1 commit into
mainfrom
fix/docs-table-cursor-escape
Apr 12, 2026
Merged

Allow cursor to escape table when table is last block#125
hackerwins merged 1 commit into
mainfrom
fix/docs-table-cursor-escape

Conversation

@hackerwins

@hackerwins hackerwins commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • When a table is the last (or only) block in a document, the cursor could not move past it — ArrowDown, ArrowRight from the last cell silently failed
  • Add Doc.ensureBlockAfter() helper that appends an empty paragraph when no block follows a given index
  • insertTable now splits the current block at the cursor ("as|df" → "as" [table] "df") and ensures a trailing paragraph
  • ArrowDown from last row and ArrowRight from last cell create a paragraph on-demand

Test plan

  • Insert table in empty document → verify cursor can ArrowDown out of table
  • Insert table at end of document → ArrowDown/ArrowRight from last cell exits to paragraph below
  • Type "asdf", place cursor between "as|df", insert table → verify "as" [table] "df" structure
  • Tab from last cell still adds a new row (existing behavior preserved)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Improved table insertion workflow—trailing text now automatically moves below the inserted table
    • Enhanced cursor navigation at table boundaries for more reliable movement when exiting tables

When a table is the last (or only) block in a document, the cursor
could not move past it — ArrowDown, ArrowRight, and Tab from the
last cell all silently failed.

- Add Doc.ensureBlockAfter() helper that appends an empty paragraph
  when no block follows a given index.
- insertTable now splits the current block at the cursor position so
  "as|df" becomes "as" [table] "df", and always ensures a trailing
  paragraph after the table.
- ArrowDown from the last row and ArrowRight from the last cell use
  ensureBlockAfter() to create a paragraph on-demand.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request introduces a new utility method ensureBlockAfter() to the Doc class that guarantees a block exists after a given index, creating an empty paragraph if necessary. The method is then integrated into table insertion and table navigation flows to ensure proper cursor positioning and document structure consistency.

Changes

Cohort / File(s) Summary
Core Utility
packages/docs/src/model/document.ts
Added public method ensureBlockAfter(blockIndex: number): string that checks for an existing block after the given index; if none exists, inserts an empty paragraph block and returns its ID.
Table Operations & Navigation
packages/docs/src/view/editor.ts, packages/docs/src/view/text-editor.ts
Refactored table insertion and table cell navigation to use ensureBlockAfter() instead of manual bounds checking; ensures a block always exists after table operations for proper cursor escape behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A block after, we now ensure—
No table lost without a door!
Through splits and cells, the cursor hops,
A helper method makes the chaos stop.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: enabling cursor escape from tables positioned as the last block.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/docs-table-cursor-escape

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 and usage tips.

@hackerwins
hackerwins merged commit 5779065 into main Apr 12, 2026
1 check passed
@hackerwins
hackerwins deleted the fix/docs-table-cursor-escape branch April 12, 2026 12:11
@github-actions

github-actions Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 115.0s

Lane Status Duration
sheets:build ✅ pass 12.7s
docs:build ✅ pass 7.7s
verify:fast ✅ pass 57.6s
frontend:build ✅ pass 15.8s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.7s
cli:build ✅ pass 1.7s
verify:entropy ✅ pass 14.5s

Verification: verify:integration

Result: ✅ PASS

@codecov

codecov Bot commented Apr 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.92593% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/docs/src/view/editor.ts 0.00% 15 Missing ⚠️
packages/docs/src/view/text-editor.ts 0.00% 4 Missing ⚠️
packages/docs/src/model/document.ts 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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