Skip to content

Commit

Permalink
refactor(config): better preivew reorient
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Jun 11, 2023
1 parent d996e4d commit c59af25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975-
symbol = {
preview = {
---Reorient the preview window on previewing a new symbol
---@param win integer source window
---@param _ integer source window id, ignored
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(win, range)
if vim.fn.line('w$') <= range['end'].line then
reorient = function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview()
view.topline = range.start.line
- math.floor(1 / 4 * vim.api.nvim_win_get_height(win))
view.topline = view.topline + invisible
vim.fn.winrestview(view)
end
end,
Expand Down Expand Up @@ -707,11 +707,11 @@ the symbols:
the source window `win` and the range of the symbol `range`
- Default:
```lua
function(win, range)
if vim.fn.line('w$') <= range['end'].line then
function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview()
view.topline = range.start.line
- math.floor(1 / 4 * vim.api.nvim_win_get_height(win))
view.topline = view.topline + invisible
vim.fn.winrestview(view)
end
end
Expand Down
9 changes: 5 additions & 4 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ the symbols:
- Function to reorient the source window when previewing symbol given
the source window `win` and the range of the symbol `range`
- Default: >lua
function(win, range)
if vim.fn.line('w$') <= range['end'].line then

function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview()
view.topline = range.start.line
- math.floor(1 / 4 * vim.api.nvim_win_get_height(win))
view.topline = view.topline + invisible
vim.fn.winrestview(view)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ M.opts = {
symbol = {
preview = {
---Reorient the preview window on previewing a new symbol
---@param win integer source window
---@param _ integer source window id, ignored
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(win, range)
if vim.fn.line('w$') <= range['end'].line then
reorient = function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview()
view.topline = range.start.line
- math.floor(1 / 4 * vim.api.nvim_win_get_height(win))
view.topline = view.topline + invisible
vim.fn.winrestview(view)
end
end,
Expand Down

0 comments on commit c59af25

Please sign in to comment.