Skip to content

Commit

Permalink
fix: add missing commit
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Dec 29, 2023
1 parent 6889a80 commit 14e9fed
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lua/treemonkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down Expand Up @@ -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 ]]
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 14e9fed

Please sign in to comment.