Skip to content

Commit

Permalink
Minimize changes to simplify implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
dcampos committed Aug 13, 2023
1 parent fb3e42f commit c602675
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
5 changes: 2 additions & 3 deletions doc/snippy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,8 @@ virtual_markers ~

{
enabled = false,
empty = '␣',
left = '❬',
right = '❭',
empty = '',
left = '',
hl_group = 'VirtualTextHint',
}

Expand Down
29 changes: 7 additions & 22 deletions lua/snippy/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ setmetatable(M, {
---@param end_right_gravity number
---@return number Extmark identifier
---@return number? Extmark identifier
local function add_mark(id, startrow, startcol, endrow, endcol, right_gravity, end_right_gravity, end_id, active)
local function add_mark(id, startrow, startcol, endrow, endcol, right_gravity, end_right_gravity, active)
local config = shared.config
local opts = {
id = id,
Expand All @@ -49,27 +49,18 @@ local function add_mark(id, startrow, startcol, endrow, endcol, right_gravity, e
right_gravity = right_gravity,
end_right_gravity = end_right_gravity,
}
if end_id then
api.nvim_buf_del_extmark(0, shared.namespace, end_id)
end_id = nil
end
if vim.fn.has('nvim-0.10') == 1 and config.virtual_markers.enabled then
if not active then
opts.virt_text_pos = 'inline'
if startrow == endrow and startcol == endcol then
opts.virt_text = { { config.virtual_markers.empty, config.virtual_markers.hl_group } }
else
opts.virt_text = { { config.virtual_markers.left, config.virtual_markers.hl_group } }
end_id = api.nvim_buf_set_extmark(0, shared.namespace, endrow, endcol, {
virt_text_pos = 'inline',
virt_text = { { config.virtual_markers.right, config.virtual_markers.hl_group } },
right_gravity = end_right_gravity,
})
end
end
end
local mark = api.nvim_buf_set_extmark(0, shared.namespace, startrow, startcol, opts)
return mark, end_id
return mark
end

local function activate_parents(number)
Expand All @@ -78,9 +69,7 @@ local function activate_parents(number)
local stop = M.state().stops[n]
local from, to = stop:get_range()
local mark_id = stop.mark
local end_id = stop.end_mark
local _, end_mark = add_mark(mark_id, from[1], from[2], to[1], to[2], false, true, end_id, true)
stop.end_mark = end_mark
local _ = add_mark(mark_id, from[1], from[2], to[1], to[2], false, true, true)
end
end

Expand All @@ -93,9 +82,7 @@ local function activate_stop_and_parents(number)
if stop.id == value.id then
local from, to = stop:get_range()
local mark_id = stop.mark
local end_id = stop.end_mark
local _, end_mark = add_mark(mark_id, from[1], from[2], to[1], to[2], false, true, end_id, true)
stop.end_mark = end_mark
local _ = add_mark(mark_id, from[1], from[2], to[1], to[2], false, true, true)
activate_parents(n)
end
end
Expand Down Expand Up @@ -188,7 +175,7 @@ function M.add_stop(spec, pos)
table.insert(
stops,
pos,
Stop.new({ id = spec.id, traversable = is_traversable(), mark = smark, end_mark = emark, spec = spec })
Stop.new({ id = spec.id, traversable = is_traversable(), mark = smark, spec = spec })
)
M.state().stops = stops
end
Expand Down Expand Up @@ -218,8 +205,7 @@ function M.deactivate_stops()
for _, stop in ipairs(M.state().stops) do
local from, to = stop:get_range()
local mark_id = stop.mark
local _, end_id = add_mark(mark_id, from[1], from[2], to[1], to[2], true, true, stop.end_mark, false)
stop.end_mark = end_id
local _ = add_mark(mark_id, from[1], from[2], to[1], to[2], true, true, false)
end
end

Expand All @@ -243,8 +229,7 @@ function M.fix_current_stop()
if new ~= old and current_line:sub(1, #old) == old then
local stop = M.stops[M.current_stop]
local from, to = stop:get_range()
local _, end_mark = add_mark(stop.mark, from[1], #old, to[1], to[2], false, true)
stop.end_mark = end_mark
local _ = add_mark(stop.mark, from[1], #old, to[1], to[2], false, true)
end
end

Expand Down
7 changes: 3 additions & 4 deletions lua/snippy/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
local default_config = {
snippet_dirs = nil,
local_snippet_dir = '.snippets',
hl_group = nil,
hl_group = 'SnippyPlaceholder',
scopes = {},
mappings = {},
choice_delay = 100,
Expand All @@ -38,9 +38,8 @@ local default_config = {
virtual_markers = {
enabled = false,
empty = '',
left = '',
right = '',
hl_group = 'VirtualTextHint',
left = '',
hl_group = 'SnippyMarker',
},
}

Expand Down

0 comments on commit c602675

Please sign in to comment.