@@ -791,6 +791,11 @@ local function help_command(param)
791791 log_add (output :sub (1 , - 2 ))
792792end
793793
794+ local function unbind_mouse ()
795+ mp .remove_key_binding (' _console_mouse_move' )
796+ mp .remove_key_binding (' _console_mbtn_left' )
797+ end
798+
794799-- Run the current command and clear the line (Enter)
795800local function handle_enter ()
796801 if searching_history then
@@ -800,6 +805,7 @@ local function handle_enter()
800805 cursor = # line + 1
801806 log_buffers [id ] = {}
802807 update ()
808+ unbind_mouse ()
803809 return
804810 end
805811
@@ -833,6 +839,46 @@ local function handle_enter()
833839 clear ()
834840end
835841
842+ local function highlight_hovered_line ()
843+ local height = mp .get_property_native (' osd-height' )
844+ if height == 0 then
845+ return
846+ end
847+
848+ local y = mp .get_property_native (' mouse-pos' ).y - global_margins .t * height
849+ -- Calculate how many lines could be printed without decreasing them for
850+ -- the input line and OSC.
851+ local max_lines = height / mp .get_property_native (' display-hidpi-scale' )
852+ / opts .font_size
853+ local clicked_line = math.floor (y / height * max_lines + .5 )
854+
855+ -- Subtract 1 line for "n hidden items" when necessary.
856+ local offset = first_match_to_print == 1 and 0 or first_match_to_print - 2
857+ max_lines = calculate_max_log_lines ()
858+
859+ if # matches < max_lines then
860+ clicked_line = clicked_line - (max_lines - # matches )
861+ max_lines = # matches
862+ elseif offset + max_lines < # matches then
863+ -- Subtract 1 line for "n hidden items".
864+ max_lines = max_lines - 1
865+ end
866+
867+ if selected_match ~= offset + clicked_line
868+ and clicked_line > 0 and clicked_line <= max_lines then
869+ selected_match = offset + clicked_line
870+ update ()
871+ end
872+ end
873+
874+ local function bind_mouse ()
875+ mp .add_forced_key_binding (' MOUSE_MOVE' , ' _console_mouse_move' , highlight_hovered_line )
876+ mp .add_forced_key_binding (' MBTN_LEFT' , ' _console_mbtn_left' , function ()
877+ highlight_hovered_line ()
878+ handle_enter ()
879+ end )
880+ end
881+
836882-- Go to the specified position in the command history
837883local function go_history (new_pos )
838884 local old_pos = history_pos
@@ -932,6 +978,7 @@ local function search_history()
932978 end
933979
934980 update ()
981+ bind_mouse ()
935982end
936983
937984local function page_up_or_prev_char ()
@@ -1082,7 +1129,12 @@ end
10821129
10831130-- Paste text from the window-system's clipboard. 'clip' determines whether the
10841131-- clipboard or the primary selection buffer is used (on X11 and Wayland only.)
1085- local function paste (clip )
1132+ local function paste (clip , is_wheel )
1133+ if is_wheel and selectable_items then
1134+ handle_enter ()
1135+ return
1136+ end
1137+
10861138 local text = get_clipboard (clip )
10871139 local before_cur = line :sub (1 , cursor - 1 )
10881140 local after_cur = line :sub (cursor )
@@ -1567,7 +1619,7 @@ local function get_bindings()
15671619 { ' shift+del' , handle_del },
15681620 { ' ins' , handle_ins },
15691621 { ' shift+ins' , function () paste (false ) end },
1570- { ' mbtn_mid' , function () paste (false ) end },
1622+ { ' mbtn_mid' , function () paste (false , true ) end },
15711623 { ' left' , function () prev_char () end },
15721624 { ' ctrl+b' , function () page_up_or_prev_char () end },
15731625 { ' right' , function () next_char () end },
@@ -1665,6 +1717,7 @@ set_active = function (active)
16651717 cursor = 1
16661718 selectable_items = nil
16671719 log_buffers [id ] = {}
1720+ unbind_mouse ()
16681721 else
16691722 repl_active = false
16701723 suggestion_buffer = {}
@@ -1679,6 +1732,7 @@ set_active = function (active)
16791732 cursor = 1
16801733 selectable_items = nil
16811734 dont_bind_up_down = false
1735+ unbind_mouse ()
16821736 end
16831737 collectgarbage ()
16841738 end
@@ -1754,6 +1808,7 @@ mp.register_script_message('get-input', function (script_name, args)
17541808 for i , item in ipairs (selectable_items ) do
17551809 matches [i ] = { index = i , text = item }
17561810 end
1811+ bind_mouse ()
17571812 end
17581813
17591814 set_active (true )
0 commit comments