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

Implement splitLevel of Tree.Edit #705

Merged
merged 2 commits into from
Dec 4, 2023
Merged

Implement splitLevel of Tree.Edit #705

merged 2 commits into from
Dec 4, 2023

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Dec 2, 2023

What this PR does / why we need it:

When a user positions the cursor within a paragraph and hits the enter key, the paragraph divides into two separate paragraphs:

  • Original: <p>a|b</p>
  • Result: <p>a</p><p>b</p>

In this commit, splitLevel is introduced to support this scenario.

doc.update((root) => {
  root.tree.edit([0,0], {type:'p',children:[{type:'text', value: 'ab'}]});
  root.tree.edit([2,2], undefined, 1); // split the paragraph
});

This commit does not cover all test cases that may arise due to the split operation. This is because we need to verify the interface first. we need to add test cases in the simultaneous editing situation to verify the algorithm later.

Tasks:

  • Refactor Tree.Edit logic to implement splitLevel of Tree.Edit
  • Remove skip from the unit tests related to splitLevel

Which issue(s) this PR fixes:

Address #662

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

Attention: 75 lines in your changes are missing coverage. Please review.

Comparison is base (12e86a2) 48.81% compared to head (c76e233) 49.11%.

Files Patch % Lines
pkg/document/crdt/tree.go 71.16% 43 Missing and 19 partials ⚠️
pkg/index/tree.go 18.18% 9 Missing ⚠️
api/converter/from_pb.go 0.00% 2 Missing ⚠️
api/converter/to_pb.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #705      +/-   ##
==========================================
+ Coverage   48.81%   49.11%   +0.29%     
==========================================
  Files          69       69              
  Lines       10127    10194      +67     
==========================================
+ Hits         4944     5007      +63     
+ Misses       4657     4656       -1     
- Partials      526      531       +5     

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

@hackerwins hackerwins force-pushed the tree-split branch 2 times, most recently from 0c38f7d to 55779cc Compare December 4, 2023 03:06
@hackerwins hackerwins added the protocol changed 📝 Whether the protocol has changed label Dec 4, 2023
@hackerwins hackerwins marked this pull request as ready for review December 4, 2023 11:42
@hackerwins hackerwins merged commit 8ede955 into main Dec 4, 2023
2 checks passed
@hackerwins hackerwins deleted the tree-split branch December 4, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
protocol changed 📝 Whether the protocol has changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant