From 76d0da58d9f87eeebc1206eca3f046df7b10946c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 03:10:38 +0000 Subject: [PATCH 1/2] Initial plan From 7fc97ff11ddf946a72c2ebe516ac94e3d9e4e9d5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 03:17:13 +0000 Subject: [PATCH 2/2] perf: cache URI validation in Link to avoid repeated work on redraws Co-authored-by: tig <585482+tig@users.noreply.github.com> --- Terminal.Gui/Views/Link.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/Link.cs b/Terminal.Gui/Views/Link.cs index ce43d2780d..2bd7ccfc51 100644 --- a/Terminal.Gui/Views/Link.cs +++ b/Terminal.Gui/Views/Link.cs @@ -180,15 +180,16 @@ protected override void UpdateTextFormatterText () public const string DEFAULT_URL = ""; private string _url = DEFAULT_URL; + private bool _isUrlValid = false; /// /// Gets or sets the URL (hyperlink target) associated with this . /// /// /// - /// Any string value is accepted. URL validation occurs at draw time: if the value is not a well-formed - /// absolute URI (per ), the link renders with the - /// style and no OSC 8 hyperlink sequence is emitted. + /// Any string value is accepted. URL validation is performed once when this property is set and the result is + /// cached: if the value is not a well-formed absolute URI (per ), the + /// link renders with the style and no OSC 8 hyperlink sequence is emitted. /// /// /// When is empty, is used as the display text. @@ -319,7 +320,7 @@ protected override bool OnDrawingText (DrawContext? context) string? url = Url; // If the URL is not valid, don't set CurrentUrl, and adjust the attributes to indicate it's not well-formed - if (!Uri.IsWellFormedUriString (Url, UriKind.Absolute)) + if (!_isUrlValid) { normalAttr = GetAttributeForRole (VisualRole.Disabled); normalAttr = normalAttr with { Background = HasFocus ? GetAttributeForRole (VisualRole.Focus).Background : normalAttr.Background }; @@ -372,6 +373,7 @@ private void SetUrl (string value) // Do the work _url = value; + _isUrlValid = Uri.IsWellFormedUriString (value, UriKind.Absolute); // CWP: Fire ValueChanged ValueChangedEventArgs changedArgs = new (oldValue, value);