@@ -152,6 +152,12 @@ local MOUSE_LOOKUP = (function()
152152 return result
153153end )()
154154
155+ -- Fake window IDs are used by read_input_stream for representing the command
156+ -- line and tabline. These are negative so they can be distinguished from
157+ -- valid IDs for actual windows.
158+ local COMMAND_LINE_WINID = - 1
159+ local TABLINE_WINID = - 2
160+
155161-- *************************************************
156162-- * Memoization
157163-- *************************************************
@@ -2156,10 +2162,11 @@ end
21562162-- 5) mouse_row (1-indexed)
21572163-- 6) mouse_col (1-indexed)
21582164-- The mouse values are 0 when there was no mouse event or getmousepos is not
2159- -- available. The mouse_winid is set to -1 when a mouse event was on the
2160- -- command line. The mouse_winid is set to -2 when a mouse event was on the
2161- -- tabline. For floating windows with borders, the left border is considered
2162- -- column 0 and the top border is considered row 0.
2165+ -- available. The mouse_winid is set to COMMAND_LINE_WINID (negative) when a
2166+ -- mouse event was on the command line. The mouse_winid is set to TABLINE_WINID
2167+ -- (negative) when a mouse event was on the tabline. For floating windows with
2168+ -- borders, the left border is considered column 0 and the top border is
2169+ -- considered row 0.
21632170local read_input_stream = function ()
21642171 local chars = {}
21652172 local chars_props = {}
@@ -2196,7 +2203,7 @@ local read_input_stream = function()
21962203 mouse_col = mousepos .wincol
21972204 -- Handle a mouse event on the command line.
21982205 if mousepos .screenrow > vim .go .lines - vim .go .cmdheight then
2199- mouse_winid = - 1
2206+ mouse_winid = COMMAND_LINE_WINID
22002207 mouse_row = mousepos .screenrow - vim .go .lines + vim .go .cmdheight
22012208 mouse_col = mousepos .screencol
22022209 end
@@ -2207,7 +2214,7 @@ local read_input_stream = function()
22072214 if vim .deep_equal (fn .win_screenpos (1 ), {2 , 1 }) -- Checks for presence of a tabline.
22082215 and mousepos .screenrow == 1
22092216 and is_ordinary_window (mousepos .winid ) then
2210- mouse_winid = - 2
2217+ mouse_winid = TABLINE_WINID
22112218 mouse_row = mousepos .screenrow
22122219 mouse_col = mousepos .screencol
22132220 end
@@ -2217,16 +2224,18 @@ local read_input_stream = function()
22172224 mouse_row = mouse_row - 1
22182225 end
22192226 -- Adjust for floating window borders.
2220- local config = api .nvim_win_get_config (mouse_winid )
2221- local is_float = tbl_get (config , ' relative' , ' ' ) ~= ' '
2222- if is_float then
2223- local border = config .border
2224- if border ~= nil and islist (border ) and # border == 8 then
2225- if border [BORDER_TOP ] ~= ' ' then
2226- mouse_row = mouse_row - 1
2227- end
2228- if border [BORDER_LEFT ] ~= ' ' then
2229- mouse_col = mouse_col - 1
2227+ if mouse_winid > 0 then
2228+ local config = api .nvim_win_get_config (mouse_winid )
2229+ local is_float = tbl_get (config , ' relative' , ' ' ) ~= ' '
2230+ if is_float then
2231+ local border = config .border
2232+ if border ~= nil and islist (border ) and # border == 8 then
2233+ if border [BORDER_TOP ] ~= ' ' then
2234+ mouse_row = mouse_row - 1
2235+ end
2236+ if border [BORDER_LEFT ] ~= ' ' then
2237+ mouse_col = mouse_col - 1
2238+ end
22302239 end
22312240 end
22322241 end
@@ -3218,7 +3227,14 @@ local handle_mouse = function(button, is_primary, init_props, init_mousepos)
32183227 previous_row = props .row
32193228 end
32203229 local winheight = get_window_height (winid )
3221- local mouse_winrow = fn .getwininfo (mouse_winid )[1 ].winrow
3230+ local mouse_winrow
3231+ if mouse_winid == COMMAND_LINE_WINID then
3232+ mouse_winrow = vim .go .lines - vim .go .cmdheight + 1
3233+ elseif mouse_winid == TABLINE_WINID then
3234+ mouse_winrow = 1
3235+ else
3236+ mouse_winrow = fn .getwininfo (mouse_winid )[1 ].winrow
3237+ end
32223238 local winrow = fn .getwininfo (winid )[1 ].winrow
32233239 local window_offset = mouse_winrow - winrow
32243240 local row = mouse_row + window_offset + scrollbar_offset
0 commit comments