From 056c9af38e9077094a898b8843018c03113cd2a9 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 15 Apr 2026 15:20:36 -0700 Subject: [PATCH] Fix macOS GUI file loading: resolve CLI paths before chdir On macOS GUI builds, chdir(HOME) runs before deferred file opens are processed, breaking relative paths passed on the command line. Resolve each argv path to absolute immediately during argument parsing. Bump version to 1.11.2. Co-Authored-By: Claude Opus 4.6 (1M context) --- CMakeLists.txt | 2 +- main.cc | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 328a0e9..a413af4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(kte) include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 20) -set(KTE_VERSION "1.11.1") +set(KTE_VERSION "1.11.2") # Default to terminal-only build to avoid SDL/OpenGL dependency by default. # Enable with -DBUILD_GUI=ON when SDL2/OpenGL/Freetype are available. diff --git a/main.cc b/main.cc index d166711..a68495a 100644 --- a/main.cc +++ b/main.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -255,7 +256,18 @@ main(int argc, char *argv[]) // Fall through: not a +number, treat as filename starting with '+' } - const std::string path = arg; + // Resolve to absolute path now, before any + // chdir (macOS GUI changes CWD to HOME before + // deferred opens are processed). + std::string path = arg; + try { + std::filesystem::path p(path); + if (p.is_relative()) { + path = std::filesystem::absolute(p).string(); + } + } catch (...) { + // Fall through with original path + } editor.RequestOpenFile(path, pending_line); pending_line = 0; // consumed (if set) }