Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-24861

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

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 18.7.0
    • CKEditor
    • None
    • Unknown

    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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mflorea Marius Dumitru Florea
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: