Skip to content

Commit

Permalink
Add old_text to TextArea widget text change callback
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-obrebski committed Nov 20, 2024
1 parent a307308 commit 795d2be
Show file tree
Hide file tree
Showing 4 changed files with 460 additions and 101 deletions.
2 changes: 1 addition & 1 deletion docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5555,7 +5555,7 @@ TextArea Attributes:
Functions similarly to the ``ignore_keys`` attribute in the ``EditField`` class.

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

* ``on_cursor_change``: Callback function called whenever the cursor position changes.
Expected function signature is ``on_cursor_change(new_cursor, old_cursor)``.
Expand Down
4 changes: 2 additions & 2 deletions library/lua/gui/widgets/text_area.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function TextArea:init()
debug=self.debug,
one_line_mode=self.one_line_mode,

on_text_change=function (val)
on_text_change=function (text, old_text)
self:updateLayout()
if self.on_text_change then
self.on_text_change(val)
self.on_text_change(text, old_text)
end
end,
on_cursor_change=self:callback('onCursorChange')
Expand Down
7 changes: 4 additions & 3 deletions library/lua/gui/widgets/text_area/text_area_content.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ function TextAreaContent:paste()
end

function TextAreaContent:setText(text)
local changed = self.text ~= text
local old_text = self.text

self.text = self:normalizeText(text)

self:recomputeLines()

if changed and self.on_text_change then
self.on_text_change(text)
if self.on_text_change and text ~= old_text then
self.on_text_change(text, old_text)
end
end

Expand Down
Loading

0 comments on commit 795d2be

Please sign in to comment.