odoo/odoo#118204

Created by fw-bot
Merged at 5190870a7c764fe852b221c053e47f973095edde

Statuses:

label
odoo-dev:master-15.0-web_editor-onPaste_fixes-rcdl-M6bS-fw
head
b9714dc549aa1d21c7c31d463db27d29c6ac841f
merged
2 years ago by Editor, David Monjoie (dmo)
odoo/odoo
15.0 #108755
saas-15.2 #116603
16.0 #116949
saas-16.1 #117246
saas-16.2 #118193
17.0
saas-17.4
18.0
saas-18.1
saas-18.2
saas-18.3
master #118204

[FW][FIX] web_editor: fix issues when pasting URL

This PR fixes the following issues, and adds the related missing unit tests.

Before this PR:
1. Pasting an image or video URL as simple text was failing, and pasting it as a link was undoing the last modification before it.

  1. Pasting image/video URL + other text fragments: The powerbox commands are not compatible with pasting text containing:
    • one image/video URL and other text fragments
    • multiple URLs.

         Choosing to embed the image/video or to paste it as URL leads to loss of all text fragments and URLs but the last URL.

  1. Pasting image URL inside an existing link: Even though the Editor's specs do not allow a URL to be transformed into a link when pasting it inside an existing link, pasting an image URL inside a link opens the powerbox with 3 commands, one of them allowing to transform the URL into a link.

~4. When pasting an image URL inside an "isolated" link (after having clicked on it and making it the only contenteditable in the document), the cursor disappeared, preventing the powerbox to open (it would open later when insering text somewhere outside the link).~

  1. The Selection is not properly restored when UNDOing after pasting over a non-collapsed selection:

    • a valid URL (not image or video)
    • text composed of a valid URL between text fragments
  2. When pasting media URL the powerbox would open with 2 command groups, containing one command each. Grouping is useless in this case.

  3. Pasting media URL with the mouse (right click + paste) failed to open Powerbox

  4. Pasting content inside an (invisible) empty link or when all its inner contents were selected lead to undesired effects, among which having nested links (see task-3081254)

After this PR:
1. Image and video URLs can be pasted as a link ~or as text~.
~But another issue arises from being able to paste a URL as text: if the user wishes to type further after the URL, hitting the SPACE key transforms the recently pasted URL behind the cursor. In order to prevent this, this PR proposes the following spec:~
~When pasting a URL as text at the end of a line, an extra space is added.~

~Otherwise the user would have no way to type more text in that line without transforming the URL into a link.
Pasting the URL somewhere other than right before a line break does not lead to the addition of an extra space, as this would mostly likely lead to an undesired inclusion of a space.~
         Pasting a URL as plain text is no longer possible, as this was considered a useless command.

  1. The powerbox does not open when pasting multiple URLs or URL + other text fragments.
    This does not change current spec, in which related tests only dealt with the scenario of pasting a single image/video URL. It proposes only that the current spec should not apply to the cases other than a single URL. In such cases, normal pasting with URL transformation takes place.

  2. The powerbox no longer opens when pasting a image URL inside a link, and the image is embedded directly. The logic for selecting the suitable powerbox commands when pasting URL was rewritten.

~4. The cursor position is restored after pasting an image URL inside an isolated link, and the powerbox opens.~

  1. Selection is properly restored after paste + UNDO.

  2. Command groups were removed from powerbox upon paste of media URL.

  3. Pasting media URL with the mouse opens Powerbox as expected.

  4. In order to prevent inadvertently pasting content inside a link rather than replacing it, this PR removes the link when pasting content inside an empty link or when all of its text content is selected, letting the pasted content replace it.

Other minor fixes:
Unnecessary regex matchings were removed.
Removed argument from call to historyPauseSteps, as this function takes no arguments.

See commit messages for details on the technicals.

task-3099012
task-3081254

Forward-Port-Of: #117246
Forward-Port-Of: #108755