forked from qt-creator/qt-creator
FakeVim: Implement :<range>sor[t][!]
None of the other options yet. Change-Id: Iabf18c1be4d228c97d2de9cb17e71c307e9ec5a2 Task-number: QTCREATORBUG-20022 Reviewed-by: Lukas Holecek <hluk@email.cz> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -2139,6 +2139,7 @@ public:
|
|||||||
bool handleExReadCommand(const ExCommand &cmd);
|
bool handleExReadCommand(const ExCommand &cmd);
|
||||||
bool handleExUndoRedoCommand(const ExCommand &cmd);
|
bool handleExUndoRedoCommand(const ExCommand &cmd);
|
||||||
bool handleExSetCommand(const ExCommand &cmd);
|
bool handleExSetCommand(const ExCommand &cmd);
|
||||||
|
bool handleExSortCommand(const ExCommand &cmd);
|
||||||
bool handleExShiftCommand(const ExCommand &cmd);
|
bool handleExShiftCommand(const ExCommand &cmd);
|
||||||
bool handleExSourceCommand(const ExCommand &cmd);
|
bool handleExSourceCommand(const ExCommand &cmd);
|
||||||
bool handleExSubstituteCommand(const ExCommand &cmd);
|
bool handleExSubstituteCommand(const ExCommand &cmd);
|
||||||
@@ -6077,6 +6078,39 @@ bool FakeVimHandler::Private::handleExShiftCommand(const ExCommand &cmd)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FakeVimHandler::Private::handleExSortCommand(const ExCommand &cmd)
|
||||||
|
{
|
||||||
|
// :[range]sor[t][!] [b][f][i][n][o][r][u][x] [/{pattern}/]
|
||||||
|
// FIXME: Only the ! for reverse is implemented.
|
||||||
|
if (!cmd.matches("sor", "sort"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Force operation on full lines, and full document if only
|
||||||
|
// one line (the current one...) is specified
|
||||||
|
int beginLine = lineForPosition(cmd.range.beginPos);
|
||||||
|
int endLine = lineForPosition(cmd.range.endPos);
|
||||||
|
if (beginLine == endLine) {
|
||||||
|
beginLine = 0;
|
||||||
|
endLine = lineForPosition(lastPositionInDocument());
|
||||||
|
}
|
||||||
|
Range range(firstPositionInLine(beginLine),
|
||||||
|
firstPositionInLine(endLine), RangeLineMode);
|
||||||
|
|
||||||
|
QString input = selectText(range);
|
||||||
|
if (input.endsWith('\n')) // It should always...
|
||||||
|
input.chop(1);
|
||||||
|
|
||||||
|
QStringList lines = input.split('\n');
|
||||||
|
lines.sort();
|
||||||
|
if (cmd.hasBang)
|
||||||
|
std::reverse(lines.begin(), lines.end());
|
||||||
|
QString res = lines.join('\n') + '\n';
|
||||||
|
|
||||||
|
replaceText(range, res);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FakeVimHandler::Private::handleExNohlsearchCommand(const ExCommand &cmd)
|
bool FakeVimHandler::Private::handleExNohlsearchCommand(const ExCommand &cmd)
|
||||||
{
|
{
|
||||||
// :noh, :nohl, ..., :nohlsearch
|
// :noh, :nohl, ..., :nohlsearch
|
||||||
@@ -6230,6 +6264,7 @@ bool FakeVimHandler::Private::handleExCommandHelper(ExCommand &cmd)
|
|||||||
|| handleExUndoRedoCommand(cmd)
|
|| handleExUndoRedoCommand(cmd)
|
||||||
|| handleExSetCommand(cmd)
|
|| handleExSetCommand(cmd)
|
||||||
|| handleExShiftCommand(cmd)
|
|| handleExShiftCommand(cmd)
|
||||||
|
|| handleExSortCommand(cmd)
|
||||||
|| handleExSourceCommand(cmd)
|
|| handleExSourceCommand(cmd)
|
||||||
|| handleExSubstituteCommand(cmd)
|
|| handleExSubstituteCommand(cmd)
|
||||||
|| handleExTabNextCommand(cmd)
|
|| handleExTabNextCommand(cmd)
|
||||||
|
Reference in New Issue
Block a user