Skip to content

Add support in getTextChangeMutation() for removed text nodes #138

Open
taylorhadden wants to merge 1 commit intotypewriter-editor:mainfrom
taylorhadden:input-text-removal-mutation
Open

Add support in getTextChangeMutation() for removed text nodes #138
taylorhadden wants to merge 1 commit intotypewriter-editor:mainfrom
taylorhadden:input-text-removal-mutation

Conversation

@taylorhadden
Copy link
Copy Markdown
Contributor

There are two common cases where mutation parsing gives up and falls back to a whole-document diff:

  1. When a delete replaced a text node with a <br>.
  2. When a delete removed a text node from within a line.

In both cases, getChangedLineRange() doesn't resolve to a correct range as it early-outs on the deleted text element. This results in diffing the entire document.

getTextChangeMutation() already handled replacing a <br> with text, so I modified it to also handle the reverse. I also added the handling of a removed text node that had a previous sibling. Pulling the index resolution into the function allowed these slightly different situations to be handled appropriately.


If you feel this change modifies getTextChangeMutation() too much, I can instead look to improve getChangedLinkRange() so that these situations fall back to a line diff instead of a whole-document diff.

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.

1 participant