History

console.lua: print position/count instead of n hidden items

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.

Guido Cella committed 2 years ago

Commit e88a1a71 parent 77239b81 file · +22 −63Browse files

Showing the changes to player/lua/console.lua (1 of 1 file). Show all

Unified · Split

player/lua/console.lua+22−63
@@ -362,60 +362,31 @@ local function populate_log_with_matches() · 361 unmodified lines
362 local log = log_buffers[id]362 local log = log_buffers[id]
363 363
364 local max_log_lines = calculate_max_log_lines()364 local max_log_lines = calculate_max_log_lines()
365 local print_counter = false
365 366
366 if selected_match < first_match_to_print then367 if #matches > max_log_lines then
367 first_match_to_print = selected_match368 print_counter = true
368 end
369
370 if first_match_to_print > 1 then
371 -- Reserve the first line for "n hidden items".
372 max_log_lines = max_log_lines - 1369 max_log_lines = max_log_lines - 1
373 end370 end
374 371
375 if selected_match > first_match_to_print + max_log_lines - 1 then372 if selected_match < first_match_to_print then
376 -- Reserve the first line for "n hidden items" if it wasn't already.373 first_match_to_print = selected_match
377 if first_match_to_print == 1 then374 elseif selected_match > first_match_to_print + max_log_lines - 1 then
378 max_log_lines = max_log_lines - 1
379 end
380
381 first_match_to_print = selected_match - max_log_lines + 1375 first_match_to_print = selected_match - max_log_lines + 1
382 end376 end
383 377
384 local last_match_to_print = math.min(first_match_to_print + max_log_lines - 1,378 local last_match_to_print = math.min(first_match_to_print + max_log_lines - 1,
385 #matches)379 #matches)
386 380
387 if last_match_to_print < #matches then381 if print_counter 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
415 log[1] = {382 log[1] = {
416 text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)',383 text = '',
417 style = styles.disabled,384 style = styles.disabled .. selected_match .. '/' .. #matches ..
418 terminal_style = terminal_styles.disabled,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 end391 end
421 392
@@ -438,14 +409,6 @@ local function populate_log_with_matches() · 16 unmodified lines
438 terminal_style = terminal_style,409 terminal_style = terminal_style,
439 }410 }
440 end411 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
449end412end
450 413
451local function print_to_terminal()414local function print_to_terminal()
@@ -831,16 +794,17 @@ local function highlight_hovered_line() · 379 unmodified lines
831 / opts.font_size794 / opts.font_size
832 local clicked_line = math.floor(y / height * max_lines + .5)795 local clicked_line = math.floor(y / height * max_lines + .5)
833 796
834 -- Subtract 1 line for "n hidden items" when necessary.797 local offset = first_match_to_print - 1
835 local offset = first_match_to_print == 1 and 0 or first_match_to_print - 2
836 max_lines = calculate_max_log_lines()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 if #matches < max_lines then805 if #matches < max_lines then
839 clicked_line = clicked_line - (max_lines - #matches)806 clicked_line = clicked_line - (max_lines - #matches)
840 max_lines = #matches807 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 end808 end
845 809
846 if selected_match ~= offset + clicked_line810 if selected_match ~= offset + clicked_line
@@ -913,11 +877,6 @@ end · 66 unmodified lines
913-- Go to the first command in the command history (PgUp)877-- Go to the first command in the command history (PgUp)
914local function handle_pgup()878local function handle_pgup()
915 if selectable_items then879 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 selected_match = math.max(selected_match - calculate_max_log_lines() + 2, 1)880 selected_match = math.max(selected_match - calculate_max_log_lines() + 2, 1)
922 update()881 update()
923 return882 return
@@ -1789,9 +1748,9 @@ mp.register_script_message('get-input', function (script_name, args) · 865 unmodified lines
1789 default_item = args.default_item1748 default_item = args.default_item
1790 1749
1791 local max_lines = calculate_max_log_lines()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 if first_match_to_print > #selectable_items - max_lines + 2 then1752 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 end1754 end
1796 1755
1797 for i, item in ipairs(selectable_items) do1756 for i, item in ipairs(selectable_items) do

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t