Repository navigation
Conversation
4235f42 to
c18af6e
Compare
|
Adds Ctrl/Cmd+click links in input fields. Automatic detection ignores formatting tags: with example formatted as code in example.com, clicking the plain .com opens the whole URL. Parsing needs to respect code spans. |
c18af6e to
3b598b6
Compare
Thanks, fixed. A link found by the parser is now skipped when it overlaps code, a code block, a text link or a mention, so with "example" formatted as code in example.com nothing opens from the plain ".com". The sent message doesn't make that a link either. While at it, pressing a link with Ctrl held now shows the same ripple as links in messages, and Ctrl-dragging a link moves it inside the field or copies it elsewhere. |
InputField::setOpenLinkCallback()lets a Ctrl+click (Cmd+click on macOS) open the link under the pointer. Text links and mention tags are found by their tags, and plain URLs, emails, mentions and hashtags with the same parser message text uses, run on the text the field would send, so an emoji inside a link is part of it like it is in the sent message. A parsed link that overlaps code, a code block, a text link or a mention is skipped, so clicking the plain text next to them doesn't open a link that runs into them.While Ctrl is held over a link, the cursor becomes a pointer and the whole link is underlined through an extra selection, so the document itself doesn't change. The underline follows the text when it changes or scrolls. The callback is asked with
OpenLinkAction::Checkbefore a link is shown as clickable and withOpenLinkAction::Openon the click, so the app decides which links can open in which field. Fields without the callback work as before.Pressing a link with Ctrl held shows the same ripple as pressing a link in a message. Dragging it moves the link within the field, with its formatting, as one undo step, and copies it anywhere else: other fields get the text with its tags, and other apps get the URL of a text link as plain text, like dragging a link out of a message. A drag that starts inside a selection carries only the selected part.
Emoji and other inline objects take one character in the document but several in the text, so
getTextPart()can now report where each object was replaced, and the parsed links are mapped back to document positions through that. The lookup is cached untilQTextDocument::revision()changes: a paragraph is parsed once after each edit and the link under the pointer is then found with a binary search, so moving over a long paragraph with Ctrl held doesn't parse it again, and moving within the same text link doesn't walk its fragments again.Used by telegramdesktop/tdesktop#31413.