@@ -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