Skip to content

feat(editor): streamline cell editing and navigation with improved keyboard support #12770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: canary
Choose a base branch
from

Conversation

NorkzYT
Copy link
Contributor

@NorkzYT NorkzYT commented Jun 10, 2025

improved-cell-editing.mp4

This PR addresses #12769 and improves table editing UX by making Enter commit changes and move focus down, and Tab/Shift+Tab move focus horizontally—matching spreadsheet-like behavior.

Typing now immediately enters edit mode for selected cells without double-clicking.
These updates apply to both the standard and virtual table views.

Summary by CodeRabbit

  • New Features
    • You can now start editing a table cell by simply typing any character while the cell is selected.
  • Improvements
    • Pressing Enter while editing a cell will exit editing and move focus down.
    • Pressing Tab or Shift-Tab while editing a cell will exit editing and move focus right or left, respectively.
  • Tests
    • Added unit tests for table cell hotkey behaviors to ensure reliable editing and navigation.
  • Chores
    • Introduced Vitest configuration for streamlined testing and coverage reporting.

…handling for cell editing in both PC and virtual table hotkeys controllers

fix(hotkeys): streamline selection editing logic to ensure consistent behavior when editing cells in both PC and virtual table hotkeys controllers
@NorkzYT NorkzYT requested a review from a team as a code owner June 10, 2025 01:01
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes update keyboard event handling in table view controllers to refine cell editing and navigation. Enter, Tab, and Shift-Tab keys now exit editing mode before moving focus. Typing a character while a cell is selected (but not editing) immediately starts editing with that character. No exported API signatures were altered.

Changes

File(s) Change Summary
.../view-presets/table/pc-virtual/controller/hotkeys.ts
.../view-presets/table/pc/controller/hotkeys.ts
Refined Enter, Tab, and Shift-Tab key handling to exit editing before navigation; added handler for direct typing to start editing a cell.
blocksuite/affine/data-view/src/tests/hotkeys.unit.spec.ts Added unit tests for hotkey handling in TableHotkeysController and VirtualHotkeysController covering editing initiation and deletion behavior.
blocksuite/affine/data-view/vitest.config.ts Added Vitest configuration with ESBuild target, global setup, test inclusion patterns, coverage, and custom console log filtering.
blocksuite/affine/data-view/package.json Added vitest as a new development dependency for testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TableHotkeysController
    participant TableView

    User->>TableHotkeysController: Presses character key (cell selected, not editing)
    TableHotkeysController->>TableView: Set cell value to character
    TableHotkeysController->>TableView: Enter editing mode
    TableHotkeysController-->>User: Prevent default, cell is now editing

    User->>TableHotkeysController: Presses Enter/Tab/Shift-Tab (while editing)
    TableHotkeysController->>TableView: Exit editing mode
    TableHotkeysController->>TableView: Move focus (down/right/left)
Loading

Suggested labels

app:core

Poem

A hop and a tap, a cell comes alive,
Press any key—watch editing arrive!
Tab and Enter now gently conclude,
Exiting edit before they move.
With every keystroke, the table feels bright—
Rabbits rejoice in the editing delight!
🐇⌨️


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cee686 and 4eef2b2.

📒 Files selected for processing (1)
  • blocksuite/affine/data-view/src/view-presets/table/pc-virtual/controller/hotkeys.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • blocksuite/affine/data-view/src/view-presets/table/pc-virtual/controller/hotkeys.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@graphite-app graphite-app bot requested review from a team June 10, 2025 01:01
Copy link
Contributor

graphite-app bot commented Jun 10, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@NorkzYT NorkzYT changed the title feat(ui): streamline cell editing and navigation with improved keyboard support feat(editor): streamline cell editing and navigation with improved keyboard support Jun 10, 2025
@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 10, 2025

Tests will be added soon.

Copy link

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 55.65%. Comparing base (a1abb60) to head (4eef2b2).

