aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2021-09-24 12:08:33 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2021-09-24 11:57:12 +0000
commit47cd1def7a7a9909a3cfc2f21f9b8a8631600a5a (patch)
tree80f008632ddcf2ec432c3967bcb76754fd54f642 /src/plugins/texteditor
parent421e06393ff9cb8f409ef5703723aaefee857c7d (diff)
TextEditor: Provide a function for inserting a parenthesis
... into a sorted list. Change-Id: Ibc39a345425945437cc8b8d9237589746143b2d9 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/textdocumentlayout.cpp7
-rw-r--r--src/plugins/texteditor/textdocumentlayout.h4
2 files changed, 9 insertions, 2 deletions
diff --git a/src/plugins/texteditor/textdocumentlayout.cpp b/src/plugins/texteditor/textdocumentlayout.cpp
index 111a47ca067..38a367cb89f 100644
--- a/src/plugins/texteditor/textdocumentlayout.cpp
+++ b/src/plugins/texteditor/textdocumentlayout.cpp
@@ -698,4 +698,11 @@ bool Parenthesis::operator==(const Parenthesis &other) const
return pos == other.pos && chr == other.chr && source == other.source && type == other.type;
}
+void insertSorted(Parentheses &list, const Parenthesis &elem)
+{
+ const auto it = std::lower_bound(list.begin(), list.end(), elem,
+ [](const auto &p1, const auto &p2) { return p1.pos < p2.pos; });
+ list.insert(it, elem);
+}
+
} // namespace TextEditor
diff --git a/src/plugins/texteditor/textdocumentlayout.h b/src/plugins/texteditor/textdocumentlayout.h
index 69b0159860e..ce86ad42961 100644
--- a/src/plugins/texteditor/textdocumentlayout.h
+++ b/src/plugins/texteditor/textdocumentlayout.h
@@ -38,8 +38,6 @@
#include <QPlainTextDocumentLayout>
namespace TextEditor {
-struct Parenthesis;
-using Parentheses = QVector<Parenthesis>;
struct TEXTEDITOR_EXPORT Parenthesis
{
@@ -55,6 +53,8 @@ struct TEXTEDITOR_EXPORT Parenthesis
bool operator==(const Parenthesis &other) const;
};
+using Parentheses = QVector<Parenthesis>;
+TEXTEDITOR_EXPORT void insertSorted(Parentheses &list, const Parenthesis &elem);
TEXTEDITOR_EXPORT QDebug operator<<(QDebug debug, const Parenthesis &parenthesis);