This makes it consistent with the new changes to show-text ${playlist} and greatly simplifies the logic, making it sane to implement scrolling the view with the wheel in the commit.
Showing the changes to player/lua/console.lua (1 of 1 file). Show all
Unified · Split
| @@ -362,60 +362,31 @@ local function populate_log_with_matches() · 361 unmodified lines | ||
| 362 | 362 | local log = log_buffers[id] |
| 363 | 363 | |
| 364 | 364 | local max_log_lines = calculate_max_log_lines() |
| 365 | + local print_counter = false | |
| 365 | 366 | |
| 366 | − if selected_match < first_match_to_print then | |
| 367 | − first_match_to_print = selected_match | |
| 368 | − end | |
| 369 | − | |
| 370 | − if first_match_to_print > 1 then | |
| 371 | − -- Reserve the first line for "n hidden items". | |
| 367 | + if #matches > max_log_lines then | |
| 368 | + print_counter = true | |
| 372 | 369 | max_log_lines = max_log_lines - 1 |
| 373 | 370 | end |
| 374 | 371 | |
| 375 | − if selected_match > first_match_to_print + max_log_lines - 1 then | |
| 376 | − -- Reserve the first line for "n hidden items" if it wasn't already. | |
| 377 | − if first_match_to_print == 1 then | |
| 378 | − max_log_lines = max_log_lines - 1 | |
| 379 | − end | |
| 380 | − | |
| 372 | + if selected_match < first_match_to_print then | |
| 373 | + first_match_to_print = selected_match | |
| 374 | + elseif selected_match > first_match_to_print + max_log_lines - 1 then | |
| 381 | 375 | first_match_to_print = selected_match - max_log_lines + 1 |
| 382 | 376 | end |
| 383 | 377 | |
| 384 | 378 | local last_match_to_print = math.min(first_match_to_print + max_log_lines - 1, |
| 385 | 379 | #matches) |
| 386 | 380 | |
| 387 | − if last_match_to_print < #matches then | |
| 388 | − -- Reserve the last line for "n hidden items". | |
| 389 | − last_match_to_print = last_match_to_print - 1 | |
| 390 | − | |
| 391 | − -- After decrementing the last match to print, we need to check if the | |
| 392 | − -- selected match is beyond the last match to print again, and shift | |
| 393 | − -- both the first and last match to print when it is. | |
| 394 | − if selected_match > last_match_to_print then | |
| 395 | − if first_match_to_print == 1 then | |
| 396 | − -- Reserve the first line for "2 hidden items". | |
| 397 | − first_match_to_print = first_match_to_print + 1 | |
| 398 | − end | |
| 399 | − | |
| 400 | − first_match_to_print = first_match_to_print + 1 | |
| 401 | − last_match_to_print = last_match_to_print + 1 | |
| 402 | − end | |
| 403 | − end | |
| 404 | − | |
| 405 | − -- When there is only 1 hidden item, print it in the previously reserved | |
| 406 | − -- line instead of printing "1 hidden items". | |
| 407 | − if first_match_to_print == 2 then | |
| 408 | − first_match_to_print = 1 | |
| 409 | − end | |
| 410 | − if last_match_to_print == #matches - 1 then | |
| 411 | − last_match_to_print = #matches | |
| 412 | − end | |
| 413 | − | |
| 414 | − if first_match_to_print > 1 then | |
| 381 | + if print_counter then | |
| 415 | 382 | log[1] = { |
| 416 | − text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)', | |
| 417 | − style = styles.disabled, | |
| 418 | − terminal_style = terminal_styles.disabled, | |
| 383 | + text = '', | |
| 384 | + style = styles.disabled .. selected_match .. '/' .. #matches .. | |
| 385 | + ' {\\fs' .. opts.font_size * 0.75 .. '}[' .. | |
| 386 | + first_match_to_print .. '-' .. last_match_to_print .. ']', | |
| 387 | + terminal_style = terminal_styles.disabled .. selected_match .. '/' .. | |
| 388 | + #matches .. ' [' .. first_match_to_print .. '-' .. | |
| 389 | + last_match_to_print .. ']', | |
| 419 | 390 | } |
| 420 | 391 | end |
| 421 | 392 | |
| @@ -438,14 +409,6 @@ local function populate_log_with_matches() · 16 unmodified lines | ||
| 438 | 409 | terminal_style = terminal_style, |
| 439 | 410 | } |
| 440 | 411 | end |
| 441 | − | |
| 442 | − if last_match_to_print < #matches then | |
| 443 | − log[#log + 1] = { | |
| 444 | − text = '↓ (' .. (#matches - last_match_to_print) .. ' hidden items)', | |
| 445 | − style = styles.disabled, | |
| 446 | − terminal_style = terminal_styles.disabled, | |
| 447 | − } | |
| 448 | − end | |
| 449 | 412 | end |
| 450 | 413 | |
| 451 | 414 | local function print_to_terminal() |
| @@ -831,16 +794,17 @@ local function highlight_hovered_line() · 379 unmodified lines | ||
| 831 | 794 | / opts.font_size |
| 832 | 795 | local clicked_line = math.floor(y / height * max_lines + .5) |
| 833 | 796 | |
| 834 | − -- Subtract 1 line for "n hidden items" when necessary. | |
| 835 | − local offset = first_match_to_print == 1 and 0 or first_match_to_print - 2 | |
| 797 | + local offset = first_match_to_print - 1 | |
| 836 | 798 | max_lines = calculate_max_log_lines() |
| 837 | 799 | |
| 800 | + -- Subtract 1 line for the position counter. | |
| 801 | + if first_match_to_print > 1 or offset + max_lines < #matches then | |
| 802 | + offset = offset - 1 | |
| 803 | + end | |
| 804 | + | |
| 838 | 805 | if #matches < max_lines then |
| 839 | 806 | clicked_line = clicked_line - (max_lines - #matches) |
| 840 | 807 | max_lines = #matches |
| 841 | − elseif offset + max_lines < #matches then | |
| 842 | − -- Subtract 1 line for "n hidden items". | |
| 843 | − max_lines = max_lines - 1 | |
| 844 | 808 | end |
| 845 | 809 | |
| 846 | 810 | if selected_match ~= offset + clicked_line |
| @@ -913,11 +877,6 @@ end · 66 unmodified lines | ||
| 913 | 877 | -- Go to the first command in the command history (PgUp) |
| 914 | 878 | local function handle_pgup() |
| 915 | 879 | if selectable_items then |
| 916 | − -- We don't know whether to count the "n hidden items" lines here; an | |
| 917 | − -- offset of 2 is better with 1 extra line because it scrolls from the | |
| 918 | − -- last to the first visible match, while with both extra lines that is | |
| 919 | − -- done with +3. When there are no "n hidden items" lines selected_match | |
| 920 | − -- becomes 1 with any offset >= 1. | |
| 921 | 880 | selected_match = math.max(selected_match - calculate_max_log_lines() + 2, 1) |
| 922 | 881 | update() |
| 923 | 882 | return |
| @@ -1789,9 +1748,9 @@ mp.register_script_message('get-input', function (script_name, args) · 865 unmodified lines | ||
| 1789 | 1748 | default_item = args.default_item |
| 1790 | 1749 | |
| 1791 | 1750 | local max_lines = calculate_max_log_lines() |
| 1792 | − first_match_to_print = math.max(1, selected_match - math.floor(max_lines / 2) + 2) | |
| 1751 | + first_match_to_print = math.max(1, selected_match - math.floor(max_lines / 2) + 1) | |
| 1793 | 1752 | if first_match_to_print > #selectable_items - max_lines + 2 then |
| 1794 | − first_match_to_print = math.max(1, #selectable_items - max_lines + 2) | |
| 1753 | + first_match_to_print = math.max(1, #selectable_items - max_lines + 1) | |
| 1795 | 1754 | end |
| 1796 | 1755 | |
| 1797 | 1756 | for i, item in ipairs(selectable_items) do |