fix(multiline_paras): <Tab> behavior outside of fb/function

The function searches for := or => patterns anywhere in the code,
without verifying that the cursor is inside an FB/Function call context

Added is_inside_fb_call() function (lines 133-176):
- Traces backwards from cursor position
- Tracks parenthesis depth to skip nested calls
- Finds the opening ( of an FB call and checks if the name before it is a known variable
- Returns true only if cursor is inside an FB/Function call

Modified jump_to_next_param() (lines 178-189):
- Now returns false immediately if not inside an FB call context
- This causes the keymap to fall back to normal <Tab> behavior

Result:
- Inside FB call: <Tab> jumps to next := or =>
- Outside FB call: <Tab> behaves normally (inserts tab character)
This commit is contained in:
2026-02-18 10:04:41 +01:00
parent 1e50b596de
commit a79082b64e
+50
View File
@@ -130,12 +130,62 @@ function M.fill_multiline_params()
vim.api.nvim_win_set_cursor(0, { new_cursor_row, new_cursor_col }) vim.api.nvim_win_set_cursor(0, { new_cursor_row, new_cursor_col })
end end
local function is_inside_fb_call(bufnr, cursor_row, cursor_col)
local function get_line_text(rownum)
return vim.api.nvim_buf_get_lines(bufnr, rownum - 1, rownum, false)[1] or ""
end
local known_vars = get_known_variables(bufnr)
local paren_depth = 0
local found_fb_call_start = false
for i = cursor_row, 1, -1 do
local line = get_line_text(i)
local line_to_cursor = (i == cursor_row) and line:sub(1, cursor_col) or line
for j = #line_to_cursor, 1, -1 do
local char = line_to_cursor:sub(j, j)
if char == ")" then
paren_depth = paren_depth + 1
elseif char == "(" then
if paren_depth > 0 then
paren_depth = paren_depth - 1
else
local before_paren = line_to_cursor:sub(1, j - 1)
local var_match = before_paren:match("#?([%w_]+)%s*$")
if var_match and known_vars[var_match] then
return true
end
found_fb_call_start = true
break
end
end
end
if found_fb_call_start then
break
end
if line:match("^%s*END_") or line:match("^%s*BEGIN") then
break
end
end
return false
end
function M.jump_to_next_param() function M.jump_to_next_param()
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1] local row = cursor[1]
local col = cursor[2] local col = cursor[2]
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
if not is_inside_fb_call(bufnr, row, col) then
return false
end
local total_lines = vim.api.nvim_buf_line_count(bufnr) local total_lines = vim.api.nvim_buf_line_count(bufnr)
local function get_line_text(rownum) local function get_line_text(rownum)