Skip to content

Commit c1ddbde

Browse files
authored
Merge pull request #5227 from wiktor-obrebski/fix/edit-field-long-lines
Fix Edit Field long lines changing text cursor behaviour
2 parents 3a70855 + 3071db5 commit c1ddbde

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

library/lua/gui/widgets/edit_field.lua

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ function EditField:init()
114114
self:setFocus(true)
115115
end
116116

117-
self.start_pos = 1
118117
self.cursor = #self.text + 1
119118
self.ignore_keys = self.ignore_keys or {}
120119

library/lua/gui/widgets/text_area.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ function TextArea:setText(text)
6969
self:getCursor()
7070
)
7171

72-
return self.text_area:setText(text)
72+
self.text_area:setText(text)
73+
74+
if self.one_line_mode then
75+
self.render_start_x = 1
76+
local cursor = self:getCursor()
77+
if cursor then
78+
self:setCursor(math.min(self:getCursor(), #text + 1))
79+
end
80+
end
7381
end
7482

7583
function TextArea:getCursor()

test/library/gui/widgets.TextArea.lua

+21
Original file line numberDiff line numberDiff line change
@@ -3391,3 +3391,24 @@ function test.should_scroll_horizontally_in_one_line_mode()
33913391

33923392
screen:dismiss()
33933393
end
3394+
3395+
function test.should_reset_horizontal_in_one_line_mode()
3396+
local text_area, screen, window, widget = arrange_textarea({
3397+
w=40,
3398+
one_line_mode=true
3399+
})
3400+
3401+
local text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dignissim volutpat orci, sed'
3402+
3403+
widget:setText(text)
3404+
3405+
widget:setCursor(#text + 1)
3406+
3407+
expect.eq(read_rendered_text(text_area), text:sub(-39) .. '_')
3408+
3409+
widget:setText('Lorem ipsum')
3410+
3411+
expect.eq(read_rendered_text(text_area), 'Lorem ipsum_')
3412+
3413+
screen:dismiss()
3414+
end

0 commit comments

Comments
 (0)