From 24d69ee6792f324d8f9c84d9da9f89f763d4dca8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 18 Oct 2019 00:26:03 +0300 Subject: [PATCH] Added rpl::event_stream for document contents changes in InputField. --- ui/widgets/input_fields.cpp | 1 + ui/widgets/input_fields.h | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index 8ad10f0..1583ddd 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -2210,6 +2210,7 @@ void InputField::onDocumentContentsChange( _correcting = false; QTextCursor(document->docHandle(), 0).endEditBlock(); handleContentsChanged(); + _documentContentsChanges.fire({position, charsRemoved, charsAdded}); }); chopByMaxLength(insertPosition, insertLength); diff --git a/ui/widgets/input_fields.h b/ui/widgets/input_fields.h index 5943da3..2dc3723 100644 --- a/ui/widgets/input_fields.h +++ b/ui/widgets/input_fields.h @@ -315,6 +315,15 @@ public: int scrollTopMax() const; void scrollTo(int top); + struct DocumentChangeInfo { + int position = 0; + int added = 0; + int removed = 0; + }; + auto documentContentsChanges() { + return _documentContentsChanges.events(); + } + ~InputField(); private slots: @@ -514,6 +523,8 @@ private: InstantReplaces _mutableInstantReplaces; bool _instantReplacesEnabled = true; + rpl::event_stream _documentContentsChanges; + }; class MaskedInputField : public RpWidgetWrap {