From a5046ab1da34a082b755fdc820ae41517f1c564b Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Wed, 6 Jul 2022 12:13:00 +0000 Subject: [PATCH] [FIX] web_editor: properly paste newlines on Windows Windows uses /r/n as newlines and the split parameter was not taking that into account, thus inserting the /r character. task-2742071 closes odoo/odoo#96422 X-original-commit: 90e565f811523968c297f0254f4aa7046c4e710e Signed-off-by: David Monjoie (dmo) --- .../js/editor/odoo-editor/src/OdooEditor.js | 2 +- .../odoo-editor/test/spec/copyPaste.test.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 b75941c0a4c..86d268687cd 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 @@ -3277,7 +3277,7 @@ export class OdooEditor extends EventTarget { } } } else if (splitAroundUrl[i] !== '') { - const textFragments = splitAroundUrl[i].split('\n'); + const textFragments = splitAroundUrl[i].split(/\r?\n/); let textIndex = 1; for (const textFragment of textFragments) { this.execCommand('insertText', textFragment); 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 71ba3e39669..fb0f90c5823 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 @@ -157,6 +157,26 @@ describe('Copy and paste', () => { contentAfter: '

abx[]cd

', }); }); + // TODO: We might want to have it consider \n as paragraph breaks + // instead of linebreaks but that would be an opinionated choice. + it('should paste text and understand \n newlines', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[]

', + stepFunction: async editor => { + await pasteText(editor, 'a\nb\nc\nd'); + }, + contentAfter: '

a
b
c
d[]

', + }); + }); + it('should paste text and understand \r\n newlines', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[]

', + stepFunction: async editor => { + await pasteText(editor, 'a\r\nb\r\nc\r\nd'); + }, + contentAfter: '

a
b
c
d[]

', + }); + }); }); describe('range not collapsed', async () => { it('should paste a text in a p', async () => {