Skip to content

Commit

Permalink
feat(config): add option to reorient the source window after jump
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Jun 11, 2023
1 parent c59af25 commit 4df9092
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975-

![preview](https://github.com/Bekaboo/dropbar.nvim/assets/76579810/93f33b90-4f42-459c-861a-1e70114ba6f2)

- [x] Reorient the source window on previewing or after jumping to a symbol

- [ ] Add hover highlights and preview for symbols shown in the winbar

- [ ] Add options to reorient the source window after jumping to a symbol

- [ ] Preview symbols (files) from `path` source

Expand Down Expand Up @@ -301,6 +302,22 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975-
end
end,
},
jump = {
---@param win integer source window id
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(win, range)
local view = vim.fn.winsaveview()
local win_height = vim.api.nvim_win_get_height(win)
local topline = range.start.line - math.floor(win_height / 4)
if
topline > view.topline
and topline + win_height < vim.fn.line('$')
then
view.topline = topline
vim.fn.winrestview(view)
end
end,
},
},
bar = {
---@type dropbar_source_t[]|fun(buf: integer, win: integer): dropbar_source_t[]
Expand Down Expand Up @@ -716,6 +733,24 @@ the symbols:
end
end
```
- `opts.symbol.jump.reorient`: `fun(win: integer, range: {start: {line: integer, character: integer}, end: {line: integer, character: integer}})`
- Function to reorient the source window after jumping to symbol given
the source window `win` and the range of the symbol `range`
- Default:
```lua
function(win, range)
local view = vim.fn.winsaveview()
local win_height = vim.api.nvim_win_get_height(win)
local topline = range.start.line - math.floor(win_height / 4)
if
topline > view.topline
and topline + win_height < vim.fn.line('$')
then
view.topline = topline
vim.fn.winrestview(view)
end
end,
```

#### Bar

Expand Down
19 changes: 18 additions & 1 deletion doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ highly-customizable 'winbar' with drop-down menu support and mutiple backends.
This features requires 'mousemoveevent' to be enabled.
- Preview symbols in their source windows when hovering over them in the
drop-down menu
- Reorient the source window on previewing or after jumping to a symbol

TODO

- Add hover highlights and preview for symbols shown in the winbar
- Add options to reorient the source window after jumping to a symbol
- Preview symbols (files) from `path` source
- Add more actions other than `jump` and `preview`, e.g. `rename`,
`delete`, `select`, etc.
Expand Down Expand Up @@ -329,7 +329,24 @@ the symbols:
end
end
<
- `opts.symbol.jump.reorient`: `fun(win: integer, range: {start: {line: integer, character: integer}, end: {line: integer, character: integer}})`
- Function to reorient the source window after jumping to symbol given
the source window `win` and the range of the symbol `range`
- Default: >lua

function(win, range)
local view = vim.fn.winsaveview()
local win_height = vim.api.nvim_win_get_height(win)
local topline = range.start.line - math.floor(win_height / 4)
if
topline > view.topline
and topline + win_height < vim.fn.line('$')
then
view.topline = topline
vim.fn.winrestview(view)
end
end,
<
..............................................................................
BAR *dropbar-configuration-options-bar*

Expand Down
3 changes: 3 additions & 0 deletions lua/dropbar/bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ function dropbar_symbol_t:jump()
self.range.start.line + 1,
self.range.start.character,
})
vim.api.nvim_win_call(self.win, function()
configs.opts.symbol.jump.reorient(self.win, self.range)
end)
end

---Preview the symbol in the source window
Expand Down
16 changes: 16 additions & 0 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ M.opts = {
end
end,
},
jump = {
---@param win integer source window id
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(win, range)
local view = vim.fn.winsaveview()
local win_height = vim.api.nvim_win_get_height(win)
local topline = range.start.line - math.floor(win_height / 4)
if
topline > view.topline
and topline + win_height < vim.fn.line('$')
then
view.topline = topline
vim.fn.winrestview(view)
end
end,
},
},
bar = {
---@type dropbar_source_t[]|fun(buf: integer, win: integer): dropbar_source_t[]
Expand Down

0 comments on commit 4df9092

Please sign in to comment.