From 83a9a19f679ff5c2d6f878484c1d6c9a63997c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Obr=C4=99bski?= Date: Wed, 9 Oct 2024 09:09:29 +0200 Subject: [PATCH] Add way to set text from the TextArea widget API --- library/lua/gui/widgets/text_area.lua | 4 ++++ test/library/gui/widgets.TextArea.lua | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/library/lua/gui/widgets/text_area.lua b/library/lua/gui/widgets/text_area.lua index c6711f90fd..a23195b133 100644 --- a/library/lua/gui/widgets/text_area.lua +++ b/library/lua/gui/widgets/text_area.lua @@ -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 diff --git a/test/library/gui/widgets.TextArea.lua b/test/library/gui/widgets.TextArea.lua index 15982f7ae6..6c300997a7 100644 --- a/test/library/gui/widgets.TextArea.lua +++ b/test/library/gui/widgets.TextArea.lua @@ -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) @@ -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