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

cursor not placed properly with autoinsert when cycling completions #942

Open
2 tasks done
stefanboca opened this issue Jan 8, 2025 · 2 comments · May be fixed by #953
Open
2 tasks done

cursor not placed properly with autoinsert when cycling completions #942

stefanboca opened this issue Jan 8, 2025 · 2 comments · May be fixed by #953
Labels
accept Applying a completion item to the buffer bug Something isn't working

Comments

@stefanboca
Copy link
Collaborator

Make sure you have done the following

  • Updated to the latest version of blink.cmp
  • Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

Say I type fori in lua. My completion menu looks like this:
image
I then select the next entry and the i disappears:
image
I then select the previous entry (the original) and the i is inserted, but the cursor is not moved, so the i is after the cursor:
image
I then accept the completion. The i remains inserted after the snippet:
image

auto_insert and preselect are enabled, as per default.

This might be a duplicate of #810, but I'm not sure.

-- Run with `nvim -u repro.lua`

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

---@diagnostic disable-next-line: missing-fields
require('lazy.minit').repro({
  spec = {
    {
      'saghen/blink.cmp',
      build = 'cargo build --release',
      opts = {
        keymap = { preset = 'enter', cmdline = { preset = 'default' } },
      },
    },
    {
      'neovim/nvim-lspconfig',
      dependencies = {
        -- for installing lua_ls. for whatever reason this doesn't work the first time. so close and reopen `nvim -u repro.lua`
        -- or run :MasonInstall lua-language-server
        { 'williamboman/mason.nvim', opts = {} },
        { 'williamboman/mason-lspconfig.nvim', opts = { ensure_installed = {"lua_ls"} } },
      },
      opts = {
        servers = {
          lua_ls = {},
        },
      },
      config = function(_, opts)
        local lspconfig = require('lspconfig')
        for server, config in pairs(opts.servers) do
          -- passing config.capabilities to blink.cmp merges with the capabilities in your
          -- `opts[server].capabilities, if you've defined it
          config.capabilities = require('blink.cmp').get_lsp_capabilities()
          lspconfig[server].setup(config)
        end
      end,
    },
  },
})

Relevant configuration

keymap = { preset = "enter" }

neovim version

NVIM v0.11.0-dev+1493-g4d9405991 Build type: RelWithDebInfo LuaJIT 2.1.1720049189

blink.cmp version

main

@stefanboca stefanboca added bug Something isn't working accept Applying a completion item to the buffer labels Jan 8, 2025
@xzbdmw
Copy link
Contributor

xzbdmw commented Jan 8, 2025

undo_preview inserts the extra i.

@xzbdmw
Copy link
Contributor

xzbdmw commented Jan 8, 2025

Rather than the concept of undo, how about remembering the context (line content, etc) when the request was sent, so we can restore the content when selection is changed, and treat each new auto_insert stateless.

#810 can also be solved by this approach, the cause is that su is not cleared by undo_preview's logic, as list.preview_undo.text_edit is not updated when user keeps typing, only when selection is changed.

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

Successfully merging a pull request may close this issue.

2 participants