From 0f74b1bc2d82d99059e4cf9c35e812b5242a794c Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 14 Oct 2024 20:01:37 +0200 Subject: [PATCH] console.lua: improve hovered line calculation - Don't do anything if clicking on the top counter, the input line or the new line between the items and the input line - Don't scroll upwards when hovering the counter - Don't redraw before clicking to avoid quickly updating the overlay before closing it with touch input, where the item you touch can be different from the one that was highlighted --- player/lua/console.lua | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index 62bc8d3d6c..8576364341 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -781,7 +781,7 @@ local function handle_enter() clear() end -local function highlight_hovered_line() +local function determine_hovered_item() local height = mp.get_property_native('osd-height') if height == 0 then return @@ -795,10 +795,12 @@ local function highlight_hovered_line() local clicked_line = math.floor(y / height * max_lines + .5) local offset = first_match_to_print - 1 + local min_line = 1 max_lines = calculate_max_log_lines() -- Subtract 1 line for the position counter. if first_match_to_print > 1 or offset + max_lines < #matches then + min_line = 2 offset = offset - 1 end @@ -807,18 +809,26 @@ local function highlight_hovered_line() max_lines = #matches end - if selected_match ~= offset + clicked_line - and clicked_line > 0 and clicked_line <= max_lines then - selected_match = offset + clicked_line - update() + if clicked_line >= min_line and clicked_line <= max_lines then + return offset + clicked_line end end local function bind_mouse() - mp.add_forced_key_binding('MOUSE_MOVE', '_console_mouse_move', highlight_hovered_line) + mp.add_forced_key_binding('MOUSE_MOVE', '_console_mouse_move', function() + local item = determine_hovered_item() + if item and item ~= selected_match then + selected_match = item + update() + end + end) + mp.add_forced_key_binding('MBTN_LEFT', '_console_mbtn_left', function() - highlight_hovered_line() - handle_enter() + local item = determine_hovered_item() + if item then + selected_match = item + handle_enter() + end end) end