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

fix: auto hide cmp windows when exec snippet_forward/snippet_backward #537

Closed
wants to merge 1 commit into from

Conversation

Parsifa1
Copy link
Contributor

@Parsifa1 Parsifa1 commented Dec 13, 2024

maybe useful :)

If there is something inappropriate, you can modify it to something better, but I think this behavior should be necessary.

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

I think we should instead figure out why buffer_events doesn't emit a cursor moved when jumping between placeholders. It seems likely it's caused by using CursorMovedI instead of CursorMoved and checking if the mode is i or s

@Parsifa1
Copy link
Contributor Author

@Saghen oh, i discovered another bug on the keymap setting, and i didn't find an good way to resolve it:

https://github.com/saghen/blink.cmp/blob/54d1a980595e056e7be45a10d1cc8c34159f6d74/lua/blink/cmp/keymap/apply.lua#L40-L44

here, if you use some self-made keymap like:

["<Tab>"] = {
    function(cmp)
        return cmp.snippet_forward()
    end,
    "select_next",
    "fallback",
},

it wont register the select mode keymap, which cause some no-response

do you have some good ideas?

@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

Fixed on main

@Parsifa1
Copy link
Contributor Author

Parsifa1 commented Dec 13, 2024

thanks for your really quick response!

with this, we will get some really cool keymap:

["<Tab>"] = {
    function(cmp)
        local ls = require "luasnip"
        local buf = vim.api.nvim_get_current_buf()
        if not ls.session or not ls.session.current_nodes[buf] or ls.session.jump_active then
            return false
        end

        local current_node = ls.session.current_nodes[buf]
        local current_start, current_end = current_node:get_buf_position()
        current_start[1] = current_start[1] + 1 -- (1, 0) indexed
        current_end[1] = current_end[1] + 1 -- (1, 0) indexed
        local cursor = vim.api.nvim_win_get_cursor(0)
        if
            cursor[1] < current_start[1]
            or cursor[1] > current_end[1]
            or cursor[2] < current_start[2]
            or cursor[2] > current_end[2]
        then
            ls.unlink_current()
        end
        return cmp.snippet_forward()
    end,
    "select_next",
    "fallback",
},

with this, if you are jumpping in the snippet and delete it in the middle, it will automatically delete the snippet-node, which your <tab> wont jumps strangely in the original location

@Parsifa1 Parsifa1 closed this Dec 13, 2024
@Parsifa1
Copy link
Contributor Author

Parsifa1 commented Dec 13, 2024

I think we should instead figure out why buffer_events doesn't emit a cursor moved when jumping between placeholders. It seems likely it's caused by using CursorMovedI instead of CursorMoved and checking if the mode is i or s

you are right.
https://github.com/saghen/blink.cmp/blob/f99b03c756b32680eea28e89f95e3c6987cc6c80/lua/blink/cmp/lib/buffer_events.lua#L66-L69

I changed the "CursorMovedI" on the autocmd to "CursorMoved" and it was fixed.
I dont know if it will cause sth going wrong, but we don't have sth like CursorMovedS

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

Successfully merging this pull request may close these issues.

2 participants