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
362362 local log = log_buffers[id]
363363
364364 local max_log_lines = calculate_max_log_lines()
365+ local print_counter = false
365366
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
372369 max_log_lines = max_log_lines - 1
373370 end
374371
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
381375 first_match_to_print = selected_match - max_log_lines + 1
382376 end
383377
384378 local last_match_to_print = math.min(first_match_to_print + max_log_lines - 1,
385379 #matches)
386380
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
415382 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 .. ']',
419390 }
420391 end
421392
@@ -438,14 +409,6 @@ local function populate_log_with_matches() · 16 unmodified lines
438409 terminal_style = terminal_style,
439410 }
440411 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
449412 end
450413
451414 local function print_to_terminal()
@@ -831,16 +794,17 @@ local function highlight_hovered_line() · 379 unmodified lines
831794 / opts.font_size
832795 local clicked_line = math.floor(y / height * max_lines + .5)
833796
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
836798 max_lines = calculate_max_log_lines()
837799
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+
838805 if #matches < max_lines then
839806 clicked_line = clicked_line - (max_lines - #matches)
840807 max_lines = #matches
841− elseif offset + max_lines < #matches then
842− -- Subtract 1 line for "n hidden items".
843− max_lines = max_lines - 1
844808 end
845809
846810 if selected_match ~= offset + clicked_line
@@ -913,11 +877,6 @@ end · 66 unmodified lines
913877 -- Go to the first command in the command history (PgUp)
914878 local function handle_pgup()
915879 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.
921880 selected_match = math.max(selected_match - calculate_max_log_lines() + 2, 1)
922881 update()
923882 return
@@ -1789,9 +1748,9 @@ mp.register_script_message('get-input', function (script_name, args) · 865 unmodified lines
17891748 default_item = args.default_item
17901749
17911750 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)
17931752 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)
17951754 end
17961755
17971756 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