From 4d3797c15e12027465faf7719719dbf1ae421c8a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Jul 2024 09:15:45 -0700 Subject: [PATCH 1/3] macos: limit URL preview to a single line, ellipses in middle --- macos/Sources/Ghostty/SurfaceView.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 5587d538e..3c2e083f8 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -159,6 +159,8 @@ extension Ghostty { Text(verbatim: url) .padding(.init(top: padding, leading: padding, bottom: padding, trailing: padding)) .background(.background) + .lineLimit(1) + .truncationMode(.middle) .opacity(isHoveringURLLeft ? 0 : 1) .onHover(perform: { hovering in isHoveringURLLeft = hovering @@ -175,6 +177,8 @@ extension Ghostty { Text(verbatim: url) .padding(.init(top: padding, leading: padding, bottom: padding, trailing: padding)) .background(.background) + .lineLimit(1) + .truncationMode(.middle) .opacity(isHoveringURLLeft ? 1 : 0) } } From eaa7a3f69c4d3792bae71049ab859e9a48d45a62 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Jul 2024 09:18:32 -0700 Subject: [PATCH 2/3] macos: left hover needs to be higher Z so it takes mouse priority --- macos/Sources/Ghostty/SurfaceView.swift | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 3c2e083f8..92d899300 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -152,6 +152,20 @@ extension Ghostty { if let url = surfaceView.hoverUrl { let padding: CGFloat = 3 ZStack { + HStack { + Spacer() + VStack(alignment: .leading) { + Spacer() + + Text(verbatim: url) + .padding(.init(top: padding, leading: padding, bottom: padding, trailing: padding)) + .background(.background) + .lineLimit(1) + .truncationMode(.middle) + .opacity(isHoveringURLLeft ? 1 : 0) + } + } + HStack { VStack(alignment: .leading) { Spacer() @@ -168,20 +182,6 @@ extension Ghostty { } Spacer() } - - HStack { - Spacer() - VStack(alignment: .leading) { - Spacer() - - Text(verbatim: url) - .padding(.init(top: padding, leading: padding, bottom: padding, trailing: padding)) - .background(.background) - .lineLimit(1) - .truncationMode(.middle) - .opacity(isHoveringURLLeft ? 1 : 0) - } - } } } From 53fbed492b27240193cdff0b06c8d9e5c97dbc51 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Jul 2024 09:26:07 -0700 Subject: [PATCH 3/3] apprt/gtk: ellipsize URLs in middle to show end --- src/apprt/gtk/Surface.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 406c7bece..62a432c9e 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -224,6 +224,7 @@ pub const URLWidget = struct { pub fn init(surface: *const Surface, str: [:0]const u8) URLWidget { // Create the left const left = c.gtk_label_new(str.ptr); + c.gtk_label_set_ellipsize(@ptrCast(left), c.PANGO_ELLIPSIZE_MIDDLE); c.gtk_widget_add_css_class(@ptrCast(left), "view"); c.gtk_widget_add_css_class(@ptrCast(left), "url-overlay"); c.gtk_widget_set_halign(left, c.GTK_ALIGN_START); @@ -232,6 +233,7 @@ pub const URLWidget = struct { // Create the right const right = c.gtk_label_new(str.ptr); + c.gtk_label_set_ellipsize(@ptrCast(right), c.PANGO_ELLIPSIZE_MIDDLE); c.gtk_widget_add_css_class(@ptrCast(right), "hidden"); c.gtk_widget_add_css_class(@ptrCast(right), "view"); c.gtk_widget_add_css_class(@ptrCast(right), "url-overlay");