From 9302104cbdfb405b415e9c410ec1326515e6725e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Aum=C3=BCller?= <aumuell@reserv.at> Date: Thu, 21 Jan 2010 17:38:29 +0100 Subject: [PATCH] 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> --- src/plugins/fakevim/fakevimhandler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index c150b3b18d3..39697b68fe8 100755 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -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) -- GitLab