Skip to content

Fix cursor position for arrow up #3305

Open
juliaroldi wants to merge 9 commits intomasterfrom
u/juliaroldi/arrow-up-table
Open

Fix cursor position for arrow up #3305
juliaroldi wants to merge 9 commits intomasterfrom
u/juliaroldi/arrow-up-table

Conversation

@juliaroldi
Copy link
Contributor

When pressing arrow up, move the cursor to the top of the cell, so the cursor can be placed at the cell above.
Before:
ArrowUpBug

After:
ArrowUpFix

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts table keyboard navigation so pressing ArrowUp preserves horizontal caret placement by computing the insertion point at the top edge of the target cell, preventing the cursor from getting “stuck” and enabling movement into the cell above.

Changes:

  • Update ArrowUp caret hit-testing to use the target cell’s rect.top instead of rect.top - 1.
  • Expand/add a unit test scenario for ArrowUp to validate horizontal-position preservation when the browser initially lands in the wrong column.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts Tweaks the Y coordinate passed to getNodePositionFromEvent for ArrowUp within table navigation.
packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts Updates/expands ArrowUp test coverage around preserving horizontal caret placement in tables.
Comments suppressed due to low confidence (1)

packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts:2216

  • This new test mocks getNodePositionFromEvent but never asserts the coordinates it is called with. Since the production change is specifically about the Y coordinate used for ArrowUp (rect.top vs rect.top - 1), the test should include an expectation that getNodePositionFromEvent is invoked with the target cell's top Y value (and the original cursorRect.left) so the fix is actually covered and protected from regression.
            // Mock getNodePositionFromEvent to return a specific position in td6 (middle row, third column)
            const targetNode = testTd6_text;
            const targetOffset = 1;
            spyOn(getNodePositionFromEventFile, 'getNodePositionFromEvent').and.returnValue({
                node: targetNode,
                offset: targetOffset,
            });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants