This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-46a5cc35-c413-4e6b-88ec-a54bc3b179c4 XWIKI-24861 Open

Create a URL or mailto link when the selected text looks like a URL or an email address

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-3096e04f-7b17-4dbb-930f-80b32de5db26 Marius Dumitru Florea created this issue on 10/Sep/26 18:00
 
Summary: Create a URL or mailto link when the selected text looks like a URL or an email address
Issue Type: cid:jira-generated-image-avatar-46a5cc35-c413-4e6b-88ec-a54bc3b179c4 Improvement
Assignee: Unassigned
Components: CKEditor
Created: 10/Sep/26 18:00
Priority: cid:jira-generated-image-static-major-6db09677-ed2d-40a3-ab2d-dd732a3bc17c Major
Reporter: Marius Dumitru Florea
Description:

Motivation

When you select some text in the WYSIWYG editor and open the link dialog to create a link, the link target is preselected with the page that would be created from the selected text (XWIKI-24834). That is the right guess for ordinary text, but not when the selected text clearly isn't a page name: selecting https://www.xwiki.org or john@example.org and validating the dialog creates a link to a new page named after that URL or email address, instead of a link to the URL or the email address itself.

Proposal

When the link dialog is opened to create a new link and there is a text selection, determine the resource type that best describes the selection before preselecting the link target:

  • add an optional matches function to the resource types declared in resource.js, taking the selected text and returning a number between 0 and 1, where 0 means the text is definitely not that resource type and 1 means it definitely is
  • select the resource type with the best score, falling back on the document resource type
  • if the suggester of the selected resource type has a suggestNew function (only the document resource type has one today), await it and preselect the resource it returns, which is what happens today
  • otherwise set the selected text as the value of the resource reference input

Notes

  • Start with the URL and the email address matchers: they are the unambiguous ones, they have no suggester, and their resource types don't require the value to be selected from a list of suggestions.
  • Putting the selected text directly in the resource reference input is only safe for the resource types that don't declare mustBeSelected. The document, attachment and user resource types do declare it, so a value that is typed but not selected is validated asynchronously against the page name strategy, which is what XWIKI-23154 introduced. In particular, text that looks like a file name doesn't mean that such an attachment exists, so the attachment resource type shouldn't be preselected without looking the attachment up first.
  • Keep matches operating on plain text, so that resource.js stays editor agnostic and can be reused by the other editors.
  • LinkIT#createLinkAfterChangingResourceType documents the current behaviour (creating a new link always targets a new page computed from the selected text, resetting the resource type to the document one) and will need to be updated.