1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-04 16:53:27 +03:00

Load buffer in command line order

Pass the first buffer on the the command line explicitely to client
creation. This ensure the buffer list matches the command line, which
makes buffer-next/buffer-previous a bit more useful.

Fixes #2705
This commit is contained in:
Maxime Coste 2022-12-06 17:48:42 +11:00
parent e7e46ef76a
commit 933e4a599c
4 changed files with 10 additions and 10 deletions

View File

@ -47,10 +47,12 @@ String ClientManager::generate_name() const
Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pid,
String name, EnvVarMap env_vars, StringView init_cmds,
Optional<BufferCoord> init_coord,
StringView init_buffer, Optional<BufferCoord> init_coord,
Client::OnExitCallback on_exit)
{
Buffer& buffer = BufferManager::instance().get_first_buffer();
Buffer& buffer = init_buffer.empty() ? BufferManager::instance().get_first_buffer()
: BufferManager::instance().get_buffer(init_buffer);
WindowAndSelections ws = get_free_window(buffer);
Client* client = new Client{std::move(ui), std::move(ws.window),
std::move(ws.selections), pid,

View File

@ -21,7 +21,7 @@ public:
Client* create_client(std::unique_ptr<UserInterface>&& ui, int pid,
String name, EnvVarMap env_vars, StringView init_cmds,
Optional<BufferCoord> init_coord,
StringView init_buffer, Optional<BufferCoord> init_coord,
Client::OnExitCallback on_exit);
bool empty() const { return m_clients.empty(); }

View File

@ -754,7 +754,7 @@ enum class ServerFlags
constexpr bool with_bit_ops(Meta::Type<ServerFlags>) { return true; }
int run_server(StringView session, StringView server_init,
StringView client_init, Optional<BufferCoord> init_coord,
StringView client_init, StringView init_buffer, Optional<BufferCoord> init_coord,
ServerFlags flags, UIType ui_type, DebugFlags debug_flags,
ConstArrayView<StringView> files)
{
@ -836,9 +836,7 @@ int run_server(StringView session, StringView server_init,
if (not files.empty()) try
{
// create buffers in reverse order so that the first given buffer
// is the most recently created one.
for (auto& file : files | reverse())
for (auto& file : files)
{
try
{
@ -867,7 +865,7 @@ int run_server(StringView session, StringView server_init,
if (not server.is_daemon())
{
local_client = client_manager.create_client(
create_local_ui(ui_type), getpid(), {}, get_env_vars(), client_init, std::move(init_coord),
create_local_ui(ui_type), getpid(), {}, get_env_vars(), client_init, init_buffer, std::move(init_coord),
[](int status) { local_client_exit = status; });
if (startup_error and local_client)
@ -1234,7 +1232,7 @@ int main(int argc, char* argv[])
((argc == 1 or (ignore_kakrc and argc == 2))
and isatty(0) ? ServerFlags::StartupInfo : ServerFlags::None);
auto debug_flags = option_from_string(Meta::Type<DebugFlags>{}, parser.get_switch("debug").value_or(""));
return run_server(session, server_init, client_init, init_coord, flags, ui_type, debug_flags, files);
return run_server(session, server_init, client_init, files.empty() ? StringView{} : files[0], init_coord, flags, ui_type, debug_flags, files);
}
catch (convert_to_client_mode& convert)
{

View File

@ -793,7 +793,7 @@ private:
auto* ui = new RemoteUI{sock, dimensions};
ClientManager::instance().create_client(
std::unique_ptr<UserInterface>(ui), pid, std::move(name),
std::move(env_vars), init_cmds, init_coord,
std::move(env_vars), init_cmds, {}, init_coord,
[ui](int status) { ui->exit(status); });
Server::instance().remove_accepter(this);