Files with missing lines Patch % Lines
...iew-presets/table/pc-virtual/controller/hotkeys.ts 75.00% 6 Missing ⚠️
...ew/src/view-presets/table/pc/controller/hotkeys.ts 75.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #12770      +/-   ##
==========================================
- Coverage   55.91%   55.65%   -0.27%     
==========================================
  Files        2652     2652              
  Lines      125440   125478      +38     
  Branches    19948    19896      -52     
==========================================
- Hits        70142    69829     -313     
- Misses      53550    53895     +345     
- Partials     1748     1754       +6     
Flag Coverage Δ
server-test 78.99% <ø> (-0.69%) ⬇️
unittest 31.62% <37.50%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@L-Sun
Copy link
Member

L-Sun commented Jun 12, 2025

Tests will be added soon.

Some tests have failed here, you might need to update them. Feel free to let me know if you need to run the test pipeline.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
blocksuite/affine/data-view/src/view-presets/table/pc-virtual/controller/hotkeys.ts (1)

192-204: 🛠️ Refactor suggestion

Shift-Tab has the identical race condition

Replicate the commit/flush guard introduced for Tab / Enter to keep behaviour consistent in all horizontal-navigation paths.

🧹 Nitpick comments (1)
blocksuite/affine/data-view/src/view-presets/table/pc-virtual/controller/hotkeys.ts (1)

