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

illuminate.nvim does not refresh highlights after autojump #221

Open
xzbdmw opened this issue Apr 10, 2024 · 14 comments
Open

illuminate.nvim does not refresh highlights after autojump #221

xzbdmw opened this issue Apr 10, 2024 · 14 comments

Comments

@xzbdmw
Copy link

xzbdmw commented Apr 10, 2024

I have illuminate.nvim and it will highlight cursorword, but leap's autojump seems not trigger their detect of new cursorpos, only after I type the third char. Is it probably a fake cursor during autojump?

iShot_2024-04-10_08.35.15.mp4
@ggandor
Copy link
Owner

ggandor commented Apr 10, 2024

Are you using stable or nightly (0.10) nvim?

@xzbdmw
Copy link
Author

xzbdmw commented Apr 10, 2024

nightly

@ggandor
Copy link
Owner

ggandor commented Apr 10, 2024

Does this snippet fix the issue?

vim.api.nvim_create_augroup('LeapIlluminate', {})
vim.api.nvim_create_autocmd('User', {
  pattern = 'LeapPatternPost',
  callback = function ()
    vim.api.nvim_exec_autocmds('CursorMoved', {
      group = 'vim_illuminate_v2_augroup'
    })
  end,
  group = 'LeapIlluminate',
})

@ggandor
Copy link
Owner

ggandor commented Apr 10, 2024

Is it probably a fake cursor during autojump?

No, on nightly it's the real one.

@ggandor
Copy link
Owner

ggandor commented Apr 10, 2024

You might ask this in the illuminate repo too.

@xzbdmw
Copy link
Author

xzbdmw commented Apr 10, 2024

Hi, if I use this function

vim.api.nvim_create_augroup("LeapIlluminate", {})
vim.api.nvim_create_autocmd("User", {
    pattern = "LeapPatternPost",
    callback = function()
        local winid = vim.api.nvim_get_current_win()
        local cursor = vim.api.nvim_win_get_cursor(winid)
        -- __AUTO_GENERATED_PRINT_VAR_START__
        print([==[function cursor:]==], vim.inspect(cursor)) -- __AUTO_GENERATED_PRINT_VAR_END__
        require("illuminate.engine").refresh_references(_, _, "hi")
    end,
    group = "LeapIlluminate",
})

the cursor pos is not updated when autojump, so illuminate can't update too

@ggandor
Copy link
Owner

ggandor commented Apr 10, 2024

Sorry, try LeapSelectPre as the pattern (PatterPost is before the jump).

@xzbdmw
Copy link
Author

xzbdmw commented Apr 10, 2024

If I add a redraw command under https://github.com/RRethy/vim-illuminate/blob/305bf07b919ac526deb5193280379e2f8b599926/lua/illuminate/highlight.lua#L51
it works, but need to work with autocmd above, and only redraw when triggered by that autocmd. otherwise makes ui laggy.
my guess is it takes time to find references and highlight, and leap maybe using getchar which freeze the ui.
edit: actually it is a little tricky, if redraw too late(search for reference takes too long), the label of leap is invisible but still can type to jump.

Edit: change redraw to redraw! works in every time.

If someone face the same problem, here is full code

vim.api.nvim_create_augroup("LeapIlluminate", {})
_G.leapjump = false
vim.api.nvim_create_autocmd("User", {
    pattern = "LeapSelectPre",
    callback = function()
        _G.leapjump = true
        local buf = vim.api.nvim_get_current_buf()
        local win = vim.api.nvim_get_current_win()
        require("illuminate.engine").refresh_references(buf, win)
    end,
    group = "LeapIlluminate",
})


function M.buf_highlight_references(bufnr, references)
    if config.min_count_to_highlight() > #references then
        return
    end
    local cursor_pos = util.get_cursor_pos()
    for _, reference in ipairs(references) do
        if config.under_cursor(bufnr) or not ref.is_pos_in_ref(cursor_pos, reference) then
            M.range(bufnr, reference[1], reference[2], reference[3])
        end
    end
    if _G.leapjump then
        vim.cmd("redraw!")
        _G.leapjump = false
    end
end

https://github.com/RRethy/vim-illuminate/blob/305bf07b919ac526deb5193280379e2f8b599926/lua/illuminate/highlight.lua#L16

@jamestansx

This comment was marked as off-topic.

@jamestansx

This comment was marked as off-topic.

@einCyberSimon

This comment was marked as off-topic.

@ggandor

This comment was marked as off-topic.

@einCyberSimon

This comment was marked as off-topic.

@ggandor ggandor changed the title Cursor don't update after autojump illuminate.nvim does not refresh highlights after autojump May 20, 2024
@ggandor

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants