Skip to content

Open links in InputField with Ctrl+click - #383

Open
meh7an wants to merge 1 commit into
desktop-app:masterfrom
meh7an:feature/open-links-in-fields
Open

meh7an wants to merge 1 commit into
desktop-app:masterfrom
meh7an:feature/open-links-in-fields

Conversation

@meh7an

@meh7an meh7an commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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::Check before a link is shown as clickable and with OpenLinkAction::Open on 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 until QTextDocument::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.

@john-preston

Copy link
Copy Markdown
Collaborator

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.

@meh7an
meh7an force-pushed the feature/open-links-in-fields branch from c18af6e to 3b598b6 Compare October 22, 2026 20:20
@meh7an

meh7an commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants