Skip to content

Commit cf766a4

Browse files
committed
"refresh_bars" -> "refresh_impl", "remove_bars" -> "remove"
The functionality applies to signs in addition to scrollbars.
1 parent 8144aff commit cf766a4

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

lua/scrollview.lua

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ local to_bool = utils.to_bool
2828
-- setting should use a window workspace to prevent unwanted side effects. More
2929
-- details are in the documentation for with_win_workspace.
3030
-- XXX: Some of the functionality is applicable to bars and signs, but is
31-
-- named as if it were only applicable to bars (since it was implemented prior
32-
-- to sign support).
31+
-- described in comments as if it were only applicable to bars (since it was
32+
-- written prior to sign support).
3333

3434
-- *************************************************
3535
-- * Forward Declarations
@@ -38,7 +38,7 @@ local to_bool = utils.to_bool
3838
-- Declared here since it's used by the earlier legend() function.
3939
local get_sign_groups
4040

41-
-- Declared here since it's used by the earlier refresh_bars() function.
41+
-- Declared here since it's used by the earlier refresh_impl() function.
4242
local is_sign_group_active
4343

4444
-- *************************************************
@@ -2398,7 +2398,7 @@ end
23982398

23992399
-- With no argument, remove all bars. Otherwise, remove the specified list of
24002400
-- bars. Global state is initialized and restored.
2401-
local remove_bars = function(target_wins)
2401+
local remove = function(target_wins)
24022402
if target_wins == nil then target_wins = get_scrollview_windows() end
24032403
if bar_bufnr == -1 and sign_bufnr == -1 then return end
24042404
local state = init()
@@ -2416,12 +2416,12 @@ end
24162416
-- the command line window (from the WinEnter event).
24172417
local remove_if_command_line_window = function()
24182418
if in_command_line_window() then
2419-
pcall(remove_bars)
2419+
pcall(remove)
24202420
end
24212421
end
24222422

