Change buffer order based on the last one used
This commit is contained in:
parent
79d8d082bd
commit
f230feec7f
|
@ -52,6 +52,16 @@ Buffer* BufferManager::get_buffer(const String& name)
|
||||||
return nullptr;
|
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,
|
CandidateList BufferManager::complete_buffername(const String& prefix,
|
||||||
CharCount cursor_pos)
|
CharCount cursor_pos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
size_t count() const { return m_buffers.size(); }
|
size_t count() const { return m_buffers.size(); }
|
||||||
|
|
||||||
Buffer* get_buffer(const String& name);
|
Buffer* get_buffer(const String& name);
|
||||||
|
void set_last_used_buffer(Buffer& buffer);
|
||||||
|
|
||||||
CandidateList complete_buffername(const String& prefix,
|
CandidateList complete_buffername(const String& prefix,
|
||||||
CharCount cursor_pos = -1);
|
CharCount cursor_pos = -1);
|
||||||
|
|
|
@ -288,6 +288,7 @@ void edit(const CommandParameters& params, Context& context)
|
||||||
buffer = open_or_create(name, context);
|
buffer = open_or_create(name, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferManager::instance().set_last_used_buffer(*buffer);
|
||||||
Window& window = *buffer->get_or_create_window();
|
Window& window = *buffer->get_or_create_window();
|
||||||
|
|
||||||
if (param_count > 1)
|
if (param_count > 1)
|
||||||
|
@ -382,6 +383,7 @@ void show_buffer(const CommandParameters& params, Context& context)
|
||||||
if (not buffer)
|
if (not buffer)
|
||||||
throw runtime_error("buffer " + buffer_name + " does not exists");
|
throw runtime_error("buffer " + buffer_name + " does not exists");
|
||||||
|
|
||||||
|
BufferManager::instance().set_last_used_buffer(*buffer);
|
||||||
context.change_editor(*buffer->get_or_create_window());
|
context.change_editor(*buffer->get_or_create_window());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user