From b4a7e5333fc4dd2ea91d175037b5a82ced3b1c0b Mon Sep 17 00:00:00 2001 From: Deependra Solanki Date: Fri, 3 Nov 2023 14:36:00 +0530 Subject: [PATCH] [FIX] web_editor: fix rollback on pasting using ctrl+shift+v MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: When pasting using CTRL+SHIFT+V, if the textFragment includes linebreak(\n), each textFragment is divided, and each seperated fragment is inserted using `insert` command, followed by `oEnter` command. However, when `oEnter` is UNBREAKABLE, the inserted text is ROLLBACKED. After this commit: We now check whether the anchorNode's closestBlock is UNBREAKABLE. If so use `oShiftEnter` command; otherwise, use `oEnter` command which avoids ROLLBACK. task-3563785 closes odoo/odoo#151911 X-original-commit: f1e35ca82cf72ffb21c586d9bf1714bb388fe257 Signed-off-by: Geelen Sébastien (sge) --- .../js/editor/odoo-editor/src/OdooEditor.js | 8 +++++--- .../odoo-editor/test/spec/copyPaste.test.js | 18 ++++++++++++++++++ 2 files changed, 23 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 45cce837350..1f836e8242a 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 @@ -79,6 +79,7 @@ import { getFontSizeDisplayValue, rightLeafOnlyNotBlockPath, lastLeaf, + isUnbreakable, } from './utils/utils.js'; import { editorCommands } from './commands/commands.js'; import { Powerbox } from './powerbox/Powerbox.js'; @@ -4983,10 +4984,11 @@ export class OdooEditor extends EventTarget { // Break line by inserting new paragraph and // remove current paragraph's bottom margin. const p = closestElement(sel.anchorNode, 'p'); - if (this._applyCommand('oEnter') === UNBREAKABLE_ROLLBACK_CODE) { + if (isUnbreakable(closestBlock(sel.anchorNode))) { this._applyCommand('oShiftEnter'); - } else if (p) { - p.style.marginBottom = '0px'; + } else { + this._applyCommand('oEnter'); + p && (p.style.marginBottom = '0px'); } } textIndex++; 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 0fa2d8a6315..770f59c60d7 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 @@ -406,6 +406,24 @@ describe('Paste', () => { '

d[]

', }); }); + it('should paste text and understand \\n newlines within UNBREAKABLE node', 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 \\n newlines within UNBREAKABLE node(2)', async () => { + await testEditor(BasicEditor, { + contentBefore: '
a[]
', + stepFunction: async editor => { + await pasteText(editor, 'b\nc\nd'); + }, + contentAfter: '
ab
c
d[]
', + }); + }); }); describe('range not collapsed', async () => { it('should paste a text in a p', async () => {