summaryrefslogtreecommitdiff
path: root/src/plugins/fakevim
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2018-03-12 14:13:07 +0100
committerhjk <hjk@qt.io>2018-03-13 06:48:42 +0000
commitae560fcc493f3be3aa4783bc2354104b433bb3ac (patch)
treef947d2bd0a747364d0da18219a87dc00a980b6a1 /src/plugins/fakevim
parent0bc100911d16730aeb3ac1e6a552412fb2047e62 (diff)
downloadqt-creator-ae560fcc493f3be3aa4783bc2354104b433bb3ac.tar.gz
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>
Diffstat (limited to 'src/plugins/fakevim')
-rw-r--r--src/plugins/fakevim/fakevimhandler.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 45139a5bfd..66ee7fc7b4 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -2139,6 +2139,7 @@ public:
bool handleExReadCommand(const ExCommand &cmd);
bool handleExUndoRedoCommand(const ExCommand &cmd);
bool handleExSetCommand(const ExCommand &cmd);
+ bool handleExSortCommand(const ExCommand &cmd);
bool handleExShiftCommand(const ExCommand &cmd);
bool handleExSourceCommand(const ExCommand &cmd);
bool handleExSubstituteCommand(const ExCommand &cmd);
@@ -6077,6 +6078,39 @@ bool FakeVimHandler::Private::handleExShiftCommand(const ExCommand &cmd)
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)
{
// :noh, :nohl, ..., :nohlsearch
@@ -6230,6 +6264,7 @@ bool FakeVimHandler::Private::handleExCommandHelper(ExCommand &cmd)
|| handleExUndoRedoCommand(cmd)
|| handleExSetCommand(cmd)
|| handleExShiftCommand(cmd)
+ || handleExSortCommand(cmd)
|| handleExSourceCommand(cmd)
|| handleExSubstituteCommand(cmd)
|| handleExTabNextCommand(cmd)