Skip to content

Commit 2a4bf6f

Browse files
committed
Add a new option, g:scrollview_signs_max
1 parent 41919ea commit 2a4bf6f

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

autoload/scrollview.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ endif
102102
let g:scrollview_signs_info_excluded =
103103
\ get(g:, 'scrollview_signs_info_excluded',
104104
\ ['changelist', 'cursor', 'latestchange'])
105+
" The maximum number of signs shown in a window. Set to -1 to have no limit.
106+
" Set to 0 to disable signs.
107+
let g:scrollview_signs_max = get(g:, 'scrollview_signs_max', -1)
105108
" The maximum number of signs shown per row. Set to -1 to have no limit.
106109
" Set to 0 to disable signs.
107110
let g:scrollview_signs_max_per_row =

doc/scrollview.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ scrollview_signs_info_excluded *scrollview_signs_info_excluded*
382382
set to `'info'` and there is no overflow. Defaults to
383383
`['changelist', 'cursor', 'latestchange']`.
384384

385+
scrollview_signs_max *scrollview_signs_max*
386+
|Number| specifying the maximum number of signs in a
387+
window. The highest priority signs are shown when the
388+
limit is reached. Applied after |scrollview_signs_max_per_row|
389+
and |scrollview_signs_max_per_row_by_group|. Set to `-1`
390+
to have no limit. Defaults to `-1`.
391+
385392
scrollview_signs_max_per_row *scrollview_signs_max_per_row*
386393
|Number| specifying the maximum number of signs per row.
387394
Set to `-1` to have no limit. Defaults to `-1`.

doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ scrollview_search_priority scrollview.txt /*scrollview_search_priority*
125125
scrollview_search_symbol scrollview.txt /*scrollview_search_symbol*
126126
scrollview_signs_hidden_for_insert scrollview.txt /*scrollview_signs_hidden_for_insert*
127127
scrollview_signs_info_excluded scrollview.txt /*scrollview_signs_info_excluded*
128+
scrollview_signs_max scrollview.txt /*scrollview_signs_max*
128129
scrollview_signs_max_per_row scrollview.txt /*scrollview_signs_max_per_row*
129130
scrollview_signs_max_per_row_by_group scrollview.txt /*scrollview_signs_max_per_row_by_group*
130131
scrollview_signs_on_startup scrollview.txt /*scrollview_signs_on_startup*

lua/scrollview.lua

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,9 @@ local show_signs = function(winid, sign_winids, bar_winid)
17581758
local line_count = api.nvim_buf_line_count(bufnr)
17591759
local topline_lookup = nil -- only set when needed
17601760
local base_col = calculate_scrollbar_column(winid)
1761-
-- lookup maps rows to a mapping of names to sign specifications (with lines).
1761+
-- lookup maps rows to a mapping of names to sign properties (with lines).
1762+
-- {[12] = {scrollview_signs_24_marks = {
1763+
-- symbol = {"c"}, lines = {79}, ...}, ...}, ...}
17621764
local lookup = {}
17631765
for _, sign_spec in pairs(sign_specs) do
17641766
local name = sign_spec.name
@@ -1846,6 +1848,10 @@ local show_signs = function(winid, sign_winids, bar_winid)
18461848
end
18471849
end
18481850
end
1851+
-- row_props maps rows to their filtered list of sign properties.
1852+
-- {[12] = {{name = "scrollview_signs_24_marks", symbol = "c",
1853+
-- lines = {79}, priority = 50, sign_spec_id = 24, ...}, ...}, ...}
1854+
local row_props = {}
18491855
for row, props_lookup in pairs(lookup) do
18501856
local props_list = {}
18511857
for _, properties in pairs(props_lookup) do
@@ -1890,6 +1896,54 @@ local show_signs = function(winid, sign_winids, bar_winid)
18901896
if max_signs_per_row >= 0 then
18911897
props_list = vim.list_slice(props_list, 1, max_signs_per_row)
18921898
end
1899+
row_props[row] = props_list
1900+
end
1901+
-- Apply window-level max.
1902+
local signs_max = vim.g.scrollview_signs_max
1903+
if signs_max >= 0 then
1904+
local bar_top, bar_bot
1905+
if bar_props ~= nil then
1906+
bar_top = bar_props.row
1907+
bar_bot = bar_props.row + bar_props.height - 1
1908+
else
1909+
local bar_position = calculate_position(winid)
1910+
bar_top = bar_position.row
1911+
bar_bot = bar_position.row + bar_position.height - 1
1912+
end
1913+
-- all_signs has a flattened version of row_props, for considering all rows
1914+
-- when sorting.
1915+
-- {{row = 12, props = {symbol = "c", priority = 50, ...}}, ...}
1916+
local all_signs = {}
1917+
for row, props_list in pairs(row_props) do
1918+
for _, props in ipairs(props_list) do
1919+
table.insert(all_signs, {row = row, props = props})
1920+
end
1921+
end
1922+
table.sort(all_signs, function(a, b)
1923+
if a.props.priority ~= b.props.priority then
1924+
return a.props.priority > b.props.priority
1925+
end
1926+
local a_dist = math.max(0, bar_top - a.row, a.row - bar_bot)
1927+
local b_dist = math.max(0, bar_top - b.row, b.row - bar_bot)
1928+
if a_dist ~= b_dist then
1929+
return a_dist < b_dist
1930+
end
1931+
if a.props.sign_spec_id ~= b.props.sign_spec_id then
1932+
return a.props.sign_spec_id < b.props.sign_spec_id
1933+
end
1934+
return a.props.lines[1] < b.props.lines[1]
1935+
end)
1936+
-- Rebuild row_props from the top signs_max entries.
1937+
row_props = {}
1938+
for i = 1, math.min(signs_max, #all_signs) do
1939+
local item = all_signs[i]
1940+
if row_props[item.row] == nil then
1941+
row_props[item.row] = {}
1942+
end
1943+
table.insert(row_props[item.row], item.props)
1944+
end
1945+
end
1946+
for row, props_list in pairs(row_props) do
18931947
-- A set of columns, to prevent creating multiple signs in the same
18941948
-- location.
18951949
local total_width = 0 -- running sum of sign widths

0 commit comments

Comments
 (0)