-
-
Notifications
You must be signed in to change notification settings - Fork 595
Description
Information
- Version: most recent master: 6a5c507
Describe the bug
If a link is output into a small grid for example it gets layouted into multiple lines. The way the linkId is currently implemented (Hash+Random) will cause those segments to be treated as different links. This results in a situation where the hover effect occurs only on parts of the link.
To Reproduce
// create a narrow grid with width 10 containing a link
AnsiConsole.Console.Write(
new Grid() { Width = 10 }
.AddColumn()
.AddRow("[link]https://google.com[/]")
);
// now hovering over the link (in a terminal that supports hyperlinks) only highlights part of the link.
// also because of the implicit link markup the link target is wrong as well.
Expected behavior
Even if the link is split into multiple rows during the render process it should be the same link (same id so the terminal recognizes it as the same link) and the target should still be valid for all segments.
Additional context
I think this are really two bugs.
- The link target is wrong because the implicit link is not set inside the style but pretty late in
AnsiBuilder.GetAnsi
but at that point the inner text might already be split and layouted all over the place. - The link Id should probably be persisted inside Style to survive the layout process. At the moment everything is split into segments and later a linkId is assigned.
Ideas:
Regarding point 1) if a link markup only has text but not set an explicit link the assignment should happen before the style is created (probably in StyleParser.cs
)
Regarding point 2) IMO the linkId should be part of the Style and just be incremented and set in the constructor if the provided link was not null or empty. The counter could simply be a static field and used like that: LinkId = Interlocked.Increment(ref _linkId);
To be honest I don't get why the current LinkId hasher was implemented as it is. First a hash is generated based on the link target and than a random number is added, so why hash the link in the first place? Just incrementing a counter would be simpler and deterministic and would result in a more testable output.
Please upvote 👍 this issue if you are interested in it.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status