forked from qt-creator/qt-creator
fakevim: fix indenting
- the indented region has been off by one line as lineForPosition returns 1-based line numbers but QTextDocument::findBlockByNumber expects base 0 - all lines (including first and last line) have to be indented - if text is collapsed, then findBlockByNumber has to be used instead of findBlockByLineNumber for getting the block containing a line Merge-request: 96 Reviewed-by: hjk <qtc-committer@nokia.com>
This commit is contained in:
@@ -2418,7 +2418,8 @@ void FakeVimHandler::Private::indentRegion(QChar typedChar)
|
|||||||
qSwap(beginLine, endLine);
|
qSwap(beginLine, endLine);
|
||||||
|
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
emit q->indentRegion(&amount, beginLine, endLine, typedChar);
|
// lineForPosition has returned 1-based line numbers
|
||||||
|
emit q->indentRegion(&amount, beginLine-1, endLine-1, typedChar);
|
||||||
|
|
||||||
setPosition(firstPositionInLine(beginLine));
|
setPosition(firstPositionInLine(beginLine));
|
||||||
moveToFirstNonBlankOnLine();
|
moveToFirstNonBlankOnLine();
|
||||||
|
@@ -634,28 +634,24 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine,
|
|||||||
indenter.setTabSize(tabSettings.m_tabSize);
|
indenter.setTabSize(tabSettings.m_tabSize);
|
||||||
|
|
||||||
const QTextDocument *doc = bt->document();
|
const QTextDocument *doc = bt->document();
|
||||||
QTextBlock begin = doc->findBlockByNumber(beginLine);
|
|
||||||
QTextBlock end = doc->findBlockByNumber(endLine);
|
|
||||||
const TextEditor::TextBlockIterator docStart(doc->begin());
|
const TextEditor::TextBlockIterator docStart(doc->begin());
|
||||||
QTextBlock cur = begin;
|
QTextBlock cur = doc->findBlockByNumber(beginLine);
|
||||||
do {
|
for(int i = beginLine; i<= endLine; ++i)
|
||||||
|
{
|
||||||
if (typedChar == 0 && cur.text().simplified().isEmpty()) {
|
if (typedChar == 0 && cur.text().simplified().isEmpty()) {
|
||||||
|
// clear empty lines
|
||||||
*amount = 0;
|
*amount = 0;
|
||||||
if (cur != end) {
|
|
||||||
QTextCursor cursor(cur);
|
QTextCursor cursor(cur);
|
||||||
while (!cursor.atBlockEnd())
|
while (!cursor.atBlockEnd())
|
||||||
cursor.deleteChar();
|
cursor.deleteChar();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const TextEditor::TextBlockIterator current(cur);
|
const TextEditor::TextBlockIterator current(cur);
|
||||||
const TextEditor::TextBlockIterator next(cur.next());
|
const TextEditor::TextBlockIterator next(cur.next());
|
||||||
*amount = indenter.indentForBottomLine(current, docStart, next, typedChar);
|
*amount = indenter.indentForBottomLine(current, docStart, next, typedChar);
|
||||||
if (cur != end)
|
|
||||||
tabSettings.indentLine(cur, *amount);
|
tabSettings.indentLine(cur, *amount);
|
||||||
}
|
}
|
||||||
if (cur != end)
|
|
||||||
cur = cur.next();
|
cur = cur.next();
|
||||||
} while (cur != end);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::quitFakeVim()
|
void FakeVimPluginPrivate::quitFakeVim()
|
||||||
|
Reference in New Issue
Block a user