summaryrefslogtreecommitdiff
path: root/src/commands.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-04-23 20:15:17 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-04-23 20:15:17 +0100
commitd6b69cb6f7818d5fb9d01007828a385eaf1308dc (patch)
treecb77cfbfa08cb09adc75cb66b92d82398437b5a2 /src/commands.cc
parent80fb8aa60d20720b2f5322dd3f29d8215bfec8e4 (diff)
Fix :open bug that could set a deleted buffer as the last used one
Diffstat (limited to 'src/commands.cc')
-rw-r--r--src/commands.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 7f515172..2b5f75da 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -132,16 +132,22 @@ void edit(const ParametersParser& parser, Context& context)
auto& name = parser.positional_count() > 0 ? parser[0]
: context.buffer().name();
+ auto& buffer_manager = BufferManager::instance();
Buffer* buffer = nullptr;
Buffer* oldbuf = &context.buffer();
if (not force_reload)
- buffer = BufferManager::instance().get_buffer_ifp(name);
+ buffer = buffer_manager.get_buffer_ifp(name);
if (not buffer)
{
if (parser.get_switch("scratch"))
{
- BufferManager::instance().delete_buffer_if_exists(name);
+ if (Buffer* buf = buffer_manager.get_buffer_ifp(name))
+ {
+ buffer_manager.delete_buffer(*buf);
+ if (buf == oldbuf)
+ oldbuf = nullptr;
+ }
buffer = new Buffer(name, Buffer::Flags::None);
}
else if (auto fifo = parser.get_switch("fifo"))
@@ -160,7 +166,8 @@ void edit(const ParametersParser& parser, Context& context)
}
}
- BufferManager::instance().set_last_used_buffer(*oldbuf);
+ if (oldbuf)
+ buffer_manager.set_last_used_buffer(*oldbuf);
const size_t param_count = parser.positional_count();
if (buffer != &context.buffer() or param_count > 1)