Calculate the hovered item from the bottom of the screen where the console is anchored. This is simpler and accurate because it accounts for the fact that the empty line between the log and the input line isn't as tall as a full line, for the exact height of an always visible OSC bottombar, and for the empty top pixels present because the height isn't an integer multiple of the font size.
Showing the changes to player/lua/console.lua (1 of 1 file). Show all
Unified · Split
| @@ -822,29 +822,24 @@ end · 821 unmodified lines | |||
| 822 | local function determine_hovered_item() | 822 | local function determine_hovered_item() |
| 823 | local height = select(2, get_scaled_osd_dimensions()) | 823 | local height = select(2, get_scaled_osd_dimensions()) |
| 824 | local y = mp.get_property_native('mouse-pos').y / scale_factor() | 824 | local y = mp.get_property_native('mouse-pos').y / scale_factor() |
| 825 | - global_margins.t * height | 825 | local log_bottom_pos = height * (1 - global_margins.b) |
| 826 | -- Calculate how many lines could be printed without decreasing them for | 826 | - bottom_left_margin - 1.5 * opts.font_size |
| 827 | -- the input line and OSC. | ||
| 828 | local max_lines = height / opts.font_size | ||
| 829 | local clicked_line = math.ceil(y / height * max_lines) | ||
| 830 | 827 | ||
| 831 | local offset = first_match_to_print - 1 | 828 | if y > log_bottom_pos then |
| 832 | local min_line = 1 | 829 | return |
| 833 | max_lines = calculate_max_log_lines() | 830 | end |
| 834 | 831 | ||
| 832 | local max_lines = calculate_max_log_lines() | ||
| 835 | -- Subtract 1 line for the position counter. | 833 | -- Subtract 1 line for the position counter. |
| 836 | if first_match_to_print > 1 or offset + max_lines < #matches then | 834 | if #matches > max_lines then |
| 837 | min_line = 2 | 835 | max_lines = max_lines - 1 |
| 838 | offset = offset - 1 | ||
| 839 | end | 836 | end |
| 837 | local last = math.min(first_match_to_print - 1 + max_lines, #matches) | ||
| 840 | 838 | ||
| 841 | if #matches < max_lines then | 839 | local hovered_item = last - math.floor((log_bottom_pos - y) / opts.font_size) |
| 842 | clicked_line = clicked_line - (max_lines - #matches) | ||
| 843 | max_lines = #matches | ||
| 844 | end | ||
| 845 | 840 | ||
| 846 | if clicked_line >= min_line and clicked_line <= max_lines then | 841 | if hovered_item >= first_match_to_print then |
| 847 | return offset + clicked_line | 842 | return hovered_item |
| 848 | end | 843 | end |
| 849 | end | 844 | end |
| 850 | 845 | ||