diff --git a/graphics/core.lua b/graphics/core.lua index e9cacd4..46110c2 100644 --- a/graphics/core.lua +++ b/graphics/core.lua @@ -216,14 +216,7 @@ function core.new_ifield(e, max_len, fg_bg, dis_fg_bg) ---@param val string function public.set_value(val) e.value = string.sub(val, 1, math.min(max_len, string.len(val))) - - self.selected_all = false - self.frame_start = math.max(1, string.len(e.value) - e.frame.w + 2) - - _update_visible() - self.cursor_pos = string.len(self.visible_text) + 1 - - public.show() + public.nav_end() end -- try to insert a character if there is space @@ -282,6 +275,21 @@ function core.new_ifield(e, max_len, fg_bg, dis_fg_bg) elseif _try_rshift() then public.show() end end + -- move cursor to the start + function public.nav_start() + self.cursor_pos = 1 + self.frame_start = 1 + public.show() + end + + -- move cursor to the end + function public.nav_end() + self.frame_start = math.max(1, string.len(e.value) - e.frame.w + 2) + _update_visible() + self.cursor_pos = string.len(self.visible_text) + 1 + public.show() + end + return public end diff --git a/graphics/elements/form/number_field.lua b/graphics/elements/form/number_field.lua index 43554ce..3c920b8 100644 --- a/graphics/elements/form/number_field.lua +++ b/graphics/elements/form/number_field.lua @@ -106,6 +106,10 @@ local function number_field(args) ifield.nav_right() elseif event.key == keys.a and event.ctrl then ifield.select_all() + elseif event.key == keys.home or event.key == keys.up then + ifield.nav_start() + elseif event.key == keys["end"] or event.key == keys.down then + ifield.nav_end() end end end diff --git a/graphics/elements/form/text_field.lua b/graphics/elements/form/text_field.lua index ebeb35a..7ac786a 100644 --- a/graphics/elements/form/text_field.lua +++ b/graphics/elements/form/text_field.lua @@ -65,6 +65,10 @@ local function text_field(args) ifield.nav_right() elseif event.key == keys.a and event.ctrl then ifield.select_all() + elseif event.key == keys.home or event.key == keys.up then + ifield.nav_start() + elseif event.key == keys["end"] or event.key == keys.down then + ifield.nav_end() end end end