Skip to content
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

fix: 表格第一个回车编辑器无法正常展示 #517

Closed
wants to merge 1 commit into from

Conversation

liuchuzhang
Copy link
Contributor

@liuchuzhang liuchuzhang commented Jan 22, 2025

Changes Overview

Implementation Approach

Testing Done

Verification Steps

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

Close #516

Summary by CodeRabbit

  • New Features
    • Enhanced table cell editing experience with improved text insertion, deletion, and selection handling
  • Bug Fixes
    • Refined text management within table cells
    • Improved handling of line breaks and cursor positioning
    • Added normalization for table structure and node management

Copy link

changeset-bot bot commented Jan 22, 2025

⚠️ No Changeset found

Latest commit: d509440

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request modifies the withTable function in the table module plugin, focusing on improving text manipulation within table cells. The changes address how line breaks, text insertion, deletion, and selection are handled when interacting with table elements. The modifications aim to enhance the editor's behavior when users perform various text operations inside table cells, ensuring more consistent and predictable interactions.

Changes

File Change Summary
packages/table-module/src/module/plugin.ts - Updated insertBreak to use '\n' instead of '\n\r' for table cells
- Modified deleteBackward and deleteForward to handle table cell boundary checks
- Enhanced deleteFragment to manage cursor position during deletions
- Updated normalizeNode to insert a paragraph after tables
- Refined insertData for handling pasted content in tables
- Improved selectAll method for table cell selection

Assessment against linked issues

Objective Addressed Explanation
Fix table first line entry display (#516)

Possibly related PRs

Poem

🐰 In tables of code, where lines dance and sway,
A rabbit hops through, clearing bugs away
Line breaks now flow, deletions precise
With each keystroke, the editor's more nice!
Hop, hop, hurray for table delight! 🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link
Contributor

@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

🧹 Nitpick comments (1)
packages/table-module/src/module/plugin.ts (1)

176-176: Update documentation for line break behavior

Please update the documentation to reflect the new line break behavior in table cells. This will help users and developers understand the expected behavior.

Consider:

  1. Adding a comment explaining why \n is used instead of \n\r
  2. Updating user documentation if table cell behavior is documented
  3. Adding a code comment about cross-platform considerations
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3cbe33 and d509440.

📒 Files selected for processing (1)
  • packages/table-module/src/module/plugin.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: test-e2e
🔇 Additional comments (1)
packages/table-module/src/module/plugin.ts (1)

176-176: Consider platform-specific line endings

The change from \n\r to \n fixes the display issue, but we should ensure consistent line ending handling across platforms.

Let's verify how line endings are handled elsewhere in the codebase:

✅ Verification successful

The change to use '\n' is correct and consistent with the codebase

The codebase already handles all line ending variants ('\n', '\r\n', '\n\r', '\r') during text processing, while consistently using '\n' for text insertions. This change aligns with that pattern and fixes the display issue without compromising cross-platform compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for line ending patterns in the codebase
echo "Searching for line ending patterns..."
rg -n "\\\\n\\\\r|\\\\r\\\\n|\\\\n|\\\\r" --type ts

# Check if there are any platform-specific line ending configurations
echo "Checking for line ending configurations..."
fd -t f ".(git|editor)config$"

Length of output: 8307

@@ -173,7 +173,7 @@ function withTable<T extends IDomEditor>(editor: T): T {

if (selectedNode != null) {
// 选中了 table ,则在 cell 内换行
newEditor.insertText('\n\r')
newEditor.insertText('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent line break handling

The insertion now uses \n, but the deletion logic in deleteCellBreak and isHalfBreak still expects \n\r. This inconsistency could lead to issues.

Consider updating the deletion logic to match the new line break format:

function isHalfBreak(newEditor: IDomEditor, location: Point): boolean {
  const offset = location.offset
  if (offset === 0) { return false }
  const node = Editor.node(newEditor, location)
  if (!Text.isText(node[0])) { return false }
  const text = Node.string((node[0]))
  if (offset >= text.length) { return false }
-  return text[offset - 1] === '\n' && text[offset] === '\r'
+  return text[offset - 1] === '\n'
}

Similar updates would be needed in deleteCellBreak function.

Also applies to: 31-108


💡 Codebase verification

Add tests for line break handling in table cells

The existing tests in plugin.test.ts only verify method calls but don't cover the actual line break behavior. Please add tests to verify:

  1. Single line break insertion in table cells
  2. Multiple line break insertions
  3. Line break deletion
  4. Cross-platform compatibility (different line ending types)

Location requiring tests:

  • packages/table-module/__tests__/plugin.test.ts
🔗 Analysis chain

Add tests for line break handling

This change fixes a bug with line breaks, but there are no corresponding test updates. Please add tests to verify:

  1. Single line break insertion in table cells
  2. Multiple line break insertions
  3. Line break deletion
  4. Cross-platform compatibility

Let's check existing tests:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for table-related tests
echo "Searching for table-related test files..."
fd -t f "table.*test.*\.(ts|js|tsx|jsx)$"

# Search for line break tests within these files
echo "Searching for line break tests..."
rg -l "insertBreak|\\\\n|\\\\r" $(fd -t f "table.*test.*\.(ts|js|tsx|jsx)$")

Length of output: 636


Script:

#!/bin/bash
# Search for cell-related test files
echo "Searching for cell-related test files..."
fd -t f "(cell|edit|content).*test.*\.(ts|js|tsx|jsx)$" packages/table-module/

# Search with broader patterns
echo "Searching for line break related tests with broader patterns..."
rg -l "newEditor\.insert|lineBreak|\\n|\\r|enter|newline" packages/table-module/__tests__/

Length of output: 591


Script:

#!/bin/bash
# Search for editor-related tests with proper escaping
echo "Searching test content..."
rg -U "newEditor|insertText|'\\\\n'|\"\\\\n\"|lineBreak|newline" packages/table-module/__tests__/

Length of output: 1025

@@ -173,7 +173,7 @@ function withTable<T extends IDomEditor>(editor: T): T {

if (selectedNode != null) {
// 选中了 table ,则在 cell 内换行
newEditor.insertText('\n\r')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

不知道之前是出于什么原因 \n 后还加了个 \r,没去看这个有什么用了,删掉 \r 看起来一切正常

Copy link
Collaborator

@cycleccc cycleccc Jan 22, 2025

Choose a reason for hiding this comment

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

216e61e
这一块改动和这个 pr 相关,具体改动的牵连还得再看看。
#264

@liuchuzhang
Copy link
Contributor Author

对其他内容有影响,先 Close 了

@liuchuzhang liuchuzhang deleted the fix/516 branch January 22, 2025 08:01
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.

Bug: 表格第一个回车编辑器无法正常展示
2 participants