24232423
-- Refreshes scrollbars. Global state is initialized and restored.
2424-
local refresh_bars = function()
2424+
local refresh_impl = function()
24252425
vim.g.scrollview_refreshing = true
24262426
local state = init()
24272427
local resume_memoize = memoize
@@ -2545,7 +2545,7 @@ end
25452545
-- which can result in bars being placed where they shouldn't be.
25462546
-- WARN: For debugging, it's helpful to use synchronous refreshing, so that
25472547
-- e.g., echom works as expected.
2548-
local refresh_bars_async = function()
2548+
local refresh_impl_async = function()
25492549
pending_async_refresh_count = pending_async_refresh_count + 1
25502550
-- Use defer_fn twice so that refreshing happens after other processing. #59.
25512551
vim.defer_fn(function()
@@ -2559,7 +2559,7 @@ local refresh_bars_async = function()
25592559
-- ScrollView may have already been disabled by time this callback
25602560
-- executes asynchronously.
25612561
if vim.g.scrollview_enabled then
2562-
refresh_bars()
2562+
refresh_impl()
25632563
end
25642564
end, 0)
25652565
end, 0)
@@ -2639,34 +2639,34 @@ local enable = function()
26392639
" <ctrl-w>o can be used to first close the floating windows, or
26402640
" alternatively :tabclose can be used (or one of the alternatives handled
26412641
" with the autocmd, like ZQ).
2642-
autocmd QuitPre * lua require('scrollview').remove_bars()
2642+
autocmd QuitPre * lua require('scrollview').remove()
26432643
26442644
" === Scrollbar Refreshing ===
26452645
26462646
" The following handles bar refreshing when changing the current window.
2647-
autocmd WinEnter,TermEnter * lua require('scrollview').refresh_bars_async()
2647+
autocmd WinEnter,TermEnter * lua require('scrollview').refresh_impl_async()
26482648
26492649
" The following restores bars after leaving the command-line window.
26502650
" Refreshing must be asynchronous, since the command line window is still
26512651
" in an intermediate state when the CmdwinLeave event is triggered.
2652-
autocmd CmdwinLeave * lua require('scrollview').refresh_bars_async()
2652+
autocmd CmdwinLeave * lua require('scrollview').refresh_impl_async()
26532653
26542654
" The following handles scrolling events, which could arise from various
26552655
" actions, including resizing windows, movements (e.g., j, k), or
26562656
" scrolling (e.g., <ctrl-e>, zz).
2657-
autocmd WinScrolled * lua require('scrollview').refresh_bars_async()
2657+
autocmd WinScrolled * lua require('scrollview').refresh_impl_async()
26582658
26592659
" The following handles window resizes that don't trigger WinScrolled
26602660
" (e.g., leaving the command line window). This was added in Neovim 0.9,
26612661
" so its presence needs to be tested.
26622662
if exists('##WinResized')
2663-
autocmd WinResized * lua require('scrollview').refresh_bars_async()
2663+
autocmd WinResized * lua require('scrollview').refresh_impl_async()
26642664
endif
26652665
26662666
" The following handles the case where text is pasted. Handling for
26672667
" TextChangedI is not necessary since WinScrolled will be triggered if
26682668
" there is corresponding scrolling when pasting.
2669-
autocmd TextChanged * lua require('scrollview').refresh_bars_async()
2669+
autocmd TextChanged * lua require('scrollview').refresh_impl_async()
26702670
26712671
" Refresh in insert mode if the number of lines changes. This handles the
26722672
" case where lines are deleted in insert mode. This is also used as a
@@ -2683,7 +2683,7 @@ local enable = function()
26832683
\ let g:scrollview_ins_mode_buf_lines = nvim_buf_line_count(0)
26842684
autocmd TextChangedI,TextChangedP *
26852685
\ if g:scrollview_ins_mode_buf_lines !=# nvim_buf_line_count(0)
2686-
\ | execute "lua require('scrollview').refresh_bars_async()"
2686+
\ | execute "lua require('scrollview').refresh_impl_async()"
26872687
\ | endif
26882688
\ | let g:scrollview_ins_mode_buf_lines = nvim_buf_line_count(0)
26892689
@@ -2695,7 +2695,7 @@ local enable = function()
26952695
autocmd InsertEnter,InsertLeave *
26962696
\ if g:scrollview_hide_bar_for_insert
26972697
\ || !empty(g:scrollview_signs_hidden_for_insert)
2698-
\ | execute "lua require('scrollview').refresh_bars_async()"
2698+
\ | execute "lua require('scrollview').refresh_impl_async()"
26992699
\ | endif
27002700
27012701
" Refresh bars if the cursor intersects a scrollview window (and the
@@ -2705,48 +2705,48 @@ local enable = function()
27052705
\ if g:scrollview_hide_on_cursor_intersect
27062706
\ && has('nvim-0.7')
27072707
\ && luaeval('require("scrollview").cursor_intersects_scrollview()')
2708-
\ | execute "lua require('scrollview').refresh_bars_async()"
2708+
\ | execute "lua require('scrollview').refresh_impl_async()"
27092709
\ | endif
27102710
27112711
" Refresh scrollview when text is changed in insert mode (and
27122712
" scrollview_hide_on_text_intersect is set). This way, scrollbars and
27132713
" signs will appear/hide accordingly when modifying text.
27142714
autocmd TextChangedI *
27152715
\ if g:scrollview_hide_on_text_intersect
2716-
\ | execute "lua require('scrollview').refresh_bars_async()"
2716+
\ | execute "lua require('scrollview').refresh_impl_async()"
27172717
\ | endif
27182718
27192719
" The following handles when :e is used to load a file. The asynchronous
27202720
" version handles a case where :e is used to reload an existing file, that
27212721
" is already scrolled. This avoids a scenario where the scrollbar is
27222722
" refreshed while the window is an intermediate state, resulting in the
27232723
" scrollbar moving to the top of the window.
2724-
autocmd BufWinEnter * lua require('scrollview').refresh_bars_async()
2724+
autocmd BufWinEnter * lua require('scrollview').refresh_impl_async()
27252725
27262726
" The following is used so that bars are shown when cycling through tabs.
2727-
autocmd TabEnter * lua require('scrollview').refresh_bars_async()
2727+
autocmd TabEnter * lua require('scrollview').refresh_impl_async()
27282728
2729-
autocmd VimResized * lua require('scrollview').refresh_bars_async()
2729+
autocmd VimResized * lua require('scrollview').refresh_impl_async()
27302730
27312731
" Scrollbar positions can become stale after adding or removing winbars.
2732-
autocmd OptionSet winbar lua require('scrollview').refresh_bars_async()
2732+
autocmd OptionSet winbar lua require('scrollview').refresh_impl_async()
27332733
27342734
" Scrollbar positions can become stale when the number column or sign
27352735
" column is added or removed (when scrollview_base=buffer).
27362736
autocmd OptionSet number,relativenumber,signcolumn
2737-
\ lua require('scrollview').refresh_bars_async()
2737+
\ lua require('scrollview').refresh_impl_async()
27382738
27392739
" The following handles scrollbar/sign generation for new floating
27402740
" windows.
2741-
autocmd WinNew * lua require('scrollview').refresh_bars_async()
2741+
autocmd WinNew * lua require('scrollview').refresh_impl_async()
27422742
augroup END
27432743
]])
27442744
-- The initial refresh is asynchronous, since :ScrollViewEnable can be used
27452745
-- in a context where Neovim is in an intermediate state. For example, for
27462746
-- ':bdelete | ScrollViewEnable', with synchronous processing, the 'topline'
27472747
-- and 'botline' in getwininfo's results correspond to the existing buffer
27482748
-- that :bdelete was called on.
2749-
refresh_bars_async()
2749+
refresh_impl_async()
27502750
end
27512751

