awful.prompt: add trail space in prompt_text_with_cursor()
Adds a trailing space after text if cursor position < text length to prevent width of the widget changing particularly useful when using 'text' and 'selectall' to do eg. in-place renaming. Sample textbox content (# space, _ cursor). Before: textbox before prompt: #term# selectall prompt textbox : #_erm <- shorter than other cases after pressing end : #term_ After: textbox before prompt: #term# selectall prompt textbox : #_erm# after pressing end : #term_ Signed-off-by: koniu <gkusnierz@gmail.com>
This commit is contained in:
parent
b4f16ff649
commit
4c031ba398
|
@ -107,17 +107,19 @@ end
|
|||
-- @param cursor_pos The cursor position.
|
||||
-- @param cursor_pos The cursor underline style.
|
||||
local function prompt_text_with_cursor(text, text_color, cursor_color, cursor_pos, cursor_ul)
|
||||
local char
|
||||
local char, spacer
|
||||
if not text then text = "" end
|
||||
if #text < cursor_pos then
|
||||
char = " "
|
||||
spacer = ""
|
||||
else
|
||||
char = util.escape(text:sub(cursor_pos, cursor_pos))
|
||||
spacer = " "
|
||||
end
|
||||
local underline = cursor_ul or "none"
|
||||
local text_start = util.escape(text:sub(1, cursor_pos - 1))
|
||||
local text_end = util.escape(text:sub(cursor_pos + 1))
|
||||
return text_start .. "<span background=\"" .. util.color_strip_alpha(cursor_color) .. "\" foreground=\"" .. util.color_strip_alpha(text_color) .. "\" underline=\"" .. underline .. "\">" .. char .. "</span>" .. text_end
|
||||
return text_start .. "<span background=\"" .. util.color_strip_alpha(cursor_color) .. "\" foreground=\"" .. util.color_strip_alpha(text_color) .. "\" underline=\"" .. underline .. "\">" .. char .. "</span>" .. text_end .. spacer
|
||||
end
|
||||
|
||||
--- Run a prompt in a box.
|
||||
|
|
Loading…
Reference in New Issue