Hi Bram,
On Mon, May 1, 2023 at 10:22 AM vim-dev ML <[email protected]>
wrote:
>
> > I am attaching some examples to describe the return value of this
> function.
> >
> > Example 1:
> > ---------- old text -----------
> > aaaaaa
> > aaaaaa
> > aaaaaa
> > --------------------------------
> >
> > ---------- new text -----------
> > aaaxx
> > xxxxxx
> > xxaaa
> > ----------------------------------
> >
> > The modification starts at index 0 and byte 3 and ends at index 2 byte 2
> in
> > the
> > old text. In the new text, the changes start at index 0 byte 3 and end at
> > index
> > 2 byte 1. In this case, the diff() function returns the following:
> >
> > [{'from': {'start': {'idx': 0, 'byte': 3}, 'end': {'idx': 2, 'byte': 2}},
> > 'to': {'start': {'idx': 0, 'byte': 3}, 'end': {'idx': 2, 'byte': 1}}}]
>
> So, how does one decide whether items were inserted or removed?
> I think that's by computing the size in items of "from" and doing the
> same for "to" and then they turn out to be equal. If someone cares
> about items being inserted/deleted this is a bit of an indirect way to
> find out.
>
I have updated the PR to include the "count" item to "from" and "to".
It indicates the number of items added or modified.
The way to interpret the "from" and "to" items is:
The text beginning at the "start" item and ending at the "end" item in
"from" is replaced by the text beginning at the "start" item and ending
at the "end" item in "to" in a diff hunk.
>
>
> > Example 2:
> > ---------- old text -----------
> > aaaaaa
> > bbbbbb
> > cccccc
> > --------------------------------
> >
> > ---------- new text -----------
> > aaaaaa
> > ----------------------------------
> >
> > In the old text, the modification starts at index 1 byte 0 and ends at
> > index 2 byte 5.
> > In the new text, the modification starts at index 1. But the byte cannot
> > be calculated
> > as the line is removed. Similarly the end of the modification also cannot
> > be calculated.
> > In this case, the diff() function returns the following:
> >
> > [{'from': {'start': {'idx': 1, 'byte': 0}, 'end': {'idx': 2, 'byte': 5}},
> > 'to': {'start': {'idx': 1, 'byte': -1}, 'end': {'idx': -1, 'byte': -1}}}]
>
> Now how does one compute the number of items inserted/removed? Is it
> true that when "to" has an "end" with index -1, that there are no items
> at all? Not sure that is always true.
>
>
> > Example 3:
> > ---------- old text -----------
> > aaaaaa
> > --------------------------------
> >
> > ---------- new text -----------
> > aaaaaa
> > bbbbbb
> > cccccc
> > ----------------------------------
> >
> > In the old text, the modification starts at index 1. But the starting
> byte
> > and ending index/byte
> > cannot be calculated. In the new text, the change starts at index 1 byte
> 0
> > and ends at
> > index 2 byte 5. In this case, the diff() function returns the following:
> >
> > [{'from': {'start': {'idx': 1, 'byte': -1}, 'end': {'idx': -1, 'byte':
> -1}},
> > 'to': {'start': {'idx': 1, 'byte': 0}, 'end': {'idx': 2, 'byte': 5}}}]
>
> So the "from" position indicates "end of the list". And the "to" info
> has two items, thus two items have been added.
>
> I hope you see that, depending on what the user of the function wants to
> know, the returned value can be hard to understand.
>
>
>
Hopefully the new "count" item will help with this.
Regards,
Yegappan
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/CAAW7x7mEuTY1WDhAH3M58gFXw8OpC60u1Xa4wjLL%2B7XY%3Ddn9ag%40mail.gmail.com.