From b4f16ff649926f86abbf0a2c584e45ef8c3f8e76 Mon Sep 17 00:00:00 2001 From: koniu Date: Wed, 19 Nov 2008 10:44:27 +0000 Subject: [PATCH] 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 --- lib/awful/prompt.lua.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index 81af01f1..6d3bb279 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -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