Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DOCS/man/select.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ PGUP and Ctrl+b
PGDN and Ctrl+f
Scroll down one page.

Shift+LEFT
Scroll left.

Shift+RIGHT
Scroll right.

Ctrl+y
Copy the focused item to the clipboard.

Expand All @@ -41,6 +47,12 @@ WHEEL_UP
WHEEL_DOWN
Scroll down.

WHEEL_LEFT and Shift+WHEEL_DOWN
Scroll left.

WHEEL_RIGHT and Shift+WHEEL_UP
Scroll right.

Typing printable characters does a fuzzy search of the presented items.

If the query starts with ``'``, only exact matches are filtered. You can also
Expand Down
22 changes: 19 additions & 3 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ local first_match_to_print = 1
local default_item
local item_positions = {}
local max_item_width = 0
local horizontal_offset = 0

local complete
local cycle_through_completions
Expand Down Expand Up @@ -709,7 +710,7 @@ local function render()
(global_margins.t + (1 - global_margins.t - global_margins.b) / 2) -
(math.min(#selectable_items, max_lines) + 1.5) * line_height / 2
alignment = 7
clipping_coordinates = "0,0," .. x + max_item_width .. "," .. osd_h
clipping_coordinates = x .. ",0," .. x + max_item_width .. "," .. osd_h
else
x = get_margin_x()
y = osd_h * (1 - global_margins.b) - get_margin_y()
Expand Down Expand Up @@ -828,7 +829,7 @@ local function render()

ass:new_event()
ass:an(4)
ass:pos(x, item_y)
ass:pos(x - horizontal_offset, item_y)
ass:append(style .. item)

item_positions[#item_positions + 1] =
Expand Down Expand Up @@ -1202,6 +1203,11 @@ local function move_history(amount, is_wheel)
render()
end

local function horizontal_scroll(amount)
horizontal_offset = math.max(horizontal_offset + amount, 0)
render()
end

-- Go to the first command in the command history (PgUp)
local function handle_pgup()
if selectable_items then
Expand Down Expand Up @@ -1231,6 +1237,7 @@ local function search_history()

searching_history = true
selectable_items = {}
horizontal_offset = 0

for i = 1, #history do
selectable_items[i] = history[#history + 1 - i]
Expand Down Expand Up @@ -1497,6 +1504,12 @@ local function get_bindings()
{ "wheel_down", function() move_history(1, true) end },
{ "wheel_left", function() end },
{ "wheel_right", function() end },
{ "shift+left", function() horizontal_scroll(-25) end },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why with shift?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrows without shift move the cursor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you move the cursor right/left ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever you want?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we never move focus from the text box? strange.

{ "shift+right", function() horizontal_scroll( 25) end },
{ "wheel_left", function() horizontal_scroll(-25) end },
{ "wheel_right", function() horizontal_scroll( 25) end },
{ "shift+wheel_up", function() horizontal_scroll(-25) end },
{ "shift+wheel_down", function() horizontal_scroll( 25) end },
{ "ctrl+left", prev_word },
{ "alt+b", prev_word },
{ "ctrl+right", next_word },
Expand Down Expand Up @@ -1653,13 +1666,16 @@ mp.register_script_message("get-input", function (script_name, args)

if args.items then
selectable_items = {}
horizontal_offset = 0

-- Limit the number of characters to prevent libass from freezing mpv.
-- Not important for terminal output.
local limit = terminal_output() and 5000 or (5 * osd_width / opts.font_size)

for i, item in ipairs(args.items) do
selectable_items[i] = item:gsub("[\r\n].*", "⋯"):sub(1, limit)
local last = next_utf8(item, limit) - 1
selectable_items[i] = item:gsub("[\r\n].*", "…"):sub(1, last) ..
(last < #item and "…" or "")
end

calculate_max_item_width()
Expand Down
Loading