1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-20 06:46:55 +00:00

console.lua: clear the suggestions when you move the cursor

Clear completion suggestions from functions that move the cursor, so
that you can't insert suggestions at the wrong spot by pressing Tab
again after moving the cursor,

Also clear suggestions from some editing functions that were never
updated. It is not actually necessary to clear suggestions from
functions that remove text in front of the cursor, but since
handle_del() already clears them, let's just clear them everywhere.
This commit is contained in:
Guido Cella 2023-12-09 22:01:57 +01:00 committed by Dudemanguy
parent 86c8ef5c1f
commit 8ceaec1742

View File

@ -550,12 +550,14 @@ end
-- Move the cursor to the next character (Right) -- Move the cursor to the next character (Right)
function next_char(amount) function next_char(amount)
cursor = next_utf8(line, cursor) cursor = next_utf8(line, cursor)
suggestion_buffer = {}
update() update()
end end
-- Move the cursor to the previous character (Left) -- Move the cursor to the previous character (Left)
function prev_char(amount) function prev_char(amount)
cursor = prev_utf8(line, cursor) cursor = prev_utf8(line, cursor)
suggestion_buffer = {}
update() update()
end end
@ -690,6 +692,7 @@ function go_history(new_pos)
end end
cursor = line:len() + 1 cursor = line:len() + 1
insert_mode = false insert_mode = false
suggestion_buffer = {}
update() update()
end end
@ -715,6 +718,7 @@ function prev_word()
-- string in order to do a "backwards" find. This wouldn't be as annoying -- string in order to do a "backwards" find. This wouldn't be as annoying
-- to do if Lua didn't insist on 1-based indexing. -- to do if Lua didn't insist on 1-based indexing.
cursor = line:len() - select(2, line:reverse():find('%s*[^%s]*', line:len() - cursor + 2)) + 1 cursor = line:len() - select(2, line:reverse():find('%s*[^%s]*', line:len() - cursor + 2)) + 1
suggestion_buffer = {}
update() update()
end end
@ -722,6 +726,7 @@ end
-- the next word. (Ctrl+Right) -- the next word. (Ctrl+Right)
function next_word() function next_word()
cursor = select(2, line:find('%s*[^%s]*', cursor)) + 1 cursor = select(2, line:find('%s*[^%s]*', cursor)) + 1
suggestion_buffer = {}
update() update()
end end
@ -1083,12 +1088,14 @@ end
-- Move the cursor to the beginning of the line (HOME) -- Move the cursor to the beginning of the line (HOME)
function go_home() function go_home()
cursor = 1 cursor = 1
suggestion_buffer = {}
update() update()
end end
-- Move the cursor to the end of the line (END) -- Move the cursor to the end of the line (END)
function go_end() function go_end()
cursor = line:len() + 1 cursor = line:len() + 1
suggestion_buffer = {}
update() update()
end end
@ -1100,6 +1107,7 @@ function del_word()
before_cur = before_cur:gsub('[^%s]+%s*$', '', 1) before_cur = before_cur:gsub('[^%s]+%s*$', '', 1)
line = before_cur .. after_cur line = before_cur .. after_cur
cursor = before_cur:len() + 1 cursor = before_cur:len() + 1
suggestion_buffer = {}
update() update()
end end
@ -1112,12 +1120,14 @@ function del_next_word()
after_cur = after_cur:gsub('^%s*[^%s]+', '', 1) after_cur = after_cur:gsub('^%s*[^%s]+', '', 1)
line = before_cur .. after_cur line = before_cur .. after_cur
suggestion_buffer = {}
update() update()
end end
-- Delete from the cursor to the end of the line (Ctrl+K) -- Delete from the cursor to the end of the line (Ctrl+K)
function del_to_eol() function del_to_eol()
line = line:sub(1, cursor - 1) line = line:sub(1, cursor - 1)
suggestion_buffer = {}
update() update()
end end
@ -1125,6 +1135,7 @@ end
function del_to_start() function del_to_start()
line = line:sub(cursor) line = line:sub(cursor)
cursor = 1 cursor = 1
suggestion_buffer = {}
update() update()
end end
@ -1197,6 +1208,7 @@ function paste(clip)
local after_cur = line:sub(cursor) local after_cur = line:sub(cursor)
line = before_cur .. text .. after_cur line = before_cur .. text .. after_cur
cursor = cursor + text:len() cursor = cursor + text:len()
suggestion_buffer = {}
update() update()
end end