Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vitual text at cursorline showing index/group/total #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/glance/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,14 @@ local function get_lsp_method_label(method_name)
return utils.capitalize(lsp.methods[method_name].label)
end

_G.Total_Count = 0
function List:setup(opts)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to pass this information to preview, do you have any suggestions?

self.groups =
process_locations(opts.results, opts.position_params, opts.offset_encoding)
local group, location =
find_starting_group_and_location(self.groups, opts.position_params)

_G.Total_Count = #opts.results
folds.reset()
folds.open(group.filename)

Expand Down
51 changes: 51 additions & 0 deletions lua/glance/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Preview.__index = Preview

local touched_buffers = {}

local virt_text_ns = vim.api.nvim_create_namespace('glance-current-count')

local winhl = {
'Normal:GlancePreviewNormal',
'CursorLine:GlancePreviewCursorLine',
Expand Down Expand Up @@ -45,7 +47,49 @@ local float_win_opts = {
local function clear_hl(bufnr)
if vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_clear_namespace(bufnr, config.namespace, 0, -1)
vim.api.nvim_buf_clear_namespace(bufnr, virt_text_ns, 0, -1)
end
end

local function refresh_virtual_text(
bufnr,
winnr,
cur_index,
group_count,
total_count
)
vim.api.nvim_buf_clear_namespace(bufnr, virt_text_ns, 0, -1)
if total_count == group_count then
vim.api.nvim_buf_set_extmark(
bufnr,
virt_text_ns,
vim.api.nvim_win_get_cursor(winnr)[1] - 1,
0,
{
virt_text = {
{ '[' .. cur_index .. '/' .. total_count .. ']', 'NoiceVirtualText' },
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The highlight name is waiting for your decision:)

virt_text_pos = 'eol',
}
)
else
vim.api.nvim_buf_set_extmark(
bufnr,
virt_text_ns,
vim.api.nvim_win_get_cursor(winnr)[1] - 1,
0,
{
virt_text = {
{
'[' .. cur_index .. '/' .. group_count .. '/' .. total_count .. ']',
'NoiceVirtualText',
},
},
virt_text_pos = 'eol',
}
)
end
vim.cmd('redraw')
end

function Preview.create(opts)
Expand Down Expand Up @@ -263,6 +307,13 @@ function Preview:update(item, group)
{ item.start_line + 1, item.start_col }
)

refresh_virtual_text(
item.bufnr,
self.winnr,
item.index,
#group.items,
_G.Total_Count
)
vim.api.nvim_win_call(self.winnr, function()
vim.cmd('norm! zv')
vim.cmd('norm! zz')
Expand Down