401-431: Edge-cases in the new type-to-edit handler

  1. Area-selection: the guard only checks for TableViewRowSelection, so a multi-cell area selection will still fall through and overwrite the first focused cell, which may surprise users.
    – Add && !selection.rowsSelection && !selection.columnsSelection to restrict to a single-cell focus.

  2. Non-BMP characters: event.key.length === 1 filters out emojis and many CJK characters (length > 1 due to UTF-16). If textual columns are expected to accept them, consider event.key.length > 0 && event.key !== 'Enter' instead.

  3. Down-stream handlers: preventDefault() is called, but you should also event.stopPropagation() to avoid duplicated handling by other listeners registered after this one.

         if (
           selection &&
           !TableViewRowSelection.is(selection) &&
+          !selection.rowsSelection &&
+          !selection.columnsSelection &&
           !selection.isEditing &&
           !event.metaKey &&
           !event.ctrlKey &&
           !event.altKey &&
-          event.key.length === 1
+          event.key.length > 0 &&
+          event.key !== 'Enter'
         ) {
@@
             event.preventDefault();
+            event.stopPropagation();
             return true;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 015e346 and 929ac8b.

📒 Files selected for processing (2)
  • blocksuite/affine/data-view/src/view-presets/table/pc-virtual/controller/hotkeys.ts (3 hunks)
  • blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts

…unit tests

feat(hotkeys.unit.spec.ts): implement unit tests for TableHotkeysController and VirtualHotkeysController to ensure correct hotkey functionality
chore(vitest.config.ts): create vitest configuration file to set up testing environment and coverage reporting
@github-actions github-actions bot added the test Related to test cases label Jun 12, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
blocksuite/affine/data-view/src/__tests__/hotkeys.unit.spec.ts (4)

10-46: Improve createLogic typing & DRY-ness

createLogic currently returns any everywhere and stubs out a large surface area.
This hides real compile-time regressions and forces heavy casting (as any) later in the tests.

Consider:

  1. Declaring minimal interfaces for View, UI, SelectionController, and Logic with only the members exercised by the tests.
  2. Returning those concrete types from createLogic.
  3. Re-using the helper across both describe blocks by exporting it (or moving to a shared helpers.ts).
-const logic: any = {
+interface MockLogic { /* minimal surface */ }
+const logic: MockLogic = {
   /* … */
}

This keeps the test harness honest and makes future refactors to the real controllers safer.


48-60: Add expectation for UI refresh side-effect

The Backspace path should trigger an ui.requestUpdate() according to the production code, yet the test only asserts this indirectly after deleting rows. Make the intent explicit:

-logic.hotkeys.Backspace();
+logic.hotkeys.Backspace();
+expect(ui.requestUpdate).toHaveBeenCalled();

This guards against regressions where the deletion still happens but the view no longer refreshes.


62-87: Cover modifier-key edge cases

The “starts editing on character key” test covers the happy path. It would be valuable to assert that the same character press with metaKey | ctrlKey | altKey does not enter edit mode, matching typical spreadsheet behaviour.

['metaKey', 'ctrlKey', 'altKey'].forEach(mod => {
  const evt = { key: 'A', metaKey: false, ctrlKey: false, altKey: false, preventDefault: vi.fn() } as any;
  evt[mod] = true;
  logic.keyDown({ get: () => ({ raw: evt }) });
  expect(selectionController.selection.isEditing).toBe(false);
});

This ensures hotkey handling doesn’t collide with browser/OS shortcuts.


90-120: Deduplicate duplicate test logic with parameterised runner

The virtual-table test repeats almost the same arrange-act-assert block as the standard table test.
Use describe.each or a helper to run the same suite against both controller classes, reducing maintenance cost:

const cases = [
  ['Table', TableHotkeysController],
  ['VirtualTable', VirtualHotkeysController],
] as const;

describe.each(cases)('%sHotkeysController', (_name, Ctrl) => {
  // shared tests …
});

Future behavioural parity changes will need to be updated in only one place.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 929ac8b and 21472c1.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • blocksuite/affine/data-view/package.json (1 hunks)
  • blocksuite/affine/data-view/src/__tests__/hotkeys.unit.spec.ts (1 hunks)
  • blocksuite/affine/data-view/vitest.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • blocksuite/affine/data-view/package.json
  • blocksuite/affine/data-view/vitest.config.ts
🔇 Additional comments (1)
blocksuite/affine/data-view/src/__tests__/hotkeys.unit.spec.ts (1)

1-4: Verify file-extension correctness in ESM/TS setup

The test file is TypeScript (*.ts) but the relative imports explicitly end with .js.
If tsconfig.json does not have allowImportingTsExtensions or the build pipeline rewrites extensions, this will break module resolution at compile time (and IntelliSense).

Please double-check that:

  1. Consumers compile the sources with the same file-extension mapping.
  2. The Vitest runner is configured with moduleFileExtensions / resolve.extensions that include .js for TS sources or uses ts-node’s --experimental-specifier-resolution=node.

If none of the above is true, change the paths to omit the extension or use .ts:

-import { TableHotkeysController } from '../view-presets/table/pc/controller/hotkeys.js';
-import { TableHotkeysController as VirtualHotkeysController } from '../view-presets/table/pc-virtual/controller/hotkeys.js';
+import { TableHotkeysController } from '../view-presets/table/pc/controller/hotkeys';
+import { TableHotkeysController as VirtualHotkeysController } from '../view-presets/table/pc-virtual/controller/hotkeys';

…o ensure proper state management during editing sessions
@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 12, 2025

@L-Sun

When you can please re-run the test pipeline.

@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 12, 2025

I need to test a bit more before.
Unsure at the moment why I receive timeouts when running yarn e2e as documentation advises. I will work on it.

Copy link

socket-security bot commented Jun 14, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​semver@​7.7.01001007277100
Addedcore-js@​3.43.0941009989100

View full report

@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 14, 2025

@L-Sun

I have fixed all issues and now the CI will fully pass no problem.

@L-Sun
Copy link
Member

L-Sun commented Jun 15, 2025

@L-Sun

I have fixed all issues and now the CI will fully pass no problem.

There are currently two type errors remaining, which can be found in the CI. I will review this PR in the coming days.

@L-Sun L-Sun self-assigned this Jun 15, 2025
@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 15, 2025

I see the type error. I thought I had committed that part. Will fix.

…is editing to streamline the editing process
@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 15, 2025

There you go. Now this should be done as I have ran yarn typecheck and found no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Related to test cases
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants