forked from qt-creator/qt-creator
fakevim: implement '&'
Change-Id: I64f214d27306733a2840036816366d7a204cbc89 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -1030,6 +1030,9 @@ public:
|
||||
QList<QTextEdit::ExtraSelection> m_searchSelections;
|
||||
QTextCursor m_searchCursor;
|
||||
QString m_oldNeedle;
|
||||
QString m_lastSubstituteFlags;
|
||||
QRegExp m_lastSubstitutePattern;
|
||||
QString m_lastSubstituteReplacement;
|
||||
|
||||
bool handleExCommandHelper(const ExCommand &cmd); // Returns success.
|
||||
bool handleExPluginCommand(const ExCommand &cmd); // Handled by plugin?
|
||||
@@ -2062,6 +2065,8 @@ EventResult FakeVimHandler::Private::handleCommandMode1(const Input &input)
|
||||
handleFfTt(m_semicolonKey);
|
||||
m_subsubmode = NoSubSubMode;
|
||||
finishMovement();
|
||||
} else if (input.is('&')) {
|
||||
handleExCommand(m_gflag ? "%s//~/&" : "s");
|
||||
} else if (input.is(':')) {
|
||||
enterExMode();
|
||||
g.commandHistory.restart();
|
||||
@@ -3267,6 +3272,33 @@ void FakeVimHandler::Private::handleCommand(const QString &cmd)
|
||||
bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
|
||||
// :substitute
|
||||
{
|
||||
QString flags;
|
||||
QRegExp pattern;
|
||||
QString replacement;
|
||||
int count = 0;
|
||||
|
||||
if (cmd.cmd.startsWith("&&")) {
|
||||
flags = cmd.cmd.mid(2);
|
||||
if (flags.isEmpty())
|
||||
flags = m_lastSubstituteFlags;
|
||||
pattern = m_lastSubstitutePattern;
|
||||
replacement = m_lastSubstituteReplacement;
|
||||
count = cmd.args.section(QLatin1Char(' '), 1, 1).toInt();
|
||||
} else if (cmd.cmd.startsWith("&")) {
|
||||
flags = cmd.cmd.mid(1);
|
||||
if (flags.isEmpty())
|
||||
flags = m_lastSubstituteFlags;
|
||||
pattern = m_lastSubstitutePattern;
|
||||
replacement = m_lastSubstituteReplacement;
|
||||
count = cmd.args.section(QLatin1Char(' '), 1, 1).toInt();
|
||||
} else if (cmd.matches("s", "substitute")) {
|
||||
flags = m_lastSubstituteFlags;
|
||||
if (flags.isEmpty())
|
||||
flags = m_lastSubstituteFlags;
|
||||
pattern = m_lastSubstitutePattern;
|
||||
replacement = m_lastSubstituteReplacement;
|
||||
count = cmd.args.section(QLatin1Char(' '), 2, 2).toInt();
|
||||
} else {
|
||||
QString line = cmd.cmd + ' ' + cmd.args;
|
||||
line = line.trimmed();
|
||||
if (line.startsWith(_("substitute")))
|
||||
@@ -3276,7 +3308,6 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
|
||||
line = line.mid(1);
|
||||
else
|
||||
return false;
|
||||
|
||||
// we have /{pattern}/{string}/[flags] now
|
||||
if (line.isEmpty())
|
||||
return false;
|
||||
@@ -3302,19 +3333,30 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
|
||||
pos2 = line.size();
|
||||
|
||||
QString needle = line.mid(1, pos1 - 1);
|
||||
const QString replacement = line.mid(pos1 + 1, pos2 - pos1 - 1);
|
||||
QString flags = line.mid(pos2 + 1);
|
||||
replacement = line.mid(pos1 + 1, pos2 - pos1 - 1);
|
||||
flags = line.mid(pos2 + 1);
|
||||
|
||||
needle.replace('$', '\n');
|
||||
needle.replace("\\\n", "\\$");
|
||||
QRegExp pattern(needle);
|
||||
pattern.setPattern(needle);
|
||||
|
||||
m_lastSubstituteFlags = flags;
|
||||
m_lastSubstitutePattern = pattern;
|
||||
m_lastSubstituteReplacement = replacement;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
count = 1;
|
||||
|
||||
if (flags.contains('i'))
|
||||
pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
beginEditBlock();
|
||||
const bool global = flags.contains('g');
|
||||
for (int a = 0; a != count; ++a) {
|
||||
const Range range = cmd.range.endPos == 0 ? rangeFromCurrentLine() : cmd.range;
|
||||
const int beginLine = lineForPosition(range.beginPos);
|
||||
const int endLine = lineForPosition(range.endPos);
|
||||
beginEditBlock();
|
||||
for (int line = endLine; line >= beginLine; --line) {
|
||||
QString origText = lineContents(line);
|
||||
QString text = origText;
|
||||
@@ -3345,6 +3387,9 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
|
||||
if (text != origText)
|
||||
setLineContents(line, text);
|
||||
}
|
||||
}
|
||||
moveToStartOfLine();
|
||||
setTargetColumn();
|
||||
endEditBlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user