-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HyperTextView #507
HyperTextView #507
Conversation
I like this idea, although I haven't had the chance to test it yet. This definitely seems like a good thing to implement in Granite imo, since it seems like a pain to write but useful for a wide variety of apps. I think doing something like pulling up a long blog post's source code on weaker hardware like a Pi or Pinebook would be a good stress test for performance, but I don't have that hardware. I'll try pulling up a long editor sometime today if I have the time, but my computer's pretty fast, so I expect it can handle this pretty well. A few thoughts in general:
|
@mcclurgm I do agree with the ideas on how to improve performance, but I'm wondering if the effort is really worth it. So having someone doing some real world testing on restricted hardware would be great. Regarding the link detection; The regex in place right now is rather simple. Leading and trailing whitespace mark the start and end of the URI. In between there must be at least four non-whitespace characters with a dot in the middle (at least 2 characters, 1 dot, at least 2 characters). The protocol information at the beginning (xyz://) is optional and HyperTextView will use http:// if there isn't any protocol.
UPDATE: While the basic idea of the regex is still the same (protocol optional, two chars, a dot, two chars), I expanded it a bit to add support for some more common use cases. See comment below. |
UPDATE:
|
@mcclurgm adressed the performance concerns: Rescanning of the buffer is now limited from line start to line end of the cursor position. Also buffer change events are debounced. That said, scanning of said substring happens once each 300ms at most. The only exception is when text was pasted - in this case a rescan of the whole buffer is forced after 300ms. This strategy seems to work quite well on my end - even for large texts. As test case I copied the source of https://blog.elementary.io/elementary-os-6-odin-beta-2/ (around 1300 lines of code) and editing feels normal on my machine. |
I'm seeing some strange behaviors here. First, it seems like there's some issue with offset. Depending on what I paste, the hypertext underlines start after the URI does, and seem to extend past the end. Here's an example:
On my machine, I see that the link underlines start after the
the link underlines start after
I see some strange behavior with links surrounding the insertion point blinking in and out when editing by hand, when I was looking at the offset issue. I've attached a video. Sorry about the artifacts. Focus on the Then another (maybe) unrelated bug. The regex (sometimes?) doesn't match at the very end of a buffer. For example, if I paste the second example string (the shortened copyright header) at the end of the file, neither URI matches. If I add a line break after that same text, the link will sometimes match. But sometimes I paste a long buffer with a link at the end and it works ok? This is a weird one too. I haven't found any indication of when it works or doesn't. Also, some things that aren't bugs but I wanted to bring up:
I can try to look into the cause of the bugs I mentioned, but I'm not really sure when I'll have time, sorry. |
@mcclurgm good catch - that was a tricky one! The wrong behaviour was because of multibyte string encoding. Or as the documentation puts it:
I fixed the error and detection works fine now even for more complex multi-byte-strings with emojis or similar. Feel free to re-test. Regarding the |
Aha--good catch. The joys of text rendering! 😬 In some very quick testing I haven't found any issues with the end of the buffer, so it's possible that was related to the offsets too. I'll let you know if I see it again. Interesting point about the tooltips. I found a mailing list thread with some cursory duckduckgo, but it looks complicated, and the thread never comes up with a complete solution. So you're right, that may be too hard to pull off. As a potential compromise, what if we only followed the link if the mouse releases close to the position where it was pressed? That would allow you to select text without following the link. (For prior art, this is how Mac's TextEdit does it. I know Google Docs shows a popup with a clickable link when you click on link text, and I think Word uses ctrl+click.) I'm not sure how easy a "click" vs a "selection drag" would be to define though: we'd probably have to make some thresholds. |
I'm up for anything which improves the experience. Maybe someone from @elementary/ux has got some additional thoughts on this? |
I'm checking out the Tasks PR to see. From my perspective from what I've seen in Calendar, this seems good to me though. I don't understand what you mean by the popover in Tasks. Is that a part of One question though: is it possible to have links without a domain name? I get that something like |
@mcclurgm thanks for your feedback!
I think we can safely assume there needs to be at least one However, I wasn't sure what the
Yes, the popover is part of HyperTextView and appears if you hover over a hyperlink and wait for a bit. It should also appear in Tasks, but does not right now - no clue why. But I think that's a minor issue and related to the Tasks app, so we should be good to merge HyperTextView regardless. Here's how it looks like in the |
That should work just as well, I think. The I am seeing the tooltip in Tasks, but strangely it's intermittent and only appears on certain links some of the time. I may try to track it down, but if you think it's Tasks-related, that doesn't have to be a blocker for this PR. |
Thanks to the engineering work of @mcclurgm and @jeremypw we even fixed the tooltip issue in the Tasks app now (elementary/tasks#281) - thank you both for this missing piece! We are now at a point with HyperTextView where I'm fully confident that HyperTextView provides a smooth experience and I'm not aware of any issues. So IMHO we are here finally able to merge - thanks for this team effort! 🥳 |
For what it’s worth I’d say LGTM. Makes sense to get a final review from Danielle though. I have some thoughts for enhancement to discuss, but let’s wait on those until we commit a functional version. (Mostly just colors and branding could be nice to customize, and also add documentation. I'd be happy to write documentation myself, once the final form is figured out.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's :)
This PR adds
Granite.Widgets.HyperTextView
, a drop in replacement forGtk.TextView
with added support for navigatable URI's. The code is mainly based on the example of Alberto Fanjul:Although it is not heavily tested yet, it should work for the majority of cases. Also I guess there is room for performance improvements (see discussion in elementary/calendar#656).
This feature request came up in Calendar (elementary/calendar#571), but would also be useful in descriptions for Tasks and potentially further cases.
Last but not least, this PR is a response to @cassidyjames request on Twitter: https://twitter.com/CassidyJames/status/1404848863395991558