Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extmarks not updated correctly in nvim_buf_attach on_lines event when using :m #28811

Open
TheBlob42 opened this issue May 17, 2024 · 0 comments
Labels
bug issues reporting wrong behavior marks marks, extmarks, decorations, virtual text, namespaces

Comments

@TheBlob42
Copy link
Contributor

Problem

Setting extmarks in the on_lines event of nvim_buf_attach for the updated lines results in wrong results when lines are moved via the :m command (e.g. :m .+2). When "moving" the line by cutting and pasting these problems do not occur, so it seems like specifically related to the :m command.

Wrapping the code for clearing the namespace and setting the extmarks into vim.schedule(...) makes it work.

Maybe this is related to #28107

Steps to reproduce

Use the following minimal.lua file:

local ns = vim.api.nvim_create_namespace('test')
vim.api.nvim_buf_attach(0, false, {
        on_lines = function(_,_,_,fl,_,llu)
            vim.print(fl .. ':' .. llu)

            vim.api.nvim_buf_clear_namespace(0, ns, fl, llu)

            for i = fl, llu - 1 do
                local first_char = vim.api.nvim_buf_get_lines(0, i, i + 1, false)[1]:sub(1, 1)
                vim.api.nvim_buf_set_extmark(0, ns, i, 0, {
                    virt_text = {{ first_char, 'WarningMsg' }},
                })
            end
        end
    }
)
  • start neovim using nvim -u NONE minimal.lua
  • source the minimal.lua file using source %
  • add a few new rows
    • every new row contains an extmark displaying first char of the line (only for demonstration purposes)
  • move one of the new lines up or down using the :m command (e.g. :m .+3)
    • the adjacent line to the moved line has the same (incorrect) extmark
    • the others have been updated accordingly

nvim_extmarks

Expected behavior

The extmarks are all updated correctly even when using the :m command

Neovim version (nvim -v)

0.10.0

Vim (not Nvim) behaves the same?

not applicable

Operating system/version

Ubuntu 20.04.6 LTS

Terminal name/version

GNOME Terminal 3.36.2

$TERM environment variable

xterm-256color

Installation

appimage

@TheBlob42 TheBlob42 added the bug issues reporting wrong behavior label May 17, 2024
@glepnir glepnir added the marks marks, extmarks, decorations, virtual text, namespaces label May 17, 2024
@justinmk justinmk added marks marks marks, extmarks, decorations, virtual text, namespaces and removed marks marks, extmarks, decorations, virtual text, namespaces marks labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior marks marks, extmarks, decorations, virtual text, namespaces
Projects
None yet
Development

No branches or pull requests

3 participants