From 7ccdbc5e978f3ec22e4c982c13e863ea8e1d6647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Aum=C3=BCller?= <aumuell@reserv.at> Date: Tue, 5 Jan 2010 18:42:26 +0100 Subject: [PATCH] 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> --- src/plugins/fakevim/fakevimhandler.cpp | 3 ++- src/plugins/fakevim/fakevimplugin.cpp | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 5527cdb8bc7..efcb6d1ab54 100755 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -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(); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 87200860d59..8926bca6ed0 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -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() -- GitLab