Skip to content

Commit

Permalink
Add way to set text from the TextArea widget API
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-obrebski committed Oct 9, 2024
1 parent e237387 commit 83a9a19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions library/lua/gui/widgets/text_area.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function TextArea:getText()
return self.subviews.text_area.text
end

function TextArea:setText(text)
return self.subviews.text_area:setText(text)
end

function TextArea:getCursor()
return self.subviews.text_area.cursor
end
Expand Down
19 changes: 18 additions & 1 deletion test/library/gui/widgets.TextArea.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ local function arrange_textarea(options)
screen:show()
screen:onRender()

return text_area, screen, window
return text_area, screen, window, screen.subviews.text_area_widget
end

local function read_rendered_text(text_area)
Expand Down Expand Up @@ -2600,3 +2600,20 @@ function test.fast_rewind_reset_selection()

screen:dismiss()
end

function test.render_text_set_by_api()
local text_area, screen, window, widget = arrange_textarea({w=80})

local text = table.concat({
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Pellentesque dignissim volutpat orci, sed molestie metus elementum vel.',
'Donec sit amet mattis ligula, ac vestibulum lorem.',
}, '\n')

widget:setText(text)
widget:setCursor(#text + 1)

expect.eq(read_rendered_text(text_area), text .. '_')

screen:dismiss()
end

0 comments on commit 83a9a19

Please sign in to comment.