fast-diff
fast-diff copied to clipboard
Editing position does not work correctly in 1.2.0
In 1.1.2 it works correctly:
node -e 'console.log(require(".")("aaaaa", "aaaa", 1))'
[ [ 0, 'a' ], [ -1, 'a' ], [ 0, 'aaa' ] ]
In 1.2.0 it does not work correctly:
node -e 'console.log(require(".")("aaaaa", "aaaa", 1))'
[ [ -1, 'a' ], [ 0, 'aaaa' ] ]
There are likely more cases, where the editing position does not have the desired effect.
Hi @gkubisa, we made some changes to the algorithm used when a numeric cursor position is given. Note that the cursor position has always been an index into the first string, so in the example you are giving, the insertion point is initially after the first "a," before one "a" is deleted. The old algorithm had serious flaws and did not work even in some simple cases. The new algorithm intentionally defaults to treating a simple deletion as a backwards deletion, as these are much more common than forwards deletions.
There is a new undocumented form of the cursor position argument that lets you specify old cursor position and new cursor position, or old and new selection ranges, which could help you.
Excellent, thank you @dgreensp ! The new form of the cursor position argument will indeed be useful to me. I think it would be good to document it, as it's a really nice and powerful feature, which people would not know about, unless they analysed the source code.