Skip to content

Commit

Permalink
Merge pull request hadronized#186 from phaazon/feature/uppercase-labels
Browse files Browse the repository at this point in the history
Add (displayed) uppercase label support.
  • Loading branch information
hadronized authored Nov 16, 2021
2 parents b3f7021 + e2846f2 commit c987423
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
7 changes: 7 additions & 0 deletions doc/hop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ below.
Defaults:~
`inclusive_jump = false`

`uppercase_labels` *hop-config-uppercase_labels*
Display labels as uppercase. This option only affects the displayed
labels; you still select them by typing the keys on your keyboard.

Defaults:~
`uppercase_labels = false`

`extensions` *hop-config-extensions*
List-table of extensions to enable (names). As described in |hop-extension|,
extensions for which the name is in that list must have a `register(opts)`
Expand Down
1 change: 1 addition & 0 deletions lua/hop/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ M.case_insensitive = true
M.create_hl_autocmd = true
M.current_line_only = false
M.inclusive_jump = false
M.uppercase_labels = false

return M
17 changes: 12 additions & 5 deletions lua/hop/hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,27 @@ function M.create_hints(jump_targets, indirect_jump_targets, opts)
end

-- Create the extmarks for per-line hints.
function M.set_hint_extmarks(hl_ns, hints)
--
-- Passing `opts.uppercase_labels = true` will display the hint as uppercase.
function M.set_hint_extmarks(hl_ns, hints, opts)
for _, hint in pairs(hints) do
if vim.fn.strdisplaywidth(hint.label) == 1 then
local label = hint.label
if opts.uppercase_labels then
label = label:upper()
end

if vim.fn.strdisplaywidth(label) == 1 then
vim.api.nvim_buf_set_extmark(hint.jump_target.buffer, hl_ns, hint.jump_target.line, hint.jump_target.column - 1, {
virt_text = { { hint.label, "HopNextKey" } },
virt_text = { { label, "HopNextKey" } },
virt_text_pos = 'overlay',
hl_mode = 'combine',
priority = prio.HINT_PRIO
})
else
-- get the byte index of the second hint so that we can slice it correctly
local snd_idx = vim.fn.byteidx(hint.label, 1)
local snd_idx = vim.fn.byteidx(label, 1)
vim.api.nvim_buf_set_extmark(hint.jump_target.buffer, hl_ns, hint.jump_target.line, hint.jump_target.column - 1, { -- HERE
virt_text = { { hint.label:sub(1, snd_idx), "HopNextKey1" }, { hint.label:sub(snd_idx + 1), "HopNextKey2" } },
virt_text = { { label:sub(1, snd_idx), "HopNextKey1" }, { label:sub(snd_idx + 1), "HopNextKey2" } },
virt_text_pos = 'overlay',
hl_mode = 'combine',
priority = prio.HINT_PRIO
Expand Down
4 changes: 2 additions & 2 deletions lua/hop/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function M.hint_with_callback(jump_target_gtr, opts, callback)
hint_state.diag_ns = vim.diagnostic.get_namespaces()
for ns in pairs(hint_state.diag_ns) do vim.diagnostic.show(ns, 0, nil, { virtual_text = false }) end
end
hint.set_hint_extmarks(hl_ns, hints)
hint.set_hint_extmarks(hl_ns, hints, opts)
vim.cmd('redraw')

while h == nil do
Expand Down Expand Up @@ -232,7 +232,7 @@ function M.refine_hints(buf_handle, key, hint_state, callback, opts)
hint_state.hints = hints

clear_namespace(buf_handle, hint_state.hl_ns)
hint.set_hint_extmarks(hint_state.hl_ns, hints)
hint.set_hint_extmarks(hint_state.hl_ns, hints, opts)
vim.cmd('redraw')
else
M.quit(buf_handle, hint_state)
Expand Down

0 comments on commit c987423

Please sign in to comment.