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:
Martin Aumüller
2010-01-05 18:42:26 +01:00
committed by hjk
parent a088b01713
commit 7ccdbc5e97
2 changed files with 12 additions and 15 deletions

View File

@@ -2418,7 +2418,8 @@ void FakeVimHandler::Private::indentRegion(QChar typedChar)
qSwap(beginLine, endLine);
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));
moveToFirstNonBlankOnLine();

View File

@@ -634,28 +634,24 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine,
indenter.setTabSize(tabSettings.m_tabSize);
const QTextDocument *doc = bt->document();
QTextBlock begin = doc->findBlockByNumber(beginLine);
QTextBlock end = doc->findBlockByNumber(endLine);
const TextEditor::TextBlockIterator docStart(doc->begin());
QTextBlock cur = begin;
do {
QTextBlock cur = doc->findBlockByNumber(beginLine);
for(int i = beginLine; i<= endLine; ++i)
{
if (typedChar == 0 && cur.text().simplified().isEmpty()) {
// clear empty lines
*amount = 0;
if (cur != end) {
QTextCursor cursor(cur);
while (!cursor.atBlockEnd())
cursor.deleteChar();
}
QTextCursor cursor(cur);
while (!cursor.atBlockEnd())
cursor.deleteChar();
} else {
const TextEditor::TextBlockIterator current(cur);
const TextEditor::TextBlockIterator next(cur.next());
*amount = indenter.indentForBottomLine(current, docStart, next, typedChar);
if (cur != end)
tabSettings.indentLine(cur, *amount);
tabSettings.indentLine(cur, *amount);
}
if (cur != end)
cur = cur.next();
} while (cur != end);
cur = cur.next();
}
}
void FakeVimPluginPrivate::quitFakeVim()