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