Skip to content

Commit b9422dc

Browse files
Add old_text to TextArea widget text change callback
1 parent a307308 commit b9422dc

4 files changed

Lines changed: 460 additions & 101 deletions

File tree

docs/dev/Lua API.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5555,7 +5555,7 @@ TextArea Attributes:
55555555
Functions similarly to the ``ignore_keys`` attribute in the ``EditField`` class.
55565556

55575557
* ``on_text_change``: Callback function called whenever the text changes.
5558-
The function signature should be ``on_text_change(new_text)``.
5558+
The function signature should be ``on_text_change(new_text, old_text)``.
55595559

55605560
* ``on_cursor_change``: Callback function called whenever the cursor position changes.
55615561
Expected function signature is ``on_cursor_change(new_cursor, old_cursor)``.

library/lua/gui/widgets/text_area.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ function TextArea:init()
3434
debug=self.debug,
3535
one_line_mode=self.one_line_mode,
3636

37-
on_text_change=function (val)
37+
on_text_change=function (text, old_text)
3838
self:updateLayout()
3939
if self.on_text_change then
40-
self.on_text_change(val)
40+
self.on_text_change(text, old_text)
4141
end
4242
end,
4343
on_cursor_change=self:callback('onCursorChange')

library/lua/gui/widgets/text_area/text_area_content.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ function TextAreaContent:paste()
189189
end
190190

191191
function TextAreaContent:setText(text)
192-
local changed = self.text ~= text
192+
local old_text = self.text
193+
193194
self.text = self:normalizeText(text)
194195

195196
self:recomputeLines()
196197

197-
if changed and self.on_text_change then
198-
self.on_text_change(text)
198+
if self.on_text_change and text ~= old_text then
199+
self.on_text_change(text, old_text)
199200
end
200201
end
201202

0 commit comments

Comments
 (0)