From a79082b64edac05522eebde7b32e16b93d5bbc84 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Wed, 18 Feb 2026 10:04:41 +0100 Subject: [PATCH] fix(multiline_paras): 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 behavior Result: - Inside FB call: jumps to next := or => - Outside FB call: behaves normally (inserts tab character) --- lua/scl/multiline_params.lua | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lua/scl/multiline_params.lua b/lua/scl/multiline_params.lua index 7769b0a..5073f3a 100644 --- a/lua/scl/multiline_params.lua +++ b/lua/scl/multiline_params.lua @@ -130,12 +130,62 @@ function M.fill_multiline_params() vim.api.nvim_win_set_cursor(0, { new_cursor_row, new_cursor_col }) 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() local cursor = vim.api.nvim_win_get_cursor(0) local row = cursor[1] local col = cursor[2] 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 function get_line_text(rownum)