Hi Bram,

On Tue, May 2, 2023 at 12:54 PM Bram Moolenaar <vim-dev-git...@256bit.org>
wrote:

>
> This part of the help is confusing and probably not right:
>
> The "byte" is -1 if text is added or removed.
>
> In the "from" dict this doesn't make sense. If text is added (and
> nothing modified) then "start" and "end should be equal, the position
> where the text is inserted. If text is removed then "start" gives the
> start of the removed text and "end" the end. The text exists, thus
> there is no reason to use -1.
>
>
>
If the "endbyte" is not -1, then removing a character cannot be
distinguished
from modifying a character as shown below:

Modifying the first character of a string:
  :echo diff(['abc'], ['xbc'])
   {'from': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': 0},
    'to': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': 0},
    'added': 0, 'modified': 1}

Adding a first character to a string:
  :echo diff(['bc'], ['abc'])
   {'from': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': -1},
    'to': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': 0},
    'added': 0, 'modified': 1}

In this case, if the "from.endbyte" is 0 instead of -1, then this case
cannot
be differentiated from the previous example.

Removing the first character from a string:
  :echo diff(['abc'], ['bc'])
   {'from': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': 0},
    'to': {'startidx': 0, 'startbyte': 0, 'endidx': 0, 'endbyte': -1},
    'added': 0, 'modified': 1}

In this case, if the "to.endbyte" is 0 instead of -1, then this case cannot
be differentiated from the first example.

There are some more examples where the "endbyte" or the "startbyte" is -1:

Removing a character from the middle of a string:
  :echo diff(['abc'], ['ac'])
   {'from': {'startidx': 0, 'startbyte': 1, 'endidx': 0, 'endbyte': 1},
    'to': {'startidx': 0, 'startbyte': 1, 'endidx': 0, 'endbyte': -1},
    'added': 0, 'modified': 1}

Adding a character to the middle of a string:
  :echo diff(['ac'], ['abc'])
   {'from': {'startidx': 0, 'startbyte': 1, 'endidx': 0, 'endbyte': -1},
    'to': {'startidx': 0, 'startbyte': 1, 'endidx': 0, 'endbyte': 1},
    'added': 0, 'modified': 1}

Removing the last character from a string:
  :echo diff(['abc'], ['ab'])
   {'from': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': 2},
    'to': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': -1},
    'added': 0, 'modified': 1}

Adding a character to the end of a string:
  :echo diff(['ab'], ['abc'])
   {'from': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': -1},
    'to': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': 2},
    'added': 0, 'modified': 1}

Modifying the last character in a string:
  :echo diff(['abc'], ['abx'])
   {'from': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': 2},
    'to': {'startidx': 0, 'startbyte': 2, 'endidx': 0, 'endbyte': 2},
    'added': 0, 'modified': 1}

Adding a new item:
  :echo diff(['a'], ['a', 'b'])
   {'from': {'startidx': 1, 'startbyte': -1, 'endidx': -1, 'endbyte': -1},
    'to': {'startidx': 1, 'startbyte': 0, 'endidx': 1, 'endbyte': 0},
    'added': 1, 'modified': 0}

Removing an item from the end:
  :echo diff(['a', 'b'], ['a'])
   {'from': {'startidx': 1, 'startbyte': 0, 'endidx': 1, 'endbyte': 0},
    'to': {'startidx': 1, 'startbyte': -1, 'endidx': -1, 'endbyte': -1},
    'added': -1, 'modified': 0}

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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7kYGQ85aJk_-0ifW1JDP071Gv-di3M5L80DcDE2g54U1w%40mail.gmail.com.

Raspunde prin e-mail lui