fix: copy_url_to_clipboard copies full OSC8 URL instead of single character

OSC8 links were only detected when exact platform-specific modifiers were held (Cmd on macOS, Ctrl on Linux), but copy_url_to_clipboard should work with either. Additionally, OSC8 links were using selectionString() which gets visible text instead of the actual URI. Now we use osc8URI() for OSC8 links and fall back to selectionString() for regex-detected links.

Fixes #7491
pull/7551/head
Alex Straight 2025-06-08 21:53:28 -07:00 committed by Mitchell Hashimoto
parent a479c9b2af
commit 5836dc4ce6
1 changed files with 22 additions and 9 deletions

View File

@ -3681,7 +3681,7 @@ fn linkAtPos(
const mouse_mods = self.mouseModsWithCapture(self.mouse.mods); const mouse_mods = self.mouseModsWithCapture(self.mouse.mods);
// If we have the proper modifiers set then we can check for OSC8 links. // If we have the proper modifiers set then we can check for OSC8 links.
if (mouse_mods.equal(input.ctrlOrSuper(.{}))) hyperlink: { if (mouse_mods.ctrl or mouse_mods.super) hyperlink: {
const rac = mouse_pin.rowAndCell(); const rac = mouse_pin.rowAndCell();
const cell = rac.cell; const cell = rac.cell;
if (!cell.hyperlink) break :hyperlink; if (!cell.hyperlink) break :hyperlink;
@ -4494,19 +4494,32 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
const pos = try self.rt_surface.getCursorPos(); const pos = try self.rt_surface.getCursorPos();
if (try self.linkAtPos(pos)) |link_info| { if (try self.linkAtPos(pos)) |link_info| {
// Get the URL text from selection const url_text = switch (link_info[0]) {
const url_text = (self.io.terminal.screen.selectionString(self.alloc, .{ ._open_osc8 => url_text: {
.sel = link_info[1], // For OSC8 links, get the URI directly from hyperlink data
.trim = self.config.clipboard_trim_trailing_spaces, const uri = self.osc8URI(link_info[1].start()) orelse {
})) catch |err| { log.warn("failed to get URI for OSC8 hyperlink", .{});
log.err("error reading url string err={}", .{err}); return false;
return false; };
break :url_text try self.alloc.dupeZ(u8, uri);
},
.open => url_text: {
// For regex links, get the text from selection
break :url_text (self.io.terminal.screen.selectionString(self.alloc, .{
.sel = link_info[1],
.trim = self.config.clipboard_trim_trailing_spaces,
})) catch |err| {
log.err("error reading url string err={}", .{err});
return false;
};
},
}; };
defer self.alloc.free(url_text); defer self.alloc.free(url_text);
self.rt_surface.setClipboardString(url_text, .standard, false) catch |err| { self.rt_surface.setClipboardString(url_text, .standard, false) catch |err| {
log.err("error copying url to clipboard err={}", .{err}); log.err("error copying url to clipboard err={}", .{err});
return true; return false;
}; };
return true; return true;