Commit 61c3de01 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

fakevim: Commands '[z' and ']z' to move to top or bottom of fold



Commands '[z' and ']z' to move [count] times to top or bottom of current
folds.

Change-Id: Ia087e47bd5f9d63a2b9a4b2ffd3fc57559dfba6b
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 9d2f1f67
......@@ -172,9 +172,7 @@ enum SubMode
YankSubMode, // Used for y
ZSubMode, // Used for z
CapitalZSubMode, // Used for Z
ReplaceSubMode, // Used for r
OpenSquareSubMode, // Used for [
CloseSquareSubMode // Used for ]
ReplaceSubMode // Used for r
};
/*! A \e SubSubMode is used for things that require one more data item
......@@ -183,12 +181,14 @@ enum SubMode
enum SubSubMode
{
NoSubSubMode,
FtSubSubMode, // Used for f, F, t, T.
MarkSubSubMode, // Used for m.
BackTickSubSubMode, // Used for `.
TickSubSubMode, // Used for '.
TextObjectSubSubMode, // Used for thing like iw, aW, as etc.
ZSubSubMode, // Used for zj, zk
FtSubSubMode, // Used for f, F, t, T.
MarkSubSubMode, // Used for m.
BackTickSubSubMode, // Used for `.
TickSubSubMode, // Used for '.
TextObjectSubSubMode, // Used for thing like iw, aW, as etc.
ZSubSubMode, // Used for zj, zk
OpenSquareSubSubMode, // Used for [{, {(, [z
CloseSquareSubSubMode, // Used for ]}, ]), ]z
SearchSubSubMode
};
......@@ -1368,8 +1368,6 @@ public:
bool handleYankSubMode(const Input &);
bool handleZSubMode(const Input &);
bool handleCapitalZSubMode(const Input &);
bool handleOpenSquareSubMode(const Input &);
bool handleCloseSquareSubMode(const Input &);
bool handleMovement(const Input &);
......@@ -2930,7 +2928,7 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
handled = false;
if (input.is('j') || input.is('k')) {
int pos = position();
emit q->foldGoTo(input.is('j') ? count() : -count());
emit q->foldGoTo(input.is('j') ? count() : -count(), false);
if (pos != position()) {
handled = true;
finishMovement(QString("%1z%2")
......@@ -2938,34 +2936,26 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
.arg(input.text()));
}
}
} else {
handled = false;
}
return handled;
}
bool FakeVimHandler::Private::handleOpenSquareSubMode(const Input &input)
{
bool handled = true;
m_submode = NoSubMode;
if (input.is('{')) {
searchBalanced(false, '{', '}');
} else if (input.is('(')) {
searchBalanced(false, '(', ')');
} else {
handled = false;
}
return handled;
}
bool FakeVimHandler::Private::handleCloseSquareSubMode(const Input &input)
{
bool handled = true;
m_submode = NoSubMode;
if (input.is('}')) {
searchBalanced(true, '}', '{');
} else if (input.is(')')) {
searchBalanced(true, ')', '(');
} else if (m_subsubmode == OpenSquareSubSubMode || CloseSquareSubSubMode) {
int pos = position();
if ((input.is('{') && m_subsubmode == OpenSquareSubSubMode)) {
searchBalanced(false, '{', '}');
} else if ((input.is('}') && m_subsubmode == CloseSquareSubSubMode)) {
searchBalanced(true, '}', '{');
} else if ((input.is('(') && m_subsubmode == OpenSquareSubSubMode)) {
searchBalanced(false, '(', ')');
} else if ((input.is(')') && m_subsubmode == CloseSquareSubSubMode)) {
searchBalanced(true, ')', '(');
} else if (input.is('z')) {
emit q->foldGoTo(m_subsubmode == OpenSquareSubSubMode ? -count() : count(), true);
}
handled = pos != position();
if (handled) {
finishMovement(QString("%1%2%3")
.arg(count())
.arg(m_subsubmode == OpenSquareSubSubMode ? '[' : ']')
.arg(input.text()));
}
} else {
handled = false;
}
......@@ -3237,9 +3227,9 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_movetype = MoveLineWise;
m_subsubmode = ZSubSubMode;
} else if (input.is('[')) {
m_submode = OpenSquareSubMode;
m_subsubmode = OpenSquareSubSubMode;
} else if (input.is(']')) {
m_submode = CloseSquareSubMode;
m_subsubmode = CloseSquareSubSubMode;
} else if (input.isKey(Key_PageDown) || input.isControl('f')) {
moveDown(count * (linesOnScreen() - 2) - cursorLineOnScreen());
scrollToLine(cursorLine());
......@@ -3304,10 +3294,6 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
handled = handleZSubMode(input);
} else if (m_submode == CapitalZSubMode) {
handled = handleCapitalZSubMode(input);
} else if (m_submode == OpenSquareSubMode) {
handled = handleOpenSquareSubMode(input);
} else if (m_submode == CloseSquareSubMode) {
handled = handleCloseSquareSubMode(input);
} else if (m_submode == ShiftLeftSubMode
|| m_submode == ShiftRightSubMode
|| m_submode == IndentSubMode) {
......@@ -3969,7 +3955,7 @@ bool FakeVimHandler::Private::handleZSubMode(const Input &input)
foldMaybeClosed = input.is('M');
emit q->foldAll(foldMaybeClosed);
} else if (input.is('j') || input.is('k')) {
emit q->foldGoTo(input.is('j') ? count() : -count());
emit q->foldGoTo(input.is('j') ? count() : -count(), false);
} else {
handled = false;
}
......
......@@ -150,7 +150,7 @@ signals:
void foldToggle(int depth);
void foldAll(bool fold);
void fold(int depth, bool fold);
void foldGoTo(int count);
void foldGoTo(int count, bool current);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
public:
......
......@@ -855,7 +855,7 @@ private slots:
void foldToggle(int depth);
void foldAll(bool fold);
void fold(int depth, bool fold);
void foldGoTo(int count);
void foldGoTo(int count, bool current);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
void showSettingsDialog();
void maybeReadVimRc();
......@@ -1452,7 +1452,7 @@ void FakeVimPluginPrivate::fold(int depth, bool fold)
documentLayout->emitDocumentSizeChanged();
}
void FakeVimPluginPrivate::foldGoTo(int count)
void FakeVimPluginPrivate::foldGoTo(int count, bool current)
{
IEditor *ieditor = EditorManager::currentEditor();
BaseTextEditorWidget *editor = qobject_cast<BaseTextEditorWidget *>(ieditor->widget());
......@@ -1464,17 +1464,23 @@ void FakeVimPluginPrivate::foldGoTo(int count)
int pos = -1;
if (count > 0) {
int repeat = count;
QTextBlock prevBlock = block;
block = block.next();
QTextBlock prevBlock = block;
int indent = BaseTextDocumentLayout::foldingIndent(block);
block = block.next();
while (block.isValid()) {
int newIndent = BaseTextDocumentLayout::foldingIndent(block);
if (prevBlock.isVisible() && indent < newIndent) {
pos = prevBlock.position();
if (--repeat <= 0)
break;
if (current ? indent > newIndent : indent < newIndent) {
if (prevBlock.isVisible()) {
pos = prevBlock.position();
if (--repeat <= 0)
break;
} else if (current) {
indent = newIndent;
}
}
indent = newIndent;
if (!current)
indent = newIndent;
prevBlock = block;
block = block.next();
}
......@@ -1484,14 +1490,15 @@ void FakeVimPluginPrivate::foldGoTo(int count)
block = block.previous();
while (block.isValid()) {
int newIndent = BaseTextDocumentLayout::foldingIndent(block);
if (indent < newIndent) {
if (current ? indent > newIndent : indent < newIndent) {
while (block.isValid() && !block.isVisible())
block = block.previous();
pos = block.position();
if (--repeat <= 0)
break;
}
indent = newIndent;
if (!current)
indent = newIndent;
block = block.previous();
}
}
......@@ -1591,8 +1598,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(foldGoTo(int, bool)),
SLOT(foldGoTo(int, bool)));
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