update move cursor functions to allow holding down key (#11)

This commit is contained in:
Kyle Yasuda 2023-08-08 02:21:24 -07:00 committed by GitHub
parent a1c2bfd9a7
commit 3814459024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -370,25 +370,31 @@ function YouTubeQueue.print_queue(duration)
end end
end end
function YouTubeQueue.move_cursor_up() function YouTubeQueue.move_cursor_up(amt)
if selected_index > 1 then selected_index = selected_index - amt
selected_index = selected_index - 1 if selected_index < 1 then
if selected_index < display_offset + 1 then selected_index = 1
display_offset = display_offset - 1 elseif selected_index > #video_queue then
selected_index = #video_queue
end
if selected_index > 1 and selected_index < display_offset + 1 then
display_offset = display_offset - math.abs(selected_index - amt)
end end
YouTubeQueue.print_queue(MSG_DURATION) YouTubeQueue.print_queue(MSG_DURATION)
end end
end
function YouTubeQueue.move_cursor_down() function YouTubeQueue.move_cursor_down(amt)
if selected_index < YouTubeQueue.size() then selected_index = selected_index + amt
selected_index = selected_index + 1 if selected_index < 1 then
if selected_index > display_offset + display_limit then selected_index = 1
display_offset = display_offset + 1 elseif selected_index > #video_queue then
selected_index = #video_queue
end
if selected_index < #video_queue and selected_index > display_offset + display_limit then
display_offset = display_offset + math.abs(selected_index - amt)
end end
YouTubeQueue.print_queue(MSG_DURATION) YouTubeQueue.print_queue(MSG_DURATION)
end end
end
function YouTubeQueue.play_video_at(idx) function YouTubeQueue.play_video_at(idx)
local queue = YouTubeQueue.get_video_queue() local queue = YouTubeQueue.get_video_queue()
@ -618,9 +624,9 @@ mp.add_key_binding(options.play_previous_in_queue, "play_previous_video",
YouTubeQueue.play_previous_video) YouTubeQueue.play_previous_video)
mp.add_key_binding(options.print_queue, "print_queue", YouTubeQueue.print_queue) mp.add_key_binding(options.print_queue, "print_queue", YouTubeQueue.print_queue)
mp.add_key_binding(options.move_cursor_up, "move_cursor_up", mp.add_key_binding(options.move_cursor_up, "move_cursor_up",
YouTubeQueue.move_cursor_up, { repeatable = true }) function() YouTubeQueue.move_cursor_up(1) end, { repeatable = true })
mp.add_key_binding(options.move_cursor_down, "move_cursor_down", mp.add_key_binding(options.move_cursor_down, "move_cursor_down",
YouTubeQueue.move_cursor_down, { repeatable = true }) function() YouTubeQueue.move_cursor_down(1) end, { repeatable = true })
mp.add_key_binding(options.play_selected_video, "play_selected_video", mp.add_key_binding(options.play_selected_video, "play_selected_video",
YouTubeQueue.play_selected_video) YouTubeQueue.play_selected_video)
mp.add_key_binding(options.open_video_in_browser, "open_video_in_browser", mp.add_key_binding(options.open_video_in_browser, "open_video_in_browser",