From 34ff41f79713630afbfbbc8666f0e836a8cdfc03 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 1 Sep 2023 16:38:16 +0200 Subject: [PATCH] [FIX] web_editor: do not normalize on preserveCursor When preserving the selection, we typically want our selection to remain as close as possible to what it was before. But `preserveCursor` called `setSelection` with its default `normalize` argument, which would change the selection in sometimes unexpected ways. Part-of: odoo/odoo#141303 --- .../src/js/editor/odoo-editor/src/utils/utils.js | 2 +- .../js/editor/odoo-editor/test/spec/color.test.js | 8 ++++---- .../js/editor/odoo-editor/test/spec/format.test.js | 5 ++--- .../src/js/editor/odoo-editor/test/spec/link.test.js | 12 ++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 1bb6c062d6c..3ca80849f32 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -890,7 +890,7 @@ export function preserveCursor(document) { replace = replace || new Map(); cursorPos[0] = replace.get(cursorPos[0]) || cursorPos[0]; cursorPos[2] = replace.get(cursorPos[2]) || cursorPos[2]; - return setSelection(...cursorPos); + return setSelection(...cursorPos, false); }; } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js index bf192955a9b..1e84af141de 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js @@ -59,9 +59,9 @@ describe('applyColor', () => { await testEditor(BasicEditor, { contentBefore: '

[


]

', stepFunction: setColor('rgb(255, 0, 0)', 'color'), - contentAfterEdit: '

[\u200B

' + + contentAfterEdit: '

[\u200B

' + '

\u200B

' + - '

]\u200B

', + '

]\u200B

', contentAfter: '

[

]

', }); }); @@ -69,9 +69,9 @@ describe('applyColor', () => { await testEditor(BasicEditor, { contentBefore: '

[


]

', stepFunction: setColor('rgb(255, 0, 0)', 'backgroundColor'), - contentAfterEdit: '

[\u200B

' + + contentAfterEdit: '

[\u200B

' + '

\u200B

' + - '

]\u200B

', + '

]\u200B

', contentAfter: '

[

]

', }); }); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js index 6d95126b358..c6d0e1728e5 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js @@ -581,7 +581,7 @@ describe('Format', () => { contentAfter: `

a[b]c

`, }); }); - it('should insert new character inside strikethrough at first position', async () => { + it('should insert before strikethrough', async () => { await testEditor(BasicEditor, { contentBefore: `

d[a${s('bc]

')}

`, stepFunction: async editor => { @@ -641,7 +641,6 @@ describe('Format', () => { }); }); it('should remove underline, write, restore underline, write, remove underline again, write (collapsed, strikeThrough)', async () => { - const uselessS = s(u('\u200B', 'first'), 'first'); // TODO: clean await testEditor(BasicEditor, { contentBefore: `

ab${u(s(`cd[]ef`))}

`, stepFunction: async editor => { @@ -652,7 +651,7 @@ describe('Format', () => { await editor.execCommand('underline'); await editor.execCommand('insert', 'C'); }, - contentAfterEdit: `

ab${u(s(`cd`))}${s(`A${u(`B`, 'first')}C[]\u200B`, 'first')}${uselessS}${u(s(`ef`))}

`, + contentAfterEdit: `

ab${u(s(`cd`))}${s(`A${u(`B`, 'first')}C[]\u200B`, 'first')}${u(s(`ef`))}

`, }); }); it('should remove only underline decoration on a span', async () => { diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js index 20dee7d771f..92a8423f45b 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js @@ -530,7 +530,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

abc[d]e

', + contentAfter: '

abc[d]e

', }); // BACKWARD await testEditor(BasicEditor, { @@ -538,7 +538,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

abc]d[e

', + contentAfter: '

abc]d[e

', }); }); it('should remove the link in the selected range in the middle of a link', async () => { @@ -548,7 +548,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

ab[c]de

', + contentAfter: '

ab[c]de

', }); // BACKWARD await testEditor(BasicEditor, { @@ -556,7 +556,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

ab]c[de

', + contentAfter: '

ab]c[de

', }); }); it('should remove the link in the selected range at the start of a link', async () => { @@ -584,7 +584,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

abc[de]f

', + contentAfter: '

abc[de]f

', }); // BACKWARD await testEditor(BasicEditor, { @@ -592,7 +592,7 @@ describe('Link', () => { stepFunction: async editor => { await unlink(editor); }, - contentAfter: '

abc]de[f

', + contentAfter: '

abc]de[f

', }); }); it('should remove the link in the selected range overlapping the start of a link', async () => {