From 32395fd83837913a2d4a43998bfd76da744ec887 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Tue, 16 Dec 2025 10:09:07 +0200 Subject: [PATCH 1/2] Fix cmd-click opening of relative/local paths --- src/Surface.zig | 24 +++++++++++++++++++++++- src/config/url.zig | 20 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 19c2662c1..6c00af575 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2034,6 +2034,23 @@ pub fn pwd( return try alloc.dupe(u8, terminal_pwd); } +/// Resolves a relative file path to an absolute path using the terminal's pwd. +fn resolvePathForOpening( + self: *Surface, + path: []const u8, +) Allocator.Error!?[]const u8 { + if (!std.fs.path.isAbsolute(path)) { + const terminal_pwd = self.io.terminal.getPwd() orelse { + return null; + }; + + const resolved = try std.fs.path.resolve(self.alloc, &.{ terminal_pwd, path }); + return resolved; + } + + return null; +} + /// Returns the x/y coordinate of where the IME (Input Method Editor) /// keyboard should be rendered. pub fn imePoint(self: *const Surface) apprt.IMEPos { @@ -4262,7 +4279,12 @@ fn processLinks(self: *Surface, pos: apprt.CursorPos) !bool { .trim = false, }); defer self.alloc.free(str); - try self.openUrl(.{ .kind = .unknown, .url = str }); + + const resolved_path = try self.resolvePathForOpening(str); + defer if (resolved_path) |p| self.alloc.free(p); + + const url_to_open = resolved_path orelse str; + try self.openUrl(.{ .kind = .unknown, .url = url_to_open }); }, ._open_osc8 => { diff --git a/src/config/url.zig b/src/config/url.zig index da3928aff..1901cb6f0 100644 --- a/src/config/url.zig +++ b/src/config/url.zig @@ -26,7 +26,7 @@ pub const regex = "(?:" ++ url_schemes ++ \\)(?: ++ ipv6_url_pattern ++ - \\|[\w\-.~:/?#@!$&*+,;=%]+(?:[\(\[]\w*[\)\]])?)+(? Date: Tue, 16 Dec 2025 10:17:54 +0200 Subject: [PATCH 2/2] Add a description to the test section comment --- src/config/url.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/url.zig b/src/config/url.zig index 1901cb6f0..fdbc964d7 100644 --- a/src/config/url.zig +++ b/src/config/url.zig @@ -253,6 +253,7 @@ test "url regex" { .input = "IPv6 in markdown [link](http://[2001:db8::1]/docs)", .expect = "http://[2001:db8::1]/docs", }, + // File paths with spaces .{ .input = "./spaces-end. ", .expect = "./spaces-end. ",