Change buffer order based on the last one used

This commit is contained in:
Maxime Coste 2012-09-28 14:14:49 +02:00
parent 79d8d082bd
commit f230feec7f
3 changed files with 13 additions and 0 deletions

View File

@ -52,6 +52,16 @@ Buffer* BufferManager::get_buffer(const String& name)
return nullptr;
}
void BufferManager::set_last_used_buffer(Buffer& buffer)
{
auto it = m_buffers.begin();
while (*it != &buffer and it != m_buffers.end())
++it;
assert(it != m_buffers.end());
m_buffers.erase(it);
m_buffers.emplace(m_buffers.begin(), &buffer);
}
CandidateList BufferManager::complete_buffername(const String& prefix,
CharCount cursor_pos)
{

View File

@ -27,6 +27,7 @@ public:
size_t count() const { return m_buffers.size(); }
Buffer* get_buffer(const String& name);
void set_last_used_buffer(Buffer& buffer);
CandidateList complete_buffername(const String& prefix,
CharCount cursor_pos = -1);

View File

@ -288,6 +288,7 @@ void edit(const CommandParameters& params, Context& context)
buffer = open_or_create(name, context);
}
BufferManager::instance().set_last_used_buffer(*buffer);
Window& window = *buffer->get_or_create_window();
if (param_count > 1)
@ -382,6 +383,7 @@ void show_buffer(const CommandParameters& params, Context& context)
if (not buffer)
throw runtime_error("buffer " + buffer_name + " does not exists");
BufferManager::instance().set_last_used_buffer(*buffer);
context.change_editor(*buffer->get_or_create_window());
}