Skip to content

Commit 3f59ac9

Browse files
committed
console.lua: implement horizontal scroll
Bind Shift+LEFT, Shift+RIGHT, Shift+WHEEL_DOWN, Shift+WHEEL_UP, WHEEL_LEFT, WHEEL_RIGHT to scroll the menu horizontally. This lets you see long items that get clipped, like long history entries and key bindings.
1 parent 233e896 commit 3f59ac9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

DOCS/man/select.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ PGUP and Ctrl+b
2828
PGDN and Ctrl+f
2929
Scroll down one page.
3030

31+
Shift+LEFT
32+
Scroll left.
33+
34+
Shift+RIGHT
35+
Scroll right.
36+
3137
Ctrl+y
3238
Copy the focused item to the clipboard.
3339

@@ -41,6 +47,12 @@ WHEEL_UP
4147
WHEEL_DOWN
4248
Scroll down.
4349

50+
WHEEL_LEFT and Shift+WHEEL_DOWN
51+
Scroll left.
52+
53+
WHEEL_RIGHT and Shift+WHEEL_UP
54+
Scroll right.
55+
4456
Typing printable characters does a fuzzy search of the presented items.
4557

4658
If the query starts with ``'``, only exact matches are filtered. You can also

player/lua/console.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ local first_match_to_print = 1
114114
local default_item
115115
local item_positions = {}
116116
local max_item_width = 0
117+
local horizontal_offset = 0
117118

118119
local complete
119120
local cycle_through_completions
@@ -709,7 +710,7 @@ local function render()
709710
(global_margins.t + (1 - global_margins.t - global_margins.b) / 2) -
710711
(math.min(#selectable_items, max_lines) + 1.5) * line_height / 2
711712
alignment = 7
712-
clipping_coordinates = "0,0," .. x + max_item_width .. "," .. osd_h
713+
clipping_coordinates = x .. ",0," .. x + max_item_width .. "," .. osd_h
713714
else
714715
x = get_margin_x()
715716
y = osd_h * (1 - global_margins.b) - get_margin_y()
@@ -828,7 +829,7 @@ local function render()
828829

829830
ass:new_event()
830831
ass:an(4)
831-
ass:pos(x, item_y)
832+
ass:pos(x - horizontal_offset, item_y)
832833
ass:append(style .. item)
833834

834835
item_positions[#item_positions + 1] =
@@ -1202,6 +1203,11 @@ local function move_history(amount, is_wheel)
12021203
render()
12031204
end
12041205

1206+
local function horizontal_scroll(amount)
1207+
horizontal_offset = math.max(horizontal_offset + amount, 0)
1208+
render()
1209+
end
1210+
12051211
-- Go to the first command in the command history (PgUp)
12061212
local function handle_pgup()
12071213
if selectable_items then
@@ -1231,6 +1237,7 @@ local function search_history()
12311237

12321238
searching_history = true
12331239
selectable_items = {}
1240+
horizontal_offset = 0
12341241

12351242
for i = 1, #history do
12361243
selectable_items[i] = history[#history + 1 - i]
@@ -1497,6 +1504,12 @@ local function get_bindings()
14971504
{ "wheel_down", function() move_history(1, true) end },
14981505
{ "wheel_left", function() end },
14991506
{ "wheel_right", function() end },
1507+
{ "shift+left", function() horizontal_scroll(-25) end },
1508+
{ "shift+right", function() horizontal_scroll(25) end },
1509+
{ "wheel_left", function() horizontal_scroll(-25) end },
1510+
{ "wheel_right", function() horizontal_scroll(25) end },
1511+
{ "shift+wheel_up", function() horizontal_scroll(-25) end },
1512+
{ "shift+wheel_down", function() horizontal_scroll(25) end },
15001513
{ "ctrl+left", prev_word },
15011514
{ "alt+b", prev_word },
15021515
{ "ctrl+right", next_word },
@@ -1653,6 +1666,7 @@ mp.register_script_message("get-input", function (script_name, args)
16531666

16541667
if args.items then
16551668
selectable_items = {}
1669+
horizontal_offset = 0
16561670

16571671
-- Limit the number of characters to prevent libass from freezing mpv.
16581672
-- Not important for terminal output.

0 commit comments

Comments
 (0)