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)