27522752
local disable = function()
@@ -2770,7 +2770,7 @@ local disable = function()
27702770
-- Remove scrollbars from all tabs.
27712771
for _, tabnr in ipairs(api.nvim_list_tabpages()) do
27722772
api.nvim_set_current_tabpage(tabnr)
2773-
pcall(remove_bars)
2773+
pcall(remove)
27742774
end
27752775
end)
27762776
api.nvim_set_current_win(winid)
@@ -2803,7 +2803,7 @@ local refresh = function()
28032803
-- be updated (e.g., :ScrollViewRefresh --sync) to accommodate (as there is
28042804
-- currently only a single refresh command and a single refresh <plug>
28052805
-- mapping, both utilizing whatever is implemented here).
2806-
refresh_bars_async()
2806+
refresh_impl_async()
28072807
end
28082808
end
28092809

@@ -3117,7 +3117,7 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
31173117
-- Refresh scrollbars to handle the scenario where
31183118
-- scrollview_hide_on_float_intersect is enabled and dragging
31193119
-- resulted in a scrollbar overlapping a floating window.
3120-
refresh_bars()
3120+
refresh_impl()
31213121
-- We only restore the cursor after dragging is finished. The
31223122
-- cursor position can't be changed while dragging (but it stays in
31233123
-- the same place when there aren't wrapped lines).
@@ -3137,7 +3137,7 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
31373137
local target = subsequent(props.lines, current, 1, true)
31383138
vim.cmd('normal!' .. target .. 'G')
31393139
end)
3140-
refresh_bars()
3140+
refresh_impl()
31413141
return
31423142
end
31433143
if not is_primary then
@@ -3245,7 +3245,7 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
32453245
end
32463246
vim.cmd('silent! aunmenu ' .. menu_name)
32473247
api.nvim_win_close(popup_win, true)
3248-
refresh_bars()
3248+
refresh_impl()
32493249
return
32503250
end
32513251
-- There was a primary click on a scrollbar.
@@ -3254,7 +3254,7 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
32543254
-- not, ignore all mouse events until a mouseup. This approach was
32553255
-- deemed preferable to refreshing scrollbars initially, as that could
32563256
-- result in unintended clicking/dragging where there is no scrollbar.
3257-
refresh_bars()
3257+
refresh_impl()
32583258
vim.cmd('redraw')
32593259
props = get_scrollview_bar_props(mouse_winid)
32603260
if vim.tbl_isempty(props)
@@ -3306,14 +3306,14 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
33063306
set_topline(winid, topline)
33073307
if api.nvim_win_get_option(winid, 'scrollbind')
33083308
or api.nvim_win_get_option(winid, 'cursorbind') then
3309-
refresh_bars()
3309+
refresh_impl()
33103310
props = get_scrollview_bar_props(winid)
33113311
end
33123312
props = move_scrollbar(props, row) -- luacheck: ignore
33133313
-- Refresh since sign backgrounds might be stale, for signs that
33143314
-- switched intersection state with scrollbar. This is fast, from
33153315
-- caching.
3316-
refresh_bars()
3316+
refresh_impl()
33173317
props = get_scrollview_bar_props(winid)
33183318
-- Apply appropriate highlighting where relevant.
33193319
if mousemove_received
@@ -3521,7 +3521,7 @@ local deregister_sign_group = function(group, refresh_)
35213521
end
35223522
sign_group_callbacks[group] = nil
35233523
if refresh_ and vim.g.scrollview_enabled then
3524-
refresh_bars()
3524+
refresh_impl()
35253525
end
35263526
end
35273527

@@ -3608,7 +3608,7 @@ local deregister_sign_spec = function(id, refresh_)
36083608
end
36093609
sign_specs[id] = nil
36103610
if refresh_ and vim.g.scrollview_enabled then
3611-
refresh_bars()
3611+
refresh_impl()
36123612
end
36133613
end
36143614

@@ -3629,7 +3629,7 @@ local set_sign_group_state = function(group, state)
36293629
sign_group_state[group] = state
36303630
end
36313631
if prior_state ~= sign_group_state[group] then
3632-
refresh_bars_async()
3632+
refresh_impl_async()
36333633
end
36343634
end
36353635

@@ -3682,7 +3682,7 @@ local win_seqs = {
36823682
t('<c-w>r'), t('<c-w><c-r>'), t('<c-w>R')
36833683
}
36843684
for _, seq in ipairs(win_seqs) do
3685-
register_key_sequence_callback(seq, 'nvs', refresh_bars_async)
3685+
register_key_sequence_callback(seq, 'nvs', refresh_impl_async)
36863686
end
36873687

36883688
-- Refresh after :wincmd.
@@ -3703,7 +3703,7 @@ if api.nvim_create_autocmd ~= nil then
37033703
end
37043704
local cmdline = fn.getcmdline()
37053705
if string.match(cmdline, '^%d*winc') ~= nil then
3706-
refresh_bars_async()
3706+
refresh_impl_async()
37073707
end
37083708
end
37093709
})
@@ -3716,7 +3716,7 @@ end
37163716
-- corresponds to the current window.
37173717
local wheel_seqs = {t('<scrollwheelup>'), t('<scrollwheeldown>')}
37183718
for _, seq in ipairs(wheel_seqs) do
3719-
register_key_sequence_callback(seq, 'nvsit', refresh_bars_async)
3719+
register_key_sequence_callback(seq, 'nvsit', refresh_impl_async)
37203720
end
37213721

37223722
-- === Fold command synchronization ===
@@ -3734,7 +3734,7 @@ local zf_operator = function(type_)
37343734
else -- luacheck: ignore 542 (an empty if branch)
37353735
-- Unsupported
37363736
end
3737-
refresh_bars_async()
3737+
refresh_impl_async()
37383738
end
37393739

37403740
register_key_sequence_callback('zf', 'n', function()
@@ -3750,14 +3750,14 @@ register_key_sequence_callback('zf', 'n', function()
37503750
end
37513751
end, 0)
37523752
end)
3753-
register_key_sequence_callback('zf', 'v', refresh_bars_async)
3753+
register_key_sequence_callback('zf', 'v', refresh_impl_async)
37543754

37553755
local fold_seqs = {
37563756
'zF', 'zd', 'zD', 'zE', 'zo', 'zO', 'zc', 'zC', 'za', 'zA', 'zv',
37573757
'zx', 'zX', 'zm', 'zM', 'zr', 'zR', 'zn', 'zN', 'zi'
37583758
}
37593759
for _, seq in ipairs(fold_seqs) do
3760-
register_key_sequence_callback(seq, 'nv', refresh_bars_async)
3760+
register_key_sequence_callback(seq, 'nv', refresh_impl_async)
37613761
end
37623762

37633763
-- === InsertLeave synchronization ===
@@ -3767,7 +3767,7 @@ end
37673767
register_key_sequence_callback(t('<c-c>'), 'i', function()
37683768
if vim.g.scrollview_hide_bar_for_insert
37693769
or not vim.tbl_isempty(vim.g.scrollview_signs_hidden_for_insert) then
3770-
refresh_bars_async()
3770+
refresh_impl_async()
37713771
end
37723772
end)
37733773

@@ -3778,8 +3778,8 @@ end)
37783778
return {
37793779
-- Functions called internally (by autocmds and operatorfunc).
37803780
cursor_intersects_scrollview = cursor_intersects_scrollview,
3781-
refresh_bars_async = refresh_bars_async,
3782-
remove_bars = remove_bars,
3781+
refresh_impl_async = refresh_impl_async,
3782+
remove = remove,
37833783
remove_if_command_line_window = remove_if_command_line_window,
37843784
zf_operator = zf_operator,
37853785

0 commit comments

Comments
 (0)