#344 nav to start/end of fields

This commit is contained in:
Mikayla Fischler 2023-09-23 15:30:53 -04:00
parent 645a5f5137
commit 18bcfb4014
3 changed files with 24 additions and 8 deletions

View File

@ -216,14 +216,7 @@ function core.new_ifield(e, max_len, fg_bg, dis_fg_bg)
---@param val string ---@param val string
function public.set_value(val) function public.set_value(val)
e.value = string.sub(val, 1, math.min(max_len, string.len(val))) e.value = string.sub(val, 1, math.min(max_len, string.len(val)))
public.nav_end()
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()
end end
-- try to insert a character if there is space -- 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 elseif _try_rshift() then public.show() end
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 return public
end end

View File

@ -106,6 +106,10 @@ local function number_field(args)
ifield.nav_right() ifield.nav_right()
elseif event.key == keys.a and event.ctrl then elseif event.key == keys.a and event.ctrl then
ifield.select_all() 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 end
end end

View File

@ -65,6 +65,10 @@ local function text_field(args)
ifield.nav_right() ifield.nav_right()
elseif event.key == keys.a and event.ctrl then elseif event.key == keys.a and event.ctrl then
ifield.select_all() 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 end
end end