forked from qt-creator/qt-creator
TextEditor: move snippet overlay into own cpp file
Change-Id: I3343d9abf19e4edc7bd88077bf8fe6666a901e1b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "texteditoroverlay.h"
|
||||
#include "texteditor.h"
|
||||
#include "snippets/snippet.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
@@ -485,80 +484,3 @@ bool TextEditorOverlay::hasFirstSelectionBeginMoved() const
|
||||
return false;
|
||||
return m_selections.at(0).m_cursor_begin.position() != m_firstSelectionOriginalBegin;
|
||||
}
|
||||
|
||||
void SnippetOverlay::clear()
|
||||
{
|
||||
TextEditorOverlay::clear();
|
||||
m_equivalentSelections.clear();
|
||||
m_manglers.clear();
|
||||
}
|
||||
|
||||
void SnippetOverlay::mapEquivalentSelections()
|
||||
{
|
||||
m_equivalentSelections.clear();
|
||||
m_equivalentSelections.resize(selections().size());
|
||||
|
||||
QMultiMap<QString, int> all;
|
||||
for (int i = 0; i < selections().size(); ++i)
|
||||
all.insert(selectionText(i).toLower(), i);
|
||||
|
||||
const QList<QString> &uniqueKeys = all.uniqueKeys();
|
||||
foreach (const QString &key, uniqueKeys) {
|
||||
QList<int> indexes;
|
||||
const auto cAll = all;
|
||||
QMultiMap<QString, int>::const_iterator lbit = cAll.lowerBound(key);
|
||||
QMultiMap<QString, int>::const_iterator ubit = cAll.upperBound(key);
|
||||
while (lbit != ubit) {
|
||||
indexes.append(lbit.value());
|
||||
++lbit;
|
||||
}
|
||||
|
||||
foreach (int index, indexes)
|
||||
m_equivalentSelections[index] = indexes;
|
||||
}
|
||||
}
|
||||
|
||||
void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
|
||||
{
|
||||
int selectionIndex = selectionIndexForCursor(cursor);
|
||||
if (selectionIndex == -1)
|
||||
return;
|
||||
|
||||
const QString ¤tText = selectionText(selectionIndex);
|
||||
const QList<int> &equivalents = m_equivalentSelections.at(selectionIndex);
|
||||
foreach (int i, equivalents) {
|
||||
if (i == selectionIndex)
|
||||
continue;
|
||||
const QString &equivalentText = selectionText(i);
|
||||
if (currentText != equivalentText) {
|
||||
QTextCursor selectionCursor = assembleCursorForSelection(i);
|
||||
selectionCursor.joinPreviousEditBlock();
|
||||
selectionCursor.removeSelectedText();
|
||||
selectionCursor.insertText(currentText);
|
||||
selectionCursor.endEditBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SnippetOverlay::setNameMangler(const QList<NameMangler *> &manglers)
|
||||
{
|
||||
m_manglers = manglers;
|
||||
}
|
||||
|
||||
void SnippetOverlay::mangle()
|
||||
{
|
||||
for (int i = 0; i < m_manglers.count(); ++i) {
|
||||
if (!m_manglers.at(i))
|
||||
continue;
|
||||
|
||||
const QString current = selectionText(i);
|
||||
const QString result = m_manglers.at(i)->mangle(current);
|
||||
if (result != current) {
|
||||
QTextCursor selectionCursor = assembleCursorForSelection(i);
|
||||
selectionCursor.joinPreviousEditBlock();
|
||||
selectionCursor.removeSelectedText();
|
||||
selectionCursor.insertText(result);
|
||||
selectionCursor.endEditBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user