summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/snippets/snippetoverlay.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2021-05-21 13:17:14 +0200
committerDavid Schulz <david.schulz@qt.io>2021-05-28 10:39:35 +0000
commitfcd93256c0696c7d58308d3306784bca1394c73e (patch)
treeb8050796d9ee75c564d54c1a8360224151805f1b /src/plugins/texteditor/snippets/snippetoverlay.cpp
parent2ccf5e2795df1b10a958c5413b82140568da67fb (diff)
downloadqt-creator-fcd93256c0696c7d58308d3306784bca1394c73e.tar.gz
Snippets: Allow defining a final snippet tabstop
Change-Id: I8b9704f66c9f0ac33dfb9d8f5e970a85bbcf143e Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/texteditor/snippets/snippetoverlay.cpp')
-rw-r--r--src/plugins/texteditor/snippets/snippetoverlay.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/plugins/texteditor/snippets/snippetoverlay.cpp b/src/plugins/texteditor/snippets/snippetoverlay.cpp
index 182813c556..b773acfee1 100644
--- a/src/plugins/texteditor/snippets/snippetoverlay.cpp
+++ b/src/plugins/texteditor/snippets/snippetoverlay.cpp
@@ -51,6 +51,12 @@ void SnippetOverlay::addSnippetSelection(const QTextCursor &cursor,
addOverlaySelection(cursor, color, color, TextEditorOverlay::ExpandBegin);
}
+void SnippetOverlay::setFinalSelection(const QTextCursor &cursor, const QColor &color)
+{
+ m_finalSelectionIndex = selections().size();
+ addOverlaySelection(cursor, color, color, TextEditorOverlay::ExpandBegin);
+}
+
void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
{
const int &currentIndex = indexForCursor(cursor);
@@ -92,6 +98,12 @@ bool SnippetOverlay::hasCursorInSelection(const QTextCursor &cursor) const
return indexForCursor(cursor) >= 0;
}
+QTextCursor SnippetOverlay::firstSelectionCursor() const
+{
+ const QList<OverlaySelection> selections = TextEditorOverlay::selections();
+ return selections.isEmpty() ? QTextCursor() : cursorForSelection(selections.first());
+}
+
QTextCursor SnippetOverlay::nextSelectionCursor(const QTextCursor &cursor) const
{
const QList<OverlaySelection> selections = TextEditorOverlay::selections();
@@ -100,8 +112,11 @@ QTextCursor SnippetOverlay::nextSelectionCursor(const QTextCursor &cursor) const
const SnippetSelection &currentSelection = selectionForCursor(cursor);
if (currentSelection.variableIndex >= 0) {
int nextVariableIndex = currentSelection.variableIndex + 1;
- if (nextVariableIndex >= m_variables.size())
+ if (nextVariableIndex >= m_variables.size()) {
+ if (m_finalSelectionIndex >= 0)
+ return cursorForIndex(m_finalSelectionIndex);
nextVariableIndex = 0;
+ }
for (int selectionIndex : m_variables[nextVariableIndex]) {
if (selections[selectionIndex].m_cursor_begin.position() > cursor.position())
@@ -143,6 +158,11 @@ QTextCursor SnippetOverlay::previousSelectionCursor(const QTextCursor &cursor) c
return cursorForSelection(selections.last());
}
+bool SnippetOverlay::isFinalSelection(const QTextCursor &cursor) const
+{
+ return m_finalSelectionIndex >= 0 ? cursor == cursorForIndex(m_finalSelectionIndex) : false;
+}
+
int SnippetOverlay::indexForCursor(const QTextCursor &cursor) const
{
return Utils::indexOf(selections(),