From bf213b01dda1425d1d7e20179dea155b52dbcf5e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 19 Nov 2015 21:33:50 +0000 Subject: [PATCH] Keep an empty last line in debug buffer to provide auto scrolling --- src/buffer_utils.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index 7cc05289..9dd16abe 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -168,11 +168,14 @@ void write_to_debug_buffer(StringView str) } constexpr StringView debug_buffer_name = "*debug*"; + // Try to ensure we keep an empty line at the end of the debug buffer + // where the user can put its cursor to scroll with new messages + const bool eol_back = not str.empty() and str.back() == '\n'; if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name)) - buffer->insert(buffer->end(), str); + buffer->insert(buffer->end()-1, eol_back ? str : str + "\n"); else { - String line = str + ((str.empty() or str.back() != '\n') ? "\n" : ""); + String line = str + (eol_back ? "\n" : "\n\n"); new Buffer(debug_buffer_name.str(), Buffer::Flags::NoUndo, line, InvalidTime); } }