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 applyDelta with block embed #3777

Merged
merged 1 commit into from
May 31, 2023
Merged

Fix applyDelta with block embed #3777

merged 1 commit into from
May 31, 2023

Conversation

luin
Copy link
Member

@luin luin commented May 20, 2023

Closes #3620

There are two cases where an implicit newline char (\n) could be added:

  1. When you insert an inline embed op or text op that doesn't end with "\n" to the end of the document (after the last \n) or right before a block embed, an implicit \n will be appended to that op.
  2. When you insert a block embed after an inline embed op or a text that doesn't end with \n, an implicit \n will be prepended to the op.

Before this PR, we only tracked the first case with a flag addedNewline. When it's true, we increase the index by 1 and record it in deleteDelta to delete it. The reason we want to delete it instead of skipping it is that a following op may contain a \n, which makes the implicit \n redundant.

However, we didn't catch the second case which led to #3620. This PR added another flag isImplicitNewlinePrepended for that case. Instead of deleting the implicit \n, we will just skip it because we know for sure the implicit \n is needed.

@@ -30,17 +30,17 @@ class Editor {
normalizedDelta.reduce((index, op) => {
const length = Op.length(op);
let attributes = op.attributes || {};
let addedNewline = false;
let isImplicitNewlinePrepended = false;
let isImplicitNewlineAppended = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

note: renamed from addedNewline

@luin luin force-pushed the zh-fix-applyDelta branch 3 times, most recently from c66c2f8 to 942463a Compare May 24, 2023 03:00
@luin luin marked this pull request as ready for review May 24, 2023 03:00
@luin luin merged commit 076f8a8 into develop May 31, 2023
@luin luin deleted the zh-fix-applyDelta branch May 31, 2023 22:39
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.

applyDelta deletes wrong text with insert + delete
2 participants