From 416a1805b3ede28db36ea9889e67d7593d1f51c4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 22 Feb 2012 22:02:43 +0000 Subject: [PATCH] Fix last line handling in buffer --- src/buffer.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 409ee4e0..8f22d1f4 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -121,7 +121,10 @@ BufferSize Buffer::length() const BufferSize Buffer::line_count() const { - return m_lines.size(); + if (m_lines.back() == m_content.size()) + return m_lines.size() - 1; + else + return m_lines.size(); } BufferString Buffer::string(const BufferIterator& begin, const BufferIterator& end) const @@ -191,7 +194,7 @@ void Buffer::compute_lines() { m_lines.clear(); m_lines.push_back(0); - for (BufferPos i = 0; i + 1 < m_content.size(); ++i) + for (BufferPos i = 0; i < m_content.size(); ++i) { if (m_content[i] == '\n') m_lines.push_back(i + 1);