From 117eee03b4043bb2b81e43dad366026258c1b21d Mon Sep 17 00:00:00 2001 From: xzb <2598514867@qq.com> Date: Thu, 9 Jan 2025 02:58:08 +0800 Subject: [PATCH] use diff --- lua/blink/cmp/completion/list.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/blink/cmp/completion/list.lua b/lua/blink/cmp/completion/list.lua index bed5065a..37e05113 100644 --- a/lua/blink/cmp/completion/list.lua +++ b/lua/blink/cmp/completion/list.lua @@ -209,8 +209,13 @@ end ---------- Preview ---------- function list.restore_content() + -- compute the diff between the current cursor column and the cursor column when the request was sent. + local diff = vim.api.nvim_win_get_cursor(0)[2] - list.context.bounds.start_col + if diff <= 0 then return end local row = list.context.cursor[1] - 1 - vim.api.nvim_buf_set_text(0, row, 0, row, -1, { list.context.get_line() }) + + -- delete those chars added by previous auto-insert + vim.api.nvim_buf_set_text(0, row, list.context.bounds.start_col, row, vim.api.nvim_win_get_cursor(0)[2], { '' }) end function list.apply_preview(item)