awful.prompt: new arg 'selectall' in add()
If set along with 'text' (prefilled content) it will position the cursor at the beginning of the line and and on text input (and not control keys, arrows, etc.) will overwrite the prefilled content with the new input. Signed-off-by: koniu <gkusnierz@gmail.com>
This commit is contained in:
parent
65d5e29141
commit
b4f16ff649
|
@ -121,7 +121,7 @@ local function prompt_text_with_cursor(text, text_color, cursor_color, cursor_po
|
|||
end
|
||||
|
||||
--- Run a prompt in a box.
|
||||
-- @param args A table with optional arguments: fg_cursor, bg_cursor, ul_cursor, prompt.
|
||||
-- @param args A table with optional arguments: fg_cursor, bg_cursor, ul_cursor, prompt, text, selectall .
|
||||
-- @param textbox The textbox to use for the prompt.
|
||||
-- @param exe_callback The callback function to call with command as argument when finished.
|
||||
-- @param completion_callback The callback function to call to get completion.
|
||||
|
@ -143,7 +143,7 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
|
|||
history_check_load(history_path, history_max)
|
||||
local history_index = history_items(history_path) + 1
|
||||
-- The cursor position
|
||||
local cur_pos = text:len() + 1
|
||||
local cur_pos = (args.selectall and 1) or text:len() + 1
|
||||
-- The completion element to use on completion request.
|
||||
local ncomp = 1
|
||||
if not textbox or not exe_callback then
|
||||
|
@ -279,6 +279,7 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
|
|||
-- len() is UTF-8 aware but #key is not,
|
||||
-- so check that we have one UTF-8 char but advance the cursor of # position
|
||||
if key:len() == 1 then
|
||||
if args.selectall and cur_pos == 1 then command = "" end
|
||||
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
|
||||
cur_pos = cur_pos + #key
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue