Skip to content

Commit

Permalink
fix: set the extmarks column value smaller than line length
Browse files Browse the repository at this point in the history
  • Loading branch information
smoka7 committed Jul 26, 2024
1 parent 036462a commit f30da70
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lua/hop/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ local function add_virt_cur(ns)
end
end

--- verify that column value is always smaller than line length
---@param wctx WindowContext
local function sanitize_cols(wctx)
local start_line = api.nvim_buf_get_lines(wctx.buf_handle, wctx.line_range[1], wctx.line_range[1] + 1, false)
if #start_line < wctx.column_range[1] then
wctx.column_range[1] = #start_line
end
local end_line = api.nvim_buf_get_lines(wctx.buf_handle, wctx.line_range[2], wctx.line_range[2] + 1, false)
if #end_line < wctx.column_range[2] then
wctx.column_range[2] = #end_line
end
end

-- Dim everything out to prepare the hop session for all windows
---@param hint_state HintState
---@param opts Options
Expand All @@ -106,6 +119,7 @@ local function apply_dimming(hint_state, opts)

for _, wctx in ipairs(hint_state.all_ctxs) do
-- Set the highlight of unmatched lines of the buffer.
sanitize_cols(wctx)
local start_line, end_line = window.line_range2extmark(wctx.line_range)
local start_col, end_col = window.column_range2extmark(wctx.column_range)
api.nvim_buf_set_extmark(wctx.buf_handle, hint_state.dim_ns, start_line, start_col, {
Expand Down

0 comments on commit f30da70

Please sign in to comment.