@@ -28,8 +28,8 @@ function Row:increment(n)
2828end
2929
3030--- @class render.md.MarkInfo
31- --- @field row integer[]
32- --- @field col integer[]
31+ --- @field row { [1] : integer , [2] ?: integer }
32+ --- @field col { [1] : integer , [2] ?: integer }
3333--- @field hl_eol ? boolean
3434--- @field hl_group ? string
3535--- @field conceal ? string
@@ -65,61 +65,37 @@ function MarkInfo.new(row, col, details)
6565 return self
6666end
6767
68- --- @param a render.md.MarkInfo
69- --- @param b render.md.MarkInfo
70- --- @return boolean
71- function MarkInfo .__lt (a , b )
72- --- @param getter fun ( mark : render.md.MarkInfo ): number[]
73- --- @return boolean ?
74- local function compare_ints (getter )
75- local as , bs = getter (a ), getter (b )
76- for i = 1 , math.max (# as , # bs ) do
77- local av , bv = as [math.min (i , # as )], bs [math.min (i , # bs )]
78- if av ~= bv then
79- return av < bv
80- end
81- end
82- return nil
83- end
68+ --- @return integer[]
69+ function MarkInfo :priorities ()
70+ local result = {}
8471
85- local row_comp = compare_ints (function (mark )
86- if mark .virt_lines == nil then
87- return mark .row
88- end
89- local offset = mark .virt_lines_above and - 0.5 or 0.5
90- return vim .iter (mark .row )
91- :map (function (row )
92- return row + offset
93- end )
94- :totable ()
95- end )
96- if row_comp ~= nil then
97- return row_comp
72+ local row_offset = 0
73+ if self .virt_lines ~= nil then
74+ row_offset = self .virt_lines_above and - 0.5 or 0.5
9875 end
76+ vim .list_extend (result , { self .row [1 ] + row_offset , (self .row [2 ] or self .row [1 ]) + row_offset })
9977
100- local col_comp = compare_ints (function (mark )
101- if mark .virt_text_win_col == nil then
102- return mark .col
103- else
104- return { mark .virt_text_win_col }
105- end
106- end )
107- if col_comp ~= nil then
108- return col_comp
109- end
78+ local col = self .virt_text_win_col or 0
79+ vim .list_extend (result , { math.max (self .col [1 ], col ), math.max ((self .col [2 ] or self .col [1 ]), col ) })
11080
111- -- Higher priority for inline text
112- local a_inline , b_inline = a .virt_text_pos == ' inline' , b .virt_text_pos == ' inline'
113- if a_inline ~= b_inline then
114- return a_inline
115- end
81+ vim .list_extend (result , {
82+ self .virt_text_pos == ' inline' and 0 or 1 , -- Inline text comes first
83+ self .sign_text == nil and 0 or 1 , -- Signs come later
84+ })
11685
117- -- Lower priority for signs
118- local a_sign , b_sign = a .sign_text ~= nil , b .sign_text ~= nil
119- if a_sign ~= b_sign then
120- return not a_sign
121- end
86+ return result
87+ end
12288
89+ --- @param a render.md.MarkInfo
90+ --- @param b render.md.MarkInfo
91+ --- @return boolean
92+ function MarkInfo .__lt (a , b )
93+ local as , bs = a :priorities (), b :priorities ()
94+ for i = 1 , math.max (# as , # bs ) do
95+ if as [i ] ~= bs [i ] then
96+ return as [i ] < bs [i ]
97+ end
98+ end
12399 return false
124100end
125101
0 commit comments