@@ -100,6 +100,7 @@ local PROPER_MODE = 2 -- considers folds and wrapped lines
100
100
local VIRTUAL_LINE_COUNT_KEY_PREFIX = 0
101
101
local PROPER_LINE_COUNT_KEY_PREFIX = 1
102
102
local TOPLINE_LOOKUP_KEY_PREFIX = 2
103
+ local GET_WINDOW_EDGES = 3
103
104
104
105
-- Maps window ID to a temporary highlight group name. This is reset on each
105
106
-- refresh cycle.
246
247
-- Returns the position of window edges, with borders considered part of the
247
248
-- window.
248
249
local get_window_edges = function (winid )
250
+ local memoize_key = table.concat ({GET_WINDOW_EDGES , winid }, ' :' )
251
+ if memoize and cache [memoize_key ] then return cache [memoize_key ] end
249
252
local top , left = unpack (fn .win_screenpos (winid ))
250
253
local bottom = top + get_window_height (winid ) - 1
251
254
local right = left + fn .winwidth (winid ) - 1
@@ -271,7 +274,9 @@ local get_window_edges = function(winid)
271
274
right = right + 1
272
275
end
273
276
end
274
- return top , bottom , left , right
277
+ local result = {top , bottom , left , right }
278
+ if memoize then cache [memoize_key ] = result end
279
+ return result
275
280
end
276
281
277
282
-- Return the floating windows that overlap the region corresponding to the
@@ -286,7 +291,7 @@ local get_float_overlaps = function(top, bottom, left, right)
286
291
local workspace_win =
287
292
fn .getwinvar (winid , WIN_WORKSPACE_BASE_WINID_VAR , - 1 ) ~= - 1
288
293
if not workspace_win and floating then
289
- local top2 , bottom2 , left2 , right2 = get_window_edges (winid )
294
+ local top2 , bottom2 , left2 , right2 = unpack ( get_window_edges (winid ) )
290
295
if top <= bottom2
291
296
and bottom >= top2
292
297
and left <= right2
@@ -2210,18 +2215,26 @@ if to_bool(fn.exists('&mousemoveevent')) then
2210
2215
mousemove_received = true
2211
2216
pending_mousemove_callback_count = pending_mousemove_callback_count + 1
2212
2217
vim .defer_fn (function ()
2213
- pending_mousemove_callback_count =
2218
+ local resume_memoize = memoize
2219
+ start_memoize ()
2220
+ pcall (function ()
2221
+ pending_mousemove_callback_count =
2214
2222
math.max (0 , pending_mousemove_callback_count - 1 )
2215
- if pending_mousemove_callback_count > 0 then
2216
- -- If there are mousemove callbacks that will occur subsequently,
2217
- -- don't execute this one.
2218
- return
2219
- end
2220
- for _ , winid in ipairs (get_scrollview_windows ()) do
2221
- local props = api .nvim_win_get_var (winid , PROPS_VAR )
2222
- if not vim .tbl_isempty (props ) and props .highlight_fn ~= nil then
2223
- props .highlight_fn (is_mouse_over_scrollview_win (winid ))
2223
+ if pending_mousemove_callback_count > 0 then
2224
+ -- If there are mousemove callbacks that will occur subsequently,
2225
+ -- don't execute this one.
2226
+ return
2227
+ end
2228
+ for _ , winid in ipairs (get_scrollview_windows ()) do
2229
+ local props = api .nvim_win_get_var (winid , PROPS_VAR )
2230
+ if not vim .tbl_isempty (props ) and props .highlight_fn ~= nil then
2231
+ props .highlight_fn (is_mouse_over_scrollview_win (winid ))
2232
+ end
2224
2233
end
2234
+ end )
2235
+ if not resume_memoize then
2236
+ stop_memoize ()
2237
+ reset_memoize ()
2225
2238
end
2226
2239
end , 0 )
2227
2240
end
0 commit comments