Skip to content

Commit

Permalink
Merge pull request #5227 from wiktor-obrebski/fix/edit-field-long-lines
Browse files Browse the repository at this point in the history
Fix Edit Field long lines changing text cursor behaviour
  • Loading branch information
myk002 authored Jan 30, 2025
2 parents 3a70855 + 3071db5 commit c1ddbde
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 0 additions & 1 deletion library/lua/gui/widgets/edit_field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ function EditField:init()
self:setFocus(true)
end

self.start_pos = 1
self.cursor = #self.text + 1
self.ignore_keys = self.ignore_keys or {}

Expand Down
10 changes: 9 additions & 1 deletion library/lua/gui/widgets/text_area.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ function TextArea:setText(text)
self:getCursor()
)

return self.text_area:setText(text)
self.text_area:setText(text)

if self.one_line_mode then
self.render_start_x = 1
local cursor = self:getCursor()
if cursor then
self:setCursor(math.min(self:getCursor(), #text + 1))
end
end
end

function TextArea:getCursor()
Expand Down
21 changes: 21 additions & 0 deletions test/library/gui/widgets.TextArea.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3391,3 +3391,24 @@ function test.should_scroll_horizontally_in_one_line_mode()

screen:dismiss()
end

function test.should_reset_horizontal_in_one_line_mode()
local text_area, screen, window, widget = arrange_textarea({
w=40,
one_line_mode=true
})

local text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dignissim volutpat orci, sed'

widget:setText(text)

widget:setCursor(#text + 1)

expect.eq(read_rendered_text(text_area), text:sub(-39) .. '_')

widget:setText('Lorem ipsum')

expect.eq(read_rendered_text(text_area), 'Lorem ipsum_')

screen:dismiss()
end

0 comments on commit c1ddbde

Please sign in to comment.