-
Notifications
You must be signed in to change notification settings - Fork 10
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
Unexpected result of getSelectText()
#47
Conversation
Bug, when vim.api.nvim_get_mode().mode == "n" |
Also, find 1 And another problem is that the use of |
ci: introduce `mini.test` test
…ch.nvim into issue-wrong_select
child.lua_func(getSelectedText, ".", selection_mode) | ||
) | ||
end | ||
-- T["param"]["old"]["at_command"] = function(selection_mode, coord) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes, that test suits works, sometimes it doesn't, but I have refactored the function for that use case, so this doesn't matter.
Hi, this looks really good! I could merge this PR right now~ But there is a little problem I met when I was testing it locally ( Here is the error msg and some info might be helpful. But if you think it not a big issue, I also think there's no need to bother with it right now.(Cause I don't think many user will user this command this way) Error executing Lua callback: ...uments/oatnil/release/scratch.nvim/lua/scratch/utils.lua:89: attempt to index a nil value CodeCompanion ─Looking at the error and the code, the issue is in the Here's the fixed version of the local function getSelectedText(mark, selection_mode)
local pos1 = vim.fn.getpos("v")
local pos2 = vim.fn.getpos(mark)
local lines = {}
-- Validate positions
if not pos1 or not pos2 then
return lines
end
local start_row, start_col = pos1[2], pos1[3]
local end_row, end_col = pos2[2], pos2[3]
-- Get text from buffer
local text = vim.api.nvim_buf_get_lines(0, start_row - 1, end_row, true)
-- Check if text is empty
if not text or #text == 0 then
return lines
end
end_row = end_row - start_row + 1
start_row = 1
if selection_mode == "v" then
if text[1] then
table.insert(lines, text[1]:sub(start_col))
for i = start_row + 1, end_row do
if text[i] then
table.insert(lines, text[i])
end
end
if lines[end_row] then
lines[end_row] = lines[end_row]:sub(1, end_col)
end
end
elseif selection_mode == "V" then
for i = start_row, end_row do
if text[i] then
table.insert(lines, text[i])
end
end
elseif selection_mode == vim.api.nvim_replace_termcodes("<C-V>", true, true, true) then
for i = start_row, end_row do
if text[i] then
table.insert(lines, text[i]:sub(start_col, end_col))
end
end
end
return lines
end |
@LintaoAmons Reason of these issue because i'm not reacting correctly in There are two use-flow branches: select and range. When I process a range of branches, I think of it as selection, and it is a bug. if mode ~= "n" then
opts = { content = utils.getSelectedText(".", mode) }
elseif args.range > 0 then
opts = { content = vim.api.nvim_buf_get_lines(0, args.line1 - 1, args.line2, true) }
end I guess that correct way. But now you must use keybinding to perform select branch. Maybe there is a magical way to determine in command mode whether it is selected or just an range, but I don't know of that way. Also, it is necessary to implement tests that will test this, and for that reason, What about your CodeCompanion. I don't really know how |
I saw you pushed some new commits, let me know if you think it's ready to merge |
@LintaoAmons Specifically within the work of this pull request, I wanted to fix Generally speaking, it is necessary to write tests for the |
I would say it's not required within this PR. I tested my workflow and it's fine. So if you are confident (comfortable) I could merge it anytime |
And how to understand it. The mode is determined correctly.
but if you do it using keymap, it does not give the correct result
|
Hi @AgatZan , I saw you haven't pushed any new commits now, I tested it locally with my workflow. It's working fine. |
Hi @LintaoAmons. In general, I see no reason to not push. All commit from those i think can actually be omitted, it's just my inner perfectionism that haunts me. |
What I mean by "unexpected".
Maybe it's just because I don't really understand the use case of
getSelectedText()
, but I guess that function will catch the text now under selection, but the'<
mark contain last selected region.