Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove cursor logic, emoji handling, canonicality, and tests #4
Conversation
dgreensp
added some commits
Oct 5, 2018
jhchen
approved these changes
Oct 5, 2018
I'd slightly prefer if we can call it newRange/oldRange instead of newSelection/oldSelection since it's shorter and in Quill selection is mostly related to the module and range is object representing position info. Also we could just change all usage of == into === to keep things consistent, with the exception of an intentional comparison with null/undefined. Otherwise looks good and happy to have this edge case taken care of! |
@@ -449,7 +465,7 @@ function diff_halfMatch_(text1, text2) { | |||
* Any edit section can move as long as it doesn't cross an equality. | |||
* @param {Array} diffs Array of diff tuples. | |||
*/ | |||
function diff_cleanupMerge(diffs) { | |||
function diff_cleanupMerge(diffs, fix_unicode) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
newRange/oldRange sounds good. Took all feedback. I will try using the latest commit in Quill, maybe before merging. |
dgreensp
force-pushed the
dg-cursor-and-unicode
branch
2 times, most recently
from
da3e786
to
ea599b6
Oct 8, 2018
dgreensp
force-pushed the
dg-cursor-and-unicode
branch
from
ea599b6
to
f4e19f4
Oct 8, 2018
dgreensp
merged commit bc1e462
into
master
Oct 8, 2018
dgreensp
deleted the
dg-cursor-and-unicode
branch
Oct 8, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
dgreensp commentedOct 5, 2018
This PR makes the following changes:
diff(...)
in a roughly backwards-compatible way to 1) meet Quill's diffing needs for text editing, and 2) make it easier to return canonical diffs with correct unicode handlingdiff('aaa', 'aa', 1)
would delete the firsta
(under the notion that the user positioned the cursor at position 1 and then backspaced), whilediff('aaa', 'aa', 2)
would delete the seconda
, and so on. However, the implementation was flawed, and fixing it would have been very complex due to interactions with the diff optimizer. It failed on documents as simple asxaa
oraax
.{oldSelection: {index, length}, newSelection: {index, length}}
representing the selection range or text cursor (a range with length 0) before and after the change. If a number is given, it represents the position of a zero-lengtholdSelection
, with thenewSelection
being inferred. Using selection ranges allows cases such as forward-delete and typing to replace a range of text to be taken into account. The major difference from the old implementation when a number is given, besides working correctly on arbitrary splices, is that it only works if the entire diff is a splice at the cursor position. It doesn't try to "fix up" the diff around the cursor position in the presence of other changes like the old implementation. It seems unlikely that someone was using this argument and relying on that precise behavior.var
andfunction
). I pretty much wrote in ES5 style, though I have not made sure the code is ES5 clean. I did change==
to===
in a few places as a matter of style and changed some indentation so I could use my IDE's auto-formatter.