From 367ec827fe98bb667d574fe804590197ca794edd Mon Sep 17 00:00:00 2001 From: dhba-odoo Date: Tue, 16 May 2023 09:36:10 +0000 Subject: [PATCH] [FIX] web_editor: shift paste of vs code content looses indentation Before this commit: when performing a shift paste of copied VS Code content, the indentation was lost. After this commit: Now, when you perform a shift paste of copied VS Code content, the indentation is preserved Task-2884491 closes odoo/odoo#136867 X-original-commit: 1641bb50aa30ac64340eb261b26d4706944299ba Signed-off-by: David Monjoie (dmo) --- .../src/js/editor/odoo-editor/src/OdooEditor.js | 11 ++++++++++- .../js/editor/odoo-editor/test/spec/copyPaste.test.js | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 1ae2ae8f8b7..64f40889735 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -4811,7 +4811,16 @@ export class OdooEditor extends EventTarget { const textFragments = splitAroundUrl[i].split(/\r?\n/); let textIndex = 1; for (const textFragment of textFragments) { - this._applyCommand('insert', textFragment); + // Replace consecutive spaces by alternating nbsp. + const modifiedTextFragment = textFragment.replace(/( {2,})/g, match => { + let alertnateValue = false; + return match.replace(/ /g, () => { + alertnateValue = !alertnateValue; + const replaceContent = alertnateValue ? '\u00A0' : ' '; + return replaceContent; + }); + }); + this._applyCommand('insert', modifiedTextFragment); if (textIndex < textFragments.length) { // Break line by inserting new paragraph and // remove current paragraph's bottom margin. diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js index 87cab3f1df9..f697cd3d90b 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js @@ -275,7 +275,7 @@ describe('Paste', () => { stepFunction: async editor => { await pasteText(editor, 'x y'); }, - contentAfter: '

abx y[]cd

', + contentAfter: '

abx    y[]cd

', }); }); it('should paste a text in a span', async () => { @@ -335,7 +335,7 @@ describe('Paste', () => { stepFunction: async editor => { await pasteText(editor, 'x y'); }, - contentAfter: '

ax y[]d

', + contentAfter: '

ax    y[]d

', }); }); it('should paste a text in a span', async () => {