-
Notifications
You must be signed in to change notification settings - Fork 28
/
dropbar.txt
2887 lines (2291 loc) · 96.3 KB
/
dropbar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*dropbar.txt* IDE-like breadcrumbs, out of the box
*dropbar.nvim.txt*
*dropbar*
*dropbar.nvim*
dropbar.nvim by Bekaboo
==============================================================================
CONTENTS *dropbar-table-of-contents*
1. Features |dropbar-features|
2. Requirements |dropbar-requirements|
3. Installation |dropbar-installation|
4. Usage |dropbar-usage|
4.1 Usage with `vim.ui.select` |dropbar-usage-with-ui-select|
5. Configuration |dropbar-configuration|
5.1 Options |dropbar-configuration-options|
5.1.1 Bar |dropbar-configuration-options-bar|
5.1.2 Menu |dropbar-configuration-options-menu|
5.1.3 Fzf |dropbar-configuration-options-fzf|
5.1.4 Icons |dropbar-configuration-options-icons|
5.1.5 Symbol |dropbar-configuration-options-symbol|
5.1.6 Sources |dropbar-configuration-options-sources|
5.1.6.1 Path |dropbar-configuration-options-sources-path|
5.1.6.2 Treesitter |dropbar-configuration-options-sources-treesitter|
5.1.6.3 LSP |dropbar-configuration-options-sources-lsp|
5.1.6.4 Markdown |dropbar-configuration-options-sources-markdown|
5.1.6.5 Terminal |dropbar-configuration-options-sources-terminal|
5.2 API |dropbar-configuration-api|
5.3 Utility Functions |dropbar-configuration-utility-functions|
5.3.1 Bar Utility Functions |dropbar-configuration-utility-functions-bar|
5.3.2 Menu Utility Functions |dropbar-configuration-utility-functions-menu|
5.5 Highlighting |dropbar-configuration-highlighting|
6. Developers |dropbar-developers|
6.1 Architecture |dropbar-developers-architecture|
6.2 Classes |dropbar-developers-classes|
6.2.1 `dropbar_t` |dropbar-developers-classes-dropbar_t|
6.2.2 `dropbar_symbol_t` |dropbar-developers-classes-dropbar_symbol_t|
6.2.4 `dropbar_menu_t` |dropbar-developers-classes-dropbar_menu_t|
6.2.5 `dropbar_menu_entry_t` |dropbar-developers-classes-dropbar_menu_entry_t|
6.2.6 `dropbar_menu_hl_info_t` |dropbar-developers-classes-dropbar_menu_hl_info_t|
6.2.7 `dropbar_source_t` |dropbar-developers-classes-dropbar_source_t|
6.2.8 `dropbar_select_opts_t` |dropbar-developers-classes-dropbar_select_opts_t|
6.3 Making a new source |dropbar-developers-making-a-new-source|
6.3.1 Making a source with drop-down menus |dropbar-developers-making-a-source-with-drop-down-menus|
6.3.2 Default `on_click()` callback |dropbar-developers-default-on_click-callback|
6.3.3 Lazy-loading expensive fields |dropbar-developers-lazy-loading-expensive-fields|
6.3.4 Practical Examples |dropbar-developers-making-a-new-source-practical-examples|
7. Similar Projects |dropbar-similar-projects|
==============================================================================
FEATURES *dropbar-features*
`dropbar.nvim` is a Neovim plugin that provides a polished, IDE-like,
highly-customizable 'winbar' with drop-down menu support and mutiple backends.
- Opening drop-down menus or go to definition with a single mouse click
- Pick mode for quickly selecting a component in the winbar with shortcuts
- Automatically truncating long components
- Multiple backends that support fall-backs
`dropbar.nvim` comes with four builtin sources:
lsp: gets symbols from language servers using nvim’s builtin LSP framework
markdown: a incremental parser that gets markdown headings
path: gets current file path
treesitter: gets symbols from treesitter parsers attached to current buf
To make a new custom source, see |dropbar-developers-making-a-new-source|.
For source fall-backs support, see |dropbar-configuration-options-bar|.
- Zero config & Zero dependency
`dropbar.nvim` does not require nvim-lspconfig , nvim-treesitter or any
third-party UI libraries to work. As long as the language server or the
treesitter parser is installed, it should work just fine.
- Drop-down menu components and winbar symbols that response to mouse/cursor
hovering
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
- Add scrollbar to the menu when the symbol list is too long
==============================================================================
REQUIREMENTS *dropbar-requirements*
- Neovim >= 0.10.0
- Optional
- nvim-web-devicons <https://github.com/nvim-tree/nvim-web-devicons>, if
you want to see icons for different filetypes
- Working language server installation for the lsp source to work
- Working treesitter parser installation for the treesitter source to work
==============================================================================
INSTALLATION *dropbar-installation*
- Using lazy.nvim <https://github.com/folke/lazy.nvim> >lua
require('lazy').setup({
{ 'Bekaboo/dropbar.nvim' }
})
<
- Using packer.nvim <https://github.com/wbthomason/packer.nvim> >lua
require('packer').startup(function(use)
use('Bekaboo/dropbar.nvim')
end)
<
- Using native package manager >bash
mkdir -p ~/.local/share/nvim/site/pack/packages/
git clone https://github.com/Bekaboo/dropbar.nvim \
~/.local/share/nvim/site/pack/packages/start/dropbar.nvim
<
==============================================================================
USAGE *dropbar-usage*
- Basics
- Moves the cursor around and see the winbar reflects your current context
- Mouse support
- Click on a component in the winbar to open a drop-down menu of its
siblings
- Click on an entry in the drop-down menu to go to its location
- Click on the indicator in the drop-down menu to open a sub-menu of its
children
- Pick mode
- Use `require('dropbar.api').pick()` to enter interactive pick mode or
`require('dropbar.api').pick(<idx>)` to directly select a component at
`idx`.
- Inside interactive pick mode, press the corresponding pivot shown before
each component to select it
- Fuzzy finder
- Use `dropbar_menu_t:fuzzy_find_open()` to interactively
filter, select and preview entries using fzf
- `i`: enter fzf mode from the menu
- `<Esc>`: exit fzf mode
- `<Up>/<Down>`: move the cursor in fzf mode
- `<CR>`: call the on_click callback of the symbol under the cursor
- Default keymaps in drop-down menu
- `<LeftMouse>`: call the `on_click` callback of the symbol at the mouse
click
- `<CR>`: find the first clickable symbol in the current drop-down menu
entry and call its `on_click` callback
- `i`: enter fzf mode from the menu
- `q` / `<Esc>`: close current menu
- To disable, remap or add new keymaps in the drop-down menu, see
|dropbar-configuration-options|
------------------------------------------------------------------------------
USAGE WITH `vim.ui.select` *dropbar-usage-with-ui-select*
Dropbar can be used as a drop-in replacement for Neovim's builtin
`vim.ui.select` menu.
To enable this functionality, simply replace `vim.ui.select` with
`dropbar.utils.menu.select`: >lua
vim.ui.select = require('dropbar.utils.menu').select
<
==============================================================================
CONFIGURATION *dropbar-configuration*
------------------------------------------------------------------------------
OPTIONS *dropbar-configuration-options*
..............................................................................
BAR *dropbar-configuration-options-bar*
These options live under `opts.bar` and are used to control the behavior of
the winbar:
- `opts.bar.enable`:
`boolean|fun(buf: integer?, win: integer?, info: table?): boolean`
- Controls whether to enable the plugin for the current buffer and window
- If a function is provided, it will be called with the current bufnr and
winid and should return a boolean
- Default: >lua
function(buf, win, _)
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end
local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end
return vim.bo[buf].ft == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
<
- `opts.bar.attach_events`: `string[]`
- Controls when to evaluate the `enable()` function and attach the plugin
to corresponding buffer or window
- Default: >lua
{
'OptionSet',
'BufWinEnter',
'BufWritePost',
}
<
- `opts.bar.update_debounce`: `number`
- Wait for a short time before updating the winbar, if another update
request is received within this time, the previous request will be
cancelled, this improves the performance when the user is holding
down a key (e.g. `'j'`) to scroll the window
- If you encounter performance issues when scrolling the window, try
setting this option to a number slightly larger than
`1000 / key_repeat_rate`
- Default: `0`
- `opts.bar.update_events.win`: `string[]`
- List of events that should trigger an update on the dropbar attached to
a single window
- Default: >lua
{
'CursorMoved',
'WinEnter',
'WinResized',
}
<
- `opts.bar.update_events.buf`: `string[]`
- List of events that should trigger an update on all dropbars attached to a
buffer
- Default: >lua
{
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'ModeChanged',
}
<
- `opts.bar.update_events.global`: `string[]`
- List of events that should trigger an update of all dropbars in current
nvim session
- Default: >lua
{
'DirChanged',
'VimResized',
}
<
- `opts.bar.hover`:
- Whether to highlight the symbol under the cursor
- This feature requires 'mousemoveevent' to be enabled
- Default: `true`
- `opts.bar.sources`:
`dropbar_source_t[]|fun(buf: integer, win: integer): dropbar_source_t[]`
- List of sources to show in the winbar
- If a function is provided, it will be called with the current bufnr and
winid and should return a list of sources
- Default: >lua
function(buf, _)
local sources = require('dropbar.sources')
local utils = require('dropbar.utils')
if vim.bo[buf].ft == 'markdown' then
return {
sources.path,
sources.markdown,
}
end
if vim.bo[buf].buftype == 'terminal' then
return {
sources.terminal,
}
end
return {
sources.path,
utils.source.fallback({
sources.lsp,
sources.treesitter,
}),
}
end
<
- For more information about sources, see
|dropbar-developers-classes-dropbar_source_t|.
- `opts.bar.padding`: `{ left: number, right: number }`
- Padding to use between the winbar and the window border
- Default: `{ left = 1, right = 1 }`
- `opts.bar.pick.pivots`: `string`
- Pivots to use in pick mode
- Default: `'abcdefghijklmnopqrstuvwxyz'`
- `opts.bar.truncate`: `boolean`
- Whether to truncate the winbar if it doesn’t fit in the window
- Default: `true`
..............................................................................
MENU *dropbar-configuration-options-menu*
These options live under `opts.menu` and are used to control the behavior of
the menu:
- `opts.menu.quick_navigation`: `boolean`
- When on, automatically set the cursor to the closest previous/next
clickable component in the direction of cursor movement on |CursorMoved|
- Default: `true`
- `opts.menu.entry.padding`: `{ left: number, right: number }`
- Padding to use between the menu entry and the menu border
- Default: `{ left = 1, right = 1 }`
- `opts.menu.preview`: `boolean`
- Whether to enable previewing for menu entries
- Default: `true`
- `opts.menu.keymaps`:
`table<string, function|string|table<string, function>|table<string, string>>`
- Buffer-local keymaps in the menu
- Use `<key> = <function|string>` to map a key in normal mode in the menu
buffer, or use `<key> = table<mode, function|string>`
to map a key in specific modes.
- Default: >lua
{
['q'] = '<C-w>q',
['<Esc>'] = '<C-w>q',
['<LeftMouse>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
local clicked_menu = utils.menu.get({ win = mouse.winid })
-- If clicked on a menu, invoke the corresponding click action,
-- else close all menus and set the cursor to the clicked window
if clicked_menu then
clicked_menu:click_at({
mouse.line,
mouse.column - 1
}, nil, 1, 'l')
return
end
utils.menu.exec('close')
utils.bar.exec('update_current_context_hl')
if vim.api.nvim_win_is_valid(mouse.winid) then
vim.api.nvim_set_current_win(mouse.winid)
end
end,
['<CR>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local cursor = vim.api.nvim_win_get_cursor(menu.win)
local component = menu.entries[cursor[1]]:first_clickable(cursor[2])
if component then
menu:click_on(component, nil, 1, 'l')
end
end,
['<MouseMove>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
utils.menu.update_hover_hl(mouse)
if M.opts.menu.preview then
utils.menu.update_preview(mouse)
end
end,
['i'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
menu:fuzzy_find_open()
end,
},
<
- `opts.menu.scrollbar`: `table<string, boolean>`
- Scrollbar configuration for the menu.
- Default: >lua
{
enable = true,
-- if false, only the scrollbar thumb will be shown
background = true
}
<
- `opts.menu.win_configs`: `table<string, dropbar_menu_win_config_opts_t>`
- Window configurations for the menu, see `:h nvim_open_win()`
- Each config key in `opts.menu.win_configs` accepts either a plain value
which will be passes directly to `nvim_open_win()`, or a function that
takes the current menu (see |dropbar-developers-classes-dropbar_menu_t|)
as an argument and returns a value to be passed to `nvim_open_win()`.
- Default: >lua
{
border = 'none',
style = 'minimal',
row = function(menu)
return menu.prev_menu
and menu.prev_menu.clicked_at
and menu.prev_menu.clicked_at[1] - vim.fn.line('w')
or 0
end,
---@param menu dropbar_menu_t
col = function(menu)
if menu.prev_menu then
return menu.prev_menu._win_configs.width
+ (menu.prev_menu.scrollbar and 1 or 0)
end
local mouse = vim.fn.getmousepos()
local bar = utils.bar.get({ win = menu.prev_win })
if not bar then
return mouse.wincol
end
local _, range = bar:get_component_at(math.max(0, mouse.wincol - 1))
return range and range.start or mouse.wincol
end,
relative = 'win',
win = function(menu)
return menu.prev_menu and menu.prev_menu.win
or vim.fn.getmousepos().winid
end,
height = function(menu)
return math.max(
1,
math.min(
#menu.entries,
vim.go.pumheight ~= 0 and vim.go.pumheight
or math.ceil(vim.go.lines / 4)
)
)
end,
width = function(menu)
local min_width = vim.go.pumwidth ~= 0 and vim.go.pumwidth or 8
if vim.tbl_isempty(menu.entries) then
return min_width
end
return math.max(
min_width,
math.max(unpack(vim.tbl_map(function(entry)
return entry:displaywidth()
end, menu.entries)))
)
end,
zindex = function(menu)
if menu.prev_menu then
if menu.prev_menu.scrollbar and menu.prev_menu.scrollbar.thumb then
return vim.api.nvim_win_get_config(menu.prev_menu.scrollbar.thumb).zindex
end
return vim.api.nvim_win_get_config(menu.prev_win).zindex
end
end,
}
<
..............................................................................
FZF *dropbar-configuration-options-fzf*
These options live under `opts.fzf` and are used to control the behavior and
appearance of the fuzzy finder interface.
- `opts.fzf.keymaps`
- The keymaps that will apply in insert mode, in the fzf prompt buffer
- Same config as `opts.menu.keymaps`
- Default: >lua
keymaps = {
['<LeftMouse>'] = function()
---@type dropbar_menu_t
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
if not mouse then
return
end
if mouse.winid ~= menu.win then
local default_func = M.opts.menu.keymaps['<LeftMouse>']
if type(default_func) == 'function' then
default_func()
end
menu:fuzzy_find_close(false)
return
elseif mouse.winrow > vim.api.nvim_buf_line_count(menu.buf) then
return
end
vim.api.nvim_win_set_cursor(menu.win, { mouse.line, mouse.column - 1 })
menu:fuzzy_find_click_on_entry(function(entry)
return entry:get_component_at(mouse.column - 1, true)
end)
end,
['<MouseMove>'] = function()
---@type dropbar_menu_t
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
if not mouse then
return
end
-- If mouse is not in the menu window or on the border, end preview
-- and clear hover highlights
if
mouse.winid ~= menu.win
or mouse.line <= 0
or mouse.column <= 0
or mouse.winrow > #menu.entries
then
-- Find the root menu
while menu and menu.prev_menu do
menu = menu.prev_menu
end
if menu then
menu:finish_preview(true)
menu:update_hover_hl()
end
return
end
if M.opts.menu.preview then
menu:preview_symbol_at({ mouse.line, mouse.column - 1 }, true)
end
menu:update_hover_hl({ mouse.line, mouse.column - 1 })
end,
['<Up>'] = api.fuzzy_find_prev,
['<Down>'] = api.fuzzy_find_next,
['<C-k>'] = api.fuzzy_find_prev,
['<C-j>'] = api.fuzzy_find_next,
['<C-p>'] = api.fuzzy_find_prev,
['<C-n>'] = api.fuzzy_find_next,
['<CR>'] = api.fuzzy_find_click,
['<S-Enter>'] = function()
api.fuzzy_find_click(-1)
end,
}
<
- `opts.fzf.win_configs`
- Options passed to `:h nvim_open_win`. The fuzzy finder will use its
parent window's config by default, but options set here will override
those.
- Same config as opts.menu.win_configs
- Default: >lua
win_configs = {
relative = 'win',
anchor = 'NW',
height = 1,
win = function(menu)
return menu.win
end,
width = function(menu)
local function border_width(border)
if type(border) == 'string' then
if border == 'none' or border == 'shadow' then
return 0
end
return 2 -- left and right border
end
local left, right = 1, 1
if
(#border == 1 and border[1] == '')
or (#border == 4 and border[4] == '')
or (#border == 8 and border[8] == '')
then
left = 0
end
if
(#border == 1 and border[1] == '')
or (#border == 4 and border[4] == '')
or (#border == 8 and border[4] == '')
then
right = 0
end
return left + right
end
local menu_width = menu._win_configs.width
+ border_width(menu._win_configs.border)
local self_width = menu._win_configs.width
local self_border = border_width(
(
M.opts.fzf.win_configs
and M.eval(M.opts.fzf.win_configs.border, menu)
)
or (menu.fzf_win_configs and M.eval(
menu.fzf_win_configs.border,
menu
))
or menu._win_configs.border
)
if self_width + self_border > menu_width then
return self_width - self_border
else
return menu_width - self_border
end
end,
row = function(menu)
local menu_border = menu._win_configs.border
if
type(menu_border) == 'string'
and menu_border ~= 'shadow'
and menu_border ~= 'none'
then
return menu._win_configs.height + 1
elseif menu_border == 'none' then
return menu._win_configs.height
end
local len_menu_border = #menu_border
if
len_menu_border == 1 and menu_border[1] ~= ''
or (len_menu_border == 2 or len_menu_border == 4)
and menu_border[2] ~= ''
or len_menu_border == 8 and menu_border[8] ~= ''
then
return menu._win_configs.height + 1
else
return menu._win_configs.height
end
end,
col = function(menu)
local menu_border = menu._win_configs.border
if
type(menu_border) == 'string'
and menu_border ~= 'shadow'
and menu_border ~= 'none'
then
return -1
end
if
type(menu_border) == 'table'
and menu_border[#menu_border] ~= ''
then
return -1
end
return 0
end,
}
<
- `opts.fzf.prompt`
- Prompt string that will be displayed in the statuscolumn of the fzf
input window.
- Can include highlight groups
- Default: `'%#htmlTag# '`
- `opts.fzf.char_pattern`
- Default: `'[%w%p]'`
- `opts.fzf.retain_inner_spaces`
- Default: `true`
- `opts.fzf.fuzzy_find_on_click`
- When opening an entry with a submenu via the fuzzy finder,
open the submenu in fuzzy finder mode.
- Default: `true`
..............................................................................
ICONS *dropbar-configuration-options-icons*
These options live under `opts.icons` and are used to configure the icons used
by the plugin:
- `opts.icons.enable`: `boolean`
- Whether to enable icons
- Default: `true`
- `opts.icons.kinds.dir_icon`: `fun(path: string): string, string?|string?`
- Directory icon and highlighting getter, set to empty string to disable
- Default: >lua
function(_)
return M.opts.icons.kinds.symbols.Folder, 'DropBarIconKindFolder'
end
<
- `opts.icons.kinds.file_icon`: `fun(path: string): string, string?|string?`
- File icon and highlighting getter, set to empty string to disable
- Default: >lua
function(path)
return M.opts.icons.kinds.symbols.File, 'DropBarIconKindFile'
end
<
- `opts.icons.kinds.symbols`: `table<string, string>`
- Table mapping the different kinds of symbols to their corresponding
icons
- Default: >lua
{
Array = ' ',
Boolean = ' ',
BreakStatement = ' ',
Call = ' ',
CaseStatement = ' ',
Class = ' ',
Color = ' ',
Constant = ' ',
Constructor = ' ',
ContinueStatement = '→ ',
Copilot = ' ',
Declaration = ' ',
Delete = ' ',
DoStatement = ' ',
Enum = ' ',
EnumMember = ' ',
Event = ' ',
Field = ' ',
File = ' ',
Folder = ' ',
ForStatement = ' ',
Function = ' ',
H1Marker = ' ', -- Used by markdown treesitter parser
H2Marker = ' ',
H3Marker = ' ',
H4Marker = ' ',
H5Marker = ' ',
H6Marker = ' ',
Identifier = ' ',
IfStatement = ' ',
Interface = ' ',
Keyword = ' ',
List = ' ',
Log = ' ',
Lsp = ' ',
Macro = ' ',
MarkdownH1 = ' ', -- Used by builtin markdown source
MarkdownH2 = ' ',
MarkdownH3 = ' ',
MarkdownH4 = ' ',
MarkdownH5 = ' ',
MarkdownH6 = ' ',
Method = ' ',
Module = ' ',
Namespace = ' ',
Null = ' ',
Number = ' ',
Object = ' ',
Operator = ' ',
Package = ' ',
Pair = ' ',
Property = ' ',
Reference = ' ',
Regex = ' ',
Repeat = ' ',
Scope = ' ',
Snippet = ' ',
Specifier = ' ',
Statement = ' ',
String = ' ',
Struct = ' ',
SwitchStatement = ' ',
Terminal = ' ',
Text = ' ',
Type = ' ',
TypeParameter = ' ',
Unit = ' ',
Value = ' ',
Variable = ' ',
WhileStatement = ' ',
}
<
- `opts.icons.ui.bar`: `table<string, string>`
- Controls the icons used in the winbar UI
- Default: >lua
{
separator = ' ',
extends = '…',
}
<
- `opts.icons.ui.menu`: `table<string, string>`
- Controls the icons used in the menu UI
- Default: >lua
{
separator = ' ',
indicator = ' ',
}
<
..............................................................................
Symbol *dropbar-configuration-options-symbol*
These options live under `opts.bar` and are used to control the behavior of
the symbols:
- `opts.symbol.on_click()`: `fun(symbol: dropbar_symbol_t, min_width: integer?, n_clicks: integer?, button: string?, modifiers: string?)|false?`
- Default function called when clicking or pressing `<CR>` on the symbol
- Default: >lua
function(symbol)
-- Update current context highlights if the symbol
-- is shown inside a menu
if symbol.entry and symbol.entry.menu then
symbol.entry.menu:update_current_context_hl(symbol.entry.idx)
elseif symbol.bar then
symbol.bar:update_current_context_hl(symbol.bar_idx)
end
-- Determine menu configs
local prev_win = nil ---@type integer?
local entries_source = nil ---@type dropbar_symbol_t[]?
local init_cursor = nil ---@type integer[]?
local win_configs = {}
if symbol.bar then -- If symbol inside a dropbar
prev_win = symbol.bar.win
entries_source = symbol.opts.siblings
init_cursor = symbol.opts.sibling_idx
and { symbol.opts.sibling_idx, 0 }
if symbol.bar.in_pick_mode then
---@param tbl number[]
local function tbl_sum(tbl)
local sum = 0
for _, v in ipairs(tbl) do
sum = sum + v
end
return sum
end
win_configs.relative = 'win'
win_configs.win = vim.api.nvim_get_current_win()
win_configs.row = 0
win_configs.col = symbol.bar.padding.left
+ tbl_sum(vim.tbl_map(
function(component)
return component:displaywidth()
+ symbol.bar.separator:displaywidth()
end,
vim.tbl_filter(function(component)
return component.bar_idx < symbol.bar_idx
end, symbol.bar.components)
))
end
elseif symbol.entry and symbol.entry.menu then -- If inside a menu
prev_win = symbol.entry.menu.win
entries_source = symbol.opts.children
end
-- Toggle existing menu
if symbol.menu then
symbol.menu:toggle({
prev_win = prev_win,
win_configs = win_configs,
})
return
end
-- Create a new menu for the symbol
if not entries_source or vim.tbl_isempty(entries_source) then
return
end
local menu = require('dropbar.menu')
local configs = require('dropbar.configs')
symbol.menu = menu.dropbar_menu_t:new({
prev_win = prev_win,
cursor = init_cursor,
win_configs = win_configs,
---@param sym dropbar_symbol_t
entries = vim.tbl_map(function(sym)
local menu_indicator_icon = configs.opts.icons.ui.menu.indicator
local menu_indicator_on_click = nil
if not sym.children or vim.tbl_isempty(sym.children) then
menu_indicator_icon =
string.rep(' ', vim.fn.strdisplaywidth(menu_indicator_icon))
menu_indicator_on_click = false
end
return menu.dropbar_menu_entry_t:new({
components = {
sym:merge({
name = '',
icon = menu_indicator_icon,
icon_hl = 'dropbarIconUIIndicator',
on_click = menu_indicator_on_click,
}),
sym:merge({
on_click = function()
local current_menu = symbol.menu
while current_menu and current_menu.prev_menu do
current_menu = current_menu.prev_menu
end
if current_menu then
current_menu:close(false)
end
sym:jump()
end,
}),
},
})
end, entries_source),
})
symbol.menu:toggle()
end
<
- `opts.symbol.preview.reorient`: `fun(win: integer, range: {start: {line: integer, character: integer}, end: {line: integer, character: integer}})`
- Function to reorient the source window when previewing symbol given
the source window `win` and the range of the symbol `range`
- Default: >lua
function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview() --[[@as vim.fn.winrestview.dict]]
view.topline = math.min(
view.topline + invisible,
math.max(1, range.start.line - vim.wo.scrolloff + 1)
)
vim.fn.winrestview(view)
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,
<
..............................................................................
SOURCES *dropbar-configuration-options-sources*
These options live under `opts.sources` and are used to control the behavior
of each sources.
PATH *dropbar-configuration-options-sources-path*
- `opts.sources.path.max_depth`: `integer`
- Maximum number of symbols to return
- A smaller number can help to improve performance in deeply nested paths
- Default: `16`
- `opts.sources.path.relative_to`: `string|fun(buf: integer, win: integer): string`
- The path to use as the root of the relative path
- If a function is provided, it will be called with the current buffer
number and window id as arguments and should return a string to be used
as the root of the relative path
- Notice: currently does not support `..` relative paths
- Default: >lua
function(_, win)
-- Workaround for Vim:E5002: Cannot find window number
local ok, cwd = pcall(vim.fn.getcwd, win)
return ok and cwd or vim.fn.getcwd()
end
<
- `opts.sources.path.filter`: `function(name: string): boolean`
- A function that takes a file name and returns whether to include it in
the results shown in the drop-down menu
- Default: >lua
function(_)
return true
end
<
- `opts.sources.path.modified`: `function(sym: dropbar_symbol_t): dropbar_symbol_t`
- A function that takes the last symbol in the result got from the path
source and returns an alternative symbol to show if the current buffer is
modified, for information about dropbar symbols see
|dropbar-developers-classes-dropbar_symbol_t|
- Default: >lua
function(sym)
return sym
end
<
- To set a different icon, name, or highlights when the buffer is modified,
you can change the corresponding fields in the returned symbol: >lua
function(sym)
return sym:merge({
name = sym.name .. ' [+]',
icon = ' ',
name_hl = 'DiffAdded',
icon_hl = 'DiffAdded',
-- ...
})
end
- `opts.sources.path.preview`: `boolean|fun(path: string): boolean?|nil`
- A boolean or a function that takes a file path and returns whether to