Commit 7ccdbc5e authored by Martin Aumüller's avatar Martin Aumüller Committed by hjk
Browse files

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: default avatarhjk <qtc-committer@nokia.com>
parent a088b017
......@@ -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();
......
......@@ -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()
......
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