summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TextEditor.cpp
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2021-09-21 17:02:48 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-22 21:35:42 +0200
commit92fffc3abc50dfd6a7cf6788984f712cece0b7d8 (patch)
tree2ae0356cb4ee078bdba20c47b846d0c40c45a6c2 /Userland/Libraries/LibGUI/TextEditor.cpp
parentd47e431d54b4facd77703f8efd3b68e2eedc4835 (diff)
downloadserenity-92fffc3abc50dfd6a7cf6788984f712cece0b7d8.zip
LibGUI: Rename CallOnChange => AllowCallback and implement elsewhere
This is a helpful option to prevent unwanted side effects, distinguish between user and programmatic input, etc. Sliders and SpinBoxes were implementing it idiosyncratically, so let's generalize the API and give Buttons and TextEditors the same ability.
Diffstat (limited to 'Userland/Libraries/LibGUI/TextEditor.cpp')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index b5ba783714..425da4e01b 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -101,11 +101,11 @@ void TextEditor::create_actions()
m_select_all_action = CommonActions::make_select_all_action([this](auto&) { select_all(); }, this);
}
-void TextEditor::set_text(StringView const& text)
+void TextEditor::set_text(StringView const& text, AllowCallback allow_callback)
{
m_selection.clear();
- document().set_text(text);
+ document().set_text(text, allow_callback);
update_content_size();
recompute_all_visual_lines();
@@ -1480,7 +1480,7 @@ void TextEditor::leave_event(Core::Event&)
m_automatic_selection_scroll_timer->start();
}
-void TextEditor::did_change()
+void TextEditor::did_change(AllowCallback allow_callback)
{
update_content_size();
recompute_all_visual_lines();
@@ -1492,9 +1492,9 @@ void TextEditor::did_change()
m_needs_rehighlight = true;
if (!m_has_pending_change_notification) {
m_has_pending_change_notification = true;
- deferred_invoke([this] {
+ deferred_invoke([this, allow_callback] {
m_has_pending_change_notification = false;
- if (on_change)
+ if (on_change && allow_callback == AllowCallback::Yes)
on_change();
});
}
@@ -1784,9 +1784,9 @@ void TextEditor::document_did_insert_line(size_t line_index)
update();
}
-void TextEditor::document_did_change()
+void TextEditor::document_did_change(AllowCallback allow_callback)
{
- did_change();
+ did_change(allow_callback);
update();
}
@@ -1814,12 +1814,12 @@ void TextEditor::document_did_update_undo_stack()
on_modified_change(document().is_modified());
}
-void TextEditor::document_did_set_text()
+void TextEditor::document_did_set_text(AllowCallback allow_callback)
{
m_line_visual_data.clear();
for (size_t i = 0; i < m_document->line_count(); ++i)
m_line_visual_data.append(make<LineVisualData>());
- document_did_change();
+ document_did_change(allow_callback);
}
void TextEditor::document_did_set_cursor(TextPosition const& position)