Skip to content

Commit

Permalink
fix: avoid removing words for current line on out of focus buffers
Browse files Browse the repository at this point in the history
Closes #433
  • Loading branch information
Saghen committed Dec 3, 2024
1 parent 38b3ad6 commit 2cbb02d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lua/blink/cmp/sources/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ local uv = vim.uv
local function get_buf_text(bufnr)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)

-- exclude word under the cursor
if bufnr ~= vim.api.nvim_get_current_buf() then return table.concat(lines, '\n') end

-- exclude word under the cursor for the current buffer
local line_number = vim.api.nvim_win_get_cursor(0)[1]
local column = vim.api.nvim_win_get_cursor(0)[2]
local line = lines[line_number]
if line ~= nil then
local start_col = column
while start_col > 1 do
local char = line:sub(start_col, start_col)
if char:match('[%w_\\-]') == nil then
start_col = start_col + 1
break
end
start_col = start_col - 1
end
local end_col = column
while end_col < #line do
local char = line:sub(end_col + 1, end_col + 1)
if char:match('[%w_\\-]') == nil then break end
end_col = end_col + 1
local start_col = column
while start_col > 1 do
local char = line:sub(start_col, start_col)
if char:match('[%w_\\-]') == nil then
start_col = start_col + 1
break
end
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)
start_col = start_col - 1
end
local end_col = column
while end_col < #line do
local char = line:sub(end_col + 1, end_col + 1)
if char:match('[%w_\\-]') == nil then break end
end_col = end_col + 1
end
lines[line_number] = line:sub(1, start_col) .. ' ' .. line:sub(end_col + 1)

return table.concat(lines, '\n')
end
Expand Down

0 comments on commit 2cbb02d

Please sign in to comment.