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