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

lightspeed intercepts the first <BS> during a change operation after a jump #140

Open
TheBlob42 opened this issue Mar 17, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@TheBlob42
Copy link
Contributor

After jumping via <Plug>Lightspeed_s, <Plug>Lightspeed_S, <Plug>Lightspeed_omni_s, <Plug>Lightspeed_gs, <Plug>Lightspeed_gS or <Plug>Lightspeed_omni_gs and calling a change operation (e.g. cw) lightspeed will intercept the first <BS> that I press. Afterwards everything works fine. Even if move the cursor after the jump via h or l the next change is still affected. But when I move the cursor after the jump with w, e, b or so the next change works fine.

Here is an example to better illustrate the issue (minimal config, only lightspeed installed and no further configuration):

  1. open nvim, enter insert mode and type some text (| is the cursor)
this is just some text for demonstration|
  1. press <esc> to go back to normal mode and jump to the word "some" by pressing Sso
this is just |some text for demonstration
  1. start changing text by pressing ce to delete the word "some" and insert some alternative
this is just yeah| text for demonstration
  1. press backspace and realize that nothing happens
this is just yeah| text for demonstration
  1. press backspace again, now the character before the cursor gets deleted properly, from now on backspace works fine again

From my own testing it only happens for the two character jump commands and only in combination with changing text. Deleting something after the jump and then entering insert mode does not show the described behavior.

I had a brief look in the source code and could see that you are handling the change operator and backspace in some cases, but from my short read I did not understand for what reason and if this could be the cause for this minor bug here. But maybe it is rather obvious for you why this is happening and if it could be avoided easily 🙂

@ggandor ggandor added the bug Something isn't working label Mar 17, 2022
@ggandor
Copy link
Owner

ggandor commented Mar 25, 2022

If I comment out handle-interrupted-change-op! in the exit forms, the same thing happens, so the problem is elsewhere. Maybe this is related to #124? ¯_(ツ)_/¯

@TheBlob42
Copy link
Contributor Author

TheBlob42 commented Apr 8, 2022

I have now found a very simple workaround for this issue:

edit: some adaptions to make it work with other buftypes

-- old:
-- autocmd User LightspeedSxLeave normal a

-- new (needs 0.7)
vim.api.nvim_create_autocmd('User', {
    pattern = 'LightspeedSxLeave',
    callback = function()
        local ignore = vim.tbl_contains({ 'terminal', 'prompt' }, vim.opt.buftype:get())
        if vim.opt.modifiable:get() and not ignore then
            vim.cmd('normal! a')
        end
    end,
})

Unfortunately I still have no clue what is causing the issue, but with this fix it at least does not bug me anymore 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants