From bdd0758ee2993e4a3be34027a2f23e75d984fd9b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 7 Nov 2012 14:04:47 +0100 Subject: [PATCH] Saner :edit and :buffer behaviour when buffer is the current one --- src/commands.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 98b14123..55fcf2ff 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -282,7 +282,12 @@ void edit(const CommandParameters& params, Context& context) } BufferManager::instance().set_last_used_buffer(*buffer); - Window& window = ClientManager::instance().get_unused_window_for_buffer(*buffer); + + if (buffer != &context.buffer()) + { + auto& manager = ClientManager::instance(); + context.change_editor(manager.get_unused_window_for_buffer(*buffer)); + } if (param_count > 1) { @@ -290,11 +295,10 @@ void edit(const CommandParameters& params, Context& context) int column = param_count > 2 ? std::max(0, str_to_int(parser[2]) - 1) : 0; - window.select(window.buffer().iterator_at({ line, column })); - window.center_selection(); + context.editor().select(context.buffer().iterator_at({ line, column })); + if (context.has_window()) + context.window().center_selection(); } - - context.change_editor(window); } void write_buffer(const CommandParameters& params, Context& context) @@ -378,8 +382,12 @@ void show_buffer(const CommandParameters& params, Context& context) throw runtime_error("buffer " + buffer_name + " does not exists"); BufferManager::instance().set_last_used_buffer(*buffer); - Window& window = ClientManager::instance().get_unused_window_for_buffer(*buffer); - context.change_editor(window); + + if (buffer != &context.buffer()) + { + auto& manager = ClientManager::instance(); + context.change_editor(manager.get_unused_window_for_buffer(*buffer)); + } } void delete_buffer(const CommandParameters& params, Context& context)