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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/table-module/src/module/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

return
}

Expand Down
Loading