Commit 9d2f1f67 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

fakevim: Commands 'zj' and 'zk' to move [count] folds down and up



It's possible to do '2dzj' to delete everything up to beginning of
second unfolded block or whole folded block.

Change-Id: I080c9ec4d12471faf09cabea3c96b448b5fc7f4d
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 1b1c008a
......@@ -188,6 +188,7 @@ enum SubSubMode
BackTickSubSubMode, // Used for `.
TickSubSubMode, // Used for '.
TextObjectSubSubMode, // Used for thing like iw, aW, as etc.
ZSubSubMode, // Used for zj, zk
SearchSubSubMode
};
......@@ -2925,6 +2926,18 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
handled = false;
}
m_subsubmode = NoSubSubMode;
} else if (m_subsubmode == ZSubSubMode) {
handled = false;
if (input.is('j') || input.is('k')) {
int pos = position();
emit q->foldGoTo(input.is('j') ? count() : -count());
if (pos != position()) {
handled = true;
finishMovement(QString("%1z%2")
.arg(count())
.arg(input.text()));
}
}
} else {
handled = false;
}
......@@ -3220,6 +3233,9 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_movetype = MoveExclusive;
}
setTargetColumn();
} else if (input.is('z')) {
m_movetype = MoveLineWise;
m_subsubmode = ZSubSubMode;
} else if (input.is('[')) {
m_submode = OpenSquareSubMode;
} else if (input.is(']')) {
......@@ -3936,27 +3952,24 @@ bool FakeVimHandler::Private::handleZSubMode(const Input &input)
const bool moveToNonBlank = (input.is('.') || input.isReturn() || input.is('-'));
const int line = m_mvcount.isEmpty() ? -1 : firstPositionInLine(count());
alignViewportToCursor(align, line, moveToNonBlank);
finishMovement();
} else if (input.is('o') || input.is('c')) {
// Open/close current fold.
foldMaybeClosed = input.is('c');
emit q->fold(count(), foldMaybeClosed);
finishMovement();
} else if (input.is('O') || input.is('C')) {
// Recursively open/close current fold.
foldMaybeClosed = input.is('C');
emit q->fold(-1, foldMaybeClosed);
finishMovement();
} else if (input.is('a') || input.is('A')) {
// Toggle current fold.
foldMaybeClosed = true;
emit q->foldToggle(input.is('a') ? count() : -1);
finishMovement();
} else if (input.is('R') || input.is('M')) {
// Open/close all folds in document.
foldMaybeClosed = input.is('M');
emit q->foldAll(foldMaybeClosed);
finishMovement();
} else if (input.is('j') || input.is('k')) {
emit q->foldGoTo(input.is('j') ? count() : -count());
} else {
handled = false;
}
......
......@@ -150,6 +150,7 @@ signals:
void foldToggle(int depth);
void foldAll(bool fold);
void fold(int depth, bool fold);
void foldGoTo(int count);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
public:
......
......@@ -855,6 +855,7 @@ private slots:
void foldToggle(int depth);
void foldAll(bool fold);
void fold(int depth, bool fold);
void foldGoTo(int count);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
void showSettingsDialog();
void maybeReadVimRc();
......@@ -1451,6 +1452,56 @@ void FakeVimPluginPrivate::fold(int depth, bool fold)
documentLayout->emitDocumentSizeChanged();
}
void FakeVimPluginPrivate::foldGoTo(int count)
{
IEditor *ieditor = EditorManager::currentEditor();
BaseTextEditorWidget *editor = qobject_cast<BaseTextEditorWidget *>(ieditor->widget());
QTC_ASSERT(editor != 0, return);
QTextCursor tc = editor->textCursor();
QTextBlock block = tc.block();
int pos = -1;
if (count > 0) {
int repeat = count;
QTextBlock prevBlock = block;
block = block.next();
int indent = BaseTextDocumentLayout::foldingIndent(block);
while (block.isValid()) {
int newIndent = BaseTextDocumentLayout::foldingIndent(block);
if (prevBlock.isVisible() && indent < newIndent) {
pos = prevBlock.position();
if (--repeat <= 0)
break;
}
indent = newIndent;
prevBlock = block;
block = block.next();
}
} else if (count < 0) {
int repeat = -count;
int indent = BaseTextDocumentLayout::foldingIndent(block);
block = block.previous();
while (block.isValid()) {
int newIndent = BaseTextDocumentLayout::foldingIndent(block);
if (indent < newIndent) {
while (block.isValid() && !block.isVisible())
block = block.previous();
pos = block.position();
if (--repeat <= 0)
break;
}
indent = newIndent;
block = block.previous();
}
}
if (pos != -1) {
tc.setPosition(pos, QTextCursor::KeepAnchor);
editor->setTextCursor(tc);
}
}
void FakeVimPluginPrivate::jumpToGlobalMark(QChar mark, bool backTickMode,
const QString &fileName)
{
......@@ -1540,6 +1591,8 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
SLOT(foldAll(bool)));
connect(handler, SIGNAL(fold(int,bool)),
SLOT(fold(int,bool)));
connect(handler, SIGNAL(foldGoTo(int)),
SLOT(foldGoTo(int)));
connect(handler, SIGNAL(jumpToGlobalMark(QChar,bool,QString)),
SLOT(jumpToGlobalMark(QChar,bool,QString)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment