[FIX] web_editor: auto transforming email URL
Typing a URL + SPACE transforms the URL into a link. Before this commit, email URLs were incorrectly prepended with 'https://'. Because it is not desirable to automatically transform email URLs, this commit disables link transformation for email URLs, leaving it only active for http URLs. task-3284649 X-original-commit: ad0e7845fceb578398e42e4b35820c415734452a Part-of: odoo/odoo#136278
This commit is contained in:
@@ -78,6 +78,7 @@ import {
|
||||
leftPos,
|
||||
isNotAllowedContent,
|
||||
childNodeIndex,
|
||||
EMAIL_REGEX,
|
||||
} from './utils/utils.js';
|
||||
import { editorCommands } from './commands/commands.js';
|
||||
import { Powerbox } from './powerbox/Powerbox.js';
|
||||
@@ -4589,7 +4590,7 @@ export class OdooEditor extends EventTarget {
|
||||
const textSliced = selection.anchorNode.textContent.slice(0, selection.anchorOffset);
|
||||
const textNodeSplitted = textSliced.split(/\s/);
|
||||
let potentialUrl = textNodeSplitted.pop();
|
||||
const lastWordMatch = potentialUrl.match(URL_REGEX_WITH_INFOS);
|
||||
const lastWordMatch = potentialUrl.match(URL_REGEX_WITH_INFOS) && !potentialUrl.match(EMAIL_REGEX);
|
||||
|
||||
if (lastWordMatch) {
|
||||
const matches = getUrlsInfosInString(textSliced);
|
||||
|
||||
@@ -4250,6 +4250,25 @@ X[]
|
||||
contentAfter: '<p>a http://test.com b <a href="http://test.com">http://test.com</a><br>[] c http://test.com d</p>',
|
||||
});
|
||||
});
|
||||
it('should not transform an email url after space', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>user@domain.com[]</p>',
|
||||
stepFunction: async (editor) => {
|
||||
editor.testMode = false;
|
||||
const selection = document.getSelection();
|
||||
const anchorOffset = selection.anchorOffset;
|
||||
const p = editor.editable.querySelector('p');
|
||||
const textNode = p.childNodes[0];
|
||||
triggerEvent(editor.editable, 'keydown', {key: ' ', code: 'Space'});
|
||||
textNode.textContent = "user@domain.com\u00a0";
|
||||
selection.extend(textNode, anchorOffset + 1);
|
||||
selection.collapseToEnd();
|
||||
triggerEvent(editor.editable, 'input', {data: ' ', inputType: 'insertText' });
|
||||
triggerEvent(editor.editable, 'keyup', {key: ' ', code: 'Space'});
|
||||
},
|
||||
contentAfter: '<p>user@domain.com []</p>',
|
||||
});
|
||||
});
|
||||
it('should not transform url after two space', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>a http://test.com b http://test.com [] c http://test.com d</p>',
|
||||
|
||||
Reference in New Issue
Block a user