forked from qt-creator/qt-creator
Snippets: Allow lowercase/titlecase/uppercase modifiers for variables
Use the same syntax already used in the custom wizard to denote variables that are modified to be lower-/title-/uppercase: $tESt:u$ will become TEST $tESt:c$ will become TESt $tESt:l$ will become test The snippet will be inserted without any name mangling happening. Once the editing is done the name mangling is applied to all fields. Change-Id: I7c1f5a1ad2bb5acf1b88b54de51bb39391c64763 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "texteditoroverlay.h"
|
||||
#include "basetexteditor.h"
|
||||
#include "snippets/snippet.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
@@ -72,6 +73,8 @@ void TextEditorOverlay::clear()
|
||||
return;
|
||||
m_selections.clear();
|
||||
m_firstSelectionOriginalBegin = -1;
|
||||
m_equivalentSelections.clear();
|
||||
m_manglers.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -490,7 +493,7 @@ void TextEditorOverlay::mapEquivalentSelections()
|
||||
|
||||
QMap<QString, int> all;
|
||||
for (int i = 0; i < m_selections.size(); ++i)
|
||||
all.insertMulti(selectionText(i), i);
|
||||
all.insertMulti(selectionText(i).toLower(), i);
|
||||
|
||||
const QList<QString> &uniqueKeys = all.uniqueKeys();
|
||||
foreach (const QString &key, uniqueKeys) {
|
||||
@@ -529,6 +532,29 @@ void TextEditorOverlay::updateEquivalentSelections(const QTextCursor &cursor)
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorOverlay::setNameMangler(const QList<NameMangler *> &manglers)
|
||||
{
|
||||
m_manglers = manglers;
|
||||
}
|
||||
|
||||
void TextEditorOverlay::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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TextEditorOverlay::hasFirstSelectionBeginMoved() const
|
||||
{
|
||||
if (m_firstSelectionOriginalBegin == -1 || m_selections.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user