Skip to content

A listener_add report can extend beyond end of buffer. #18664

@paul-ollis

Description

@paul-ollis

Steps to reproduce

Save this as changes.vim.

func HandleChange(bufnr, start, end, added, changes)
    let g:report_number += 1
    let msg = printf(
        \ '%d: lines = %d -> %d, added = %d',
        \ g:report_number, a:start, a:end, a:added)
    call add(g:reports, msg)

    for d in a:changes
        let msg = printf(
            \ '    lines = %d -> %d, added = %d',
            \ d['lnum'], d['end'], d['added'])
        call add(g:reports, msg)
    endfor
endfunc

let g:report_number = 0
let g:reports = []

winpos 20 40
set lines=89
set columns=120
edit text1.txt
call listener_add('HandleChange', bufnr())

8,9 !cat text2.txt
undo
call listener_flush(bufnr())

new
call append(0, g:reports)

Create text1.txt with content:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

and text2.txt:

Line a
Line b
Line c
Line d
Line e

Run [g]vim -c 'source changes.vim'.

Expected behaviour

Just before the undo command is executed the buffer contains 13 lines:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line a
Line b
Line c
Line d
Line e
Line 10

The 3rd report is:

3: lines = 8 -> 15, added = -3
      lines = 8 -> 8, added = 2
      lines = 10 -> 15, added = -5

I would have expected the report to start "3: lines = 8 -> 13, added = -3".

I may just be misunderstanding, but this seems to make the overall start, end and added values of little value and require looping over the list of individual change reports.

I confess that I am not sure if this is a bug, or just a feature that needs clarifying in the help.

Version of Vim

IMproved 9.1 patches: 1-1813

Environment

Linux, running in Gvim.

Logs and stack traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions