parent
6bb775241c
commit
6840f7ce9c
|
@ -89,15 +89,6 @@ Buffer& BufferManager::get_buffer(StringView name)
|
||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferManager::set_last_used_buffer(Buffer& buffer)
|
|
||||||
{
|
|
||||||
auto it = find_if(m_buffers, [&buffer](const SafePtr<Buffer>& p)
|
|
||||||
{ return p.get() == &buffer; });
|
|
||||||
kak_assert(it != m_buffers.end());
|
|
||||||
m_buffers.erase(it);
|
|
||||||
m_buffers.emplace(m_buffers.begin(), &buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BufferManager::backup_modified_buffers()
|
void BufferManager::backup_modified_buffers()
|
||||||
{
|
{
|
||||||
for (auto& buf : m_buffers)
|
for (auto& buf : m_buffers)
|
||||||
|
|
|
@ -29,7 +29,6 @@ public:
|
||||||
|
|
||||||
Buffer* get_buffer_ifp(StringView name);
|
Buffer* get_buffer_ifp(StringView name);
|
||||||
Buffer& get_buffer(StringView name);
|
Buffer& get_buffer(StringView name);
|
||||||
void set_last_used_buffer(Buffer& buffer);
|
|
||||||
|
|
||||||
void backup_modified_buffers();
|
void backup_modified_buffers();
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,8 @@ void Client::change_buffer(Buffer& buffer)
|
||||||
if (m_buffer_reload_dialog_opened)
|
if (m_buffer_reload_dialog_opened)
|
||||||
close_buffer_reload_dialog();
|
close_buffer_reload_dialog();
|
||||||
|
|
||||||
|
m_last_buffer = &m_window->buffer();
|
||||||
|
|
||||||
auto& client_manager = ClientManager::instance();
|
auto& client_manager = ClientManager::instance();
|
||||||
m_window->options().unregister_watcher(*this);
|
m_window->options().unregister_watcher(*this);
|
||||||
client_manager.add_free_window(std::move(m_window),
|
client_manager.add_free_window(std::move(m_window),
|
||||||
|
|
|
@ -52,6 +52,9 @@ public:
|
||||||
|
|
||||||
StringView get_env_var(StringView name) const;
|
StringView get_env_var(StringView name) const;
|
||||||
|
|
||||||
|
Buffer* last_buffer() const { return m_last_buffer.get(); }
|
||||||
|
void set_last_buffer(Buffer* last_buffer) { m_last_buffer = last_buffer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_option_changed(const Option& option) override;
|
void on_option_changed(const Option& option) override;
|
||||||
|
|
||||||
|
@ -77,6 +80,8 @@ private:
|
||||||
Vector<Key, MemoryDomain::Client> m_pending_keys;
|
Vector<Key, MemoryDomain::Client> m_pending_keys;
|
||||||
|
|
||||||
bool m_buffer_reload_dialog_opened = false;
|
bool m_buffer_reload_dialog_opened = false;
|
||||||
|
|
||||||
|
SafePtr<Buffer> m_last_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,8 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
|
||||||
for (auto& client : m_clients)
|
for (auto& client : m_clients)
|
||||||
{
|
{
|
||||||
client->context().forget_jumps_to_buffer(buffer);
|
client->context().forget_jumps_to_buffer(buffer);
|
||||||
|
if (client->last_buffer() == &buffer)
|
||||||
|
client->set_last_buffer(nullptr);
|
||||||
|
|
||||||
if (&client->context().buffer() != &buffer)
|
if (&client->context().buffer() != &buffer)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -134,7 +134,6 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
auto& buffer_manager = BufferManager::instance();
|
auto& buffer_manager = BufferManager::instance();
|
||||||
|
|
||||||
Buffer* buffer = buffer_manager.get_buffer_ifp(name);
|
Buffer* buffer = buffer_manager.get_buffer_ifp(name);
|
||||||
Buffer* oldbuf = &context.buffer();
|
|
||||||
|
|
||||||
if (force_reload and buffer and buffer->flags() & Buffer::Flags::File)
|
if (force_reload and buffer and buffer->flags() & Buffer::Flags::File)
|
||||||
reload_file_buffer(*buffer);
|
reload_file_buffer(*buffer);
|
||||||
|
@ -143,11 +142,7 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
if (parser.get_switch("scratch"))
|
if (parser.get_switch("scratch"))
|
||||||
{
|
{
|
||||||
if (Buffer* buf = buffer_manager.get_buffer_ifp(name))
|
if (Buffer* buf = buffer_manager.get_buffer_ifp(name))
|
||||||
{
|
|
||||||
buffer_manager.delete_buffer(*buf);
|
buffer_manager.delete_buffer(*buf);
|
||||||
if (buf == oldbuf)
|
|
||||||
oldbuf = nullptr;
|
|
||||||
}
|
|
||||||
buffer = new Buffer(name, Buffer::Flags::None);
|
buffer = new Buffer(name, Buffer::Flags::None);
|
||||||
}
|
}
|
||||||
else if (auto fifo = parser.get_switch("fifo"))
|
else if (auto fifo = parser.get_switch("fifo"))
|
||||||
|
@ -162,9 +157,6 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldbuf)
|
|
||||||
buffer_manager.set_last_used_buffer(*oldbuf);
|
|
||||||
|
|
||||||
const size_t param_count = parser.positional_count();
|
const size_t param_count = parser.positional_count();
|
||||||
if (buffer != &context.buffer() or param_count > 1)
|
if (buffer != &context.buffer() or param_count > 1)
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
|
@ -379,12 +371,9 @@ const CommandDesc buffer_cmd = {
|
||||||
buffer_completer,
|
buffer_completer,
|
||||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
{
|
{
|
||||||
Buffer* oldbuf = &context.buffer();
|
|
||||||
Buffer& buffer = BufferManager::instance().get_buffer(parser[0]);
|
Buffer& buffer = BufferManager::instance().get_buffer(parser[0]);
|
||||||
|
if (&buffer != &context.buffer())
|
||||||
if (&buffer != oldbuf)
|
|
||||||
{
|
{
|
||||||
BufferManager::instance().set_last_used_buffer(*oldbuf);
|
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.change_buffer(buffer);
|
context.change_buffer(buffer);
|
||||||
}
|
}
|
||||||
|
@ -417,7 +406,6 @@ void cycle_buffer(const ParametersParser& parser, Context& context, const ShellC
|
||||||
|
|
||||||
if (newbuf != oldbuf)
|
if (newbuf != oldbuf)
|
||||||
{
|
{
|
||||||
BufferManager::instance().set_last_used_buffer(*oldbuf);
|
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.change_buffer(*newbuf);
|
context.change_buffer(*newbuf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,14 +160,15 @@ void goto_commands(Context& context, NormalParams params)
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
{
|
{
|
||||||
auto& buffer_manager = BufferManager::instance();
|
Buffer* target = nullptr;
|
||||||
auto it = buffer_manager.begin();
|
if (not context.has_client() or
|
||||||
if (it->get() == &buffer and ++it == buffer_manager.end())
|
not (target = context.client().last_buffer()))
|
||||||
|
{
|
||||||
|
context.print_status({"no last buffer", get_face("Error")});
|
||||||
break;
|
break;
|
||||||
Buffer& target = **it;
|
}
|
||||||
BufferManager::instance().set_last_used_buffer(buffer);
|
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.change_buffer(target);
|
context.change_buffer(*target);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'f':
|
case 'f':
|
||||||
|
@ -195,8 +196,6 @@ void goto_commands(Context& context, NormalParams params)
|
||||||
|
|
||||||
if (buffer != &context.buffer())
|
if (buffer != &context.buffer())
|
||||||
{
|
{
|
||||||
Buffer* oldbuf = &context.buffer();
|
|
||||||
BufferManager::instance().set_last_used_buffer(*oldbuf);
|
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.change_buffer(*buffer);
|
context.change_buffer(*buffer);
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1112,6 @@ void jump(Context& context, NormalParams)
|
||||||
|
|
||||||
Buffer* oldbuf = &context.buffer();
|
Buffer* oldbuf = &context.buffer();
|
||||||
Buffer& buffer = const_cast<Buffer&>(jump.buffer());
|
Buffer& buffer = const_cast<Buffer&>(jump.buffer());
|
||||||
BufferManager::instance().set_last_used_buffer(buffer);
|
|
||||||
if (&buffer != oldbuf)
|
if (&buffer != oldbuf)
|
||||||
context.change_buffer(buffer);
|
context.change_buffer(buffer);
|
||||||
context.selections_write_only() = jump;
|
context.selections_write_only() = jump;
|
||||||
|
|
|
@ -38,6 +38,14 @@ struct RefPtr
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr& operator=(T* ptr)
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
m_ptr = ptr;
|
||||||
|
acquire();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
T* operator->() const { return m_ptr; }
|
T* operator->() const { return m_ptr; }
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user