diff --git a/lua/treemonkey.lua b/lua/treemonkey.lua index 20e5189..32354fa 100644 --- a/lua/treemonkey.lua +++ b/lua/treemonkey.lua @@ -22,9 +22,10 @@ local function getcharstr() end end ----@param opts { row: integer, col: integer, label: string, hi?: string, buf?: integer } -local function mark_label(opts) - return vim.api.nvim_buf_set_extmark(opts.buf or 0, M.namespace, opts.row, opts.col, { +---@param buf integer +---@param opts { row: integer, col: integer, label: string, hi: string } +local function mark_label(buf, opts) + return vim.api.nvim_buf_set_extmark(buf, M.namespace, opts.row, opts.col, { virt_text = { { opts.label, opts.hi or "@text.warning" } }, virt_text_pos = "overlay", }) @@ -184,18 +185,13 @@ local function choose_node(nodes, opts) return end - -- if choice is made by a label without upper case (e.g., 1, 2, 3, !, @, ...), - if opts.steps == 1 or first_label:lower() == first_label:upper() then - return first_choice - end - local ambiguity = positions[first_choice.row][first_choice.col] - if opts.steps == nil and #ambiguity == 1 then - return ambiguity[1] - end - - if opts.steps ~= nil and opts.steps ~= 2 then - error("TreemonkeyOpts.steps should be one of nil, 1 or 2") + if + opts.steps == 1 -- user wants to explicitly stop at here + or first_label:lower() == first_label:upper() -- choice is made by a label without upper case (e.g, 1, !, ...) + or (opts.steps == nil and #ambiguity == 1) -- second step is not required + then + return first_choice end --[[ second choice ]] @@ -243,11 +239,17 @@ end ---@param opts? TreemonkeyOpts ---@return TreemonkeyOpts local function init_opts(opts) - return vim.tbl_deep_extend("keep", opts or {}, { + local o = vim.tbl_deep_extend("keep", opts or {}, { highlight = { label = "@text.warning" }, labels = labels_default, experimental = {}, }) + + if o.steps ~= nil and o.steps ~= 1 and o.steps ~= 2 then + error("TreemonkeyOpts.steps should be one of nil, 1 or 2") + end + + return o end ---@param opts TreemonkeyOpts?