fakevim: make line counting more vi-like

- apparently one additional empty line is added to the document at its end,
  if the last line ends with \n

Merge-request: 99
Reviewed-by: hjk <qtc-committer@nokia.com>
This commit is contained in:
Martin Aumüller
2010-01-21 17:38:29 +01:00
committed by hjk
parent 07f6d29937
commit 9302104cbd

View File

@@ -2817,7 +2817,12 @@ int FakeVimHandler::Private::cursorColumnInDocument() const
int FakeVimHandler::Private::linesInDocument() const
{
return m_tc.isNull() ? 0 : m_tc.document()->blockCount();
if (m_tc.isNull())
return 0;
const QTextDocument *doc = m_tc.document();
const int count = doc->blockCount();
// Qt inserts an empty line if the last character is a '\n', but that's not how vi does it
return doc->lastBlock().length()<=1 ? count-1 : count;
}
void FakeVimHandler::Private::scrollToLineInDocument(int line)