FIX - Add clickable hyperlinks when URLs are on screen #659#734
FIX - Add clickable hyperlinks when URLs are on screen #659#734karan68 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
|
|
||
| // It's not guaranteed that Black is actually dark and BrightWhite light (vice versa for a light theme). | ||
| // Such is the case with macOS 26's "Clear Dark" theme (and probably a lot other themes). | ||
| // Its black is #35424C (l=0.3716; oof!) and bright white is #E5EFF5 (l=0.9464). | ||
| // If we have a color such as #43698A (l=0.5065), which is l>0.5 ("light") and need a contrasting color, | ||
| // we need that to be #E5EFF5, even though that's also l>0.5. With a midpoint of 0.659, we get that right. | ||
| let lightness = self.auto_colors.map(|c| c.as_oklab().lightness()); | ||
| self.auto_color_threshold = (lightness[0] + lightness[1]) * 0.5; | ||
|
|
||
| // Ensure [0] is dark and [1] is light. | ||
| if lightness[0] > lightness[1] { |
There was a problem hiding this comment.
It looks like you reverted a change from main (#728) somehow. Please be careful not to do that.
There was a problem hiding this comment.
In general, the merge conflict resolution strategy where you delete all incoming changes is not good or typically acceptable for a collaborative project.
There was a problem hiding this comment.
Hey @DHowett , it missed my check sorry , i have reverted back , could you please review it , if i have missed something
|
DHowett can you approve this ? |
|
Hey there! Thanks for working on this. There are two main issues with this pull request. First, it should not be edit's job to spawn a browser. That will not work properly when it is used over a remote connection (or in WSL on Windows!). There is a well-documented VT sequence ("OSC 8") that can be used to indicate to a terminal emulator the span of a hyperlink. That puts the link handling in control of the client, rather than the server, in remote connection scenarios. Second, though: we are currently working on our syntax highlighting and pattern matching engine, which will make cases like this significantly easier to handle without writing too much bespoke code. We would rather hold off on this change until it has landed because of the changes it will require to the text buffer implementation; you can check its progress in #753 and #624 |
|
oh cool! thanks for letting me know about it |
Summary
Fixed a framebuffer artifact where hyperlink underlines could linger on rows below the last rendered document line.
Implemented hyperlink detection, styling, and Ctrl/Cmd+click navigation.
What / Where
src/buffer/mod.rs
Added lightweight hyperlink detection and caching (HyperlinkCache, LinkRange) and line‑level URL scanning.
In TextBuffer::render, track the last framebuffer row that contains document content and, after rendering, explicitly clear all remaining rows in the textarea viewport (text + fg/bg + attributes) so the diff sees them as changed.
Applied per‑line hyperlink styling (BrightCyan + underline) over the exact URL span.
src/tui.rs
For textareas, added Ctrl/Cmd+click handling: map click → document offset, resolve find_link_at_offset, and open the URL via start/open/xdg-open.
src/framebuffer.rs
Kept diffing model intact; no partial “dirty region” tracking, just used the new back‑buffer clears so rows below the last rendered line no longer carry stale styled pixels.
Why
Before: when hyperlink layout shrank upward, rows below the last rendered document line were never written into the back buffer, so front/back matched and the diff skipped them, leaving old underline/color data on screen.
After: TextBuffer::render always clears rows from last_rendered_row + 1 to the bottom of the textarea viewport, guaranteeing those rows change in the back buffer and get fully cleared in the terminal.
Tests
Automated:
cargo test (all unit tests and doctests pass).
Manual:
Open a file with long hyperlinks near the bottom of the viewport, edit/shorten the document or reflow so content moves up, and confirm no stale underlines remain below the last line.
Verify hyperlinks render underlined + cyan and that Ctrl/Cmd+click opens the correct URL.