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 4c399d37f58..cc32eaaf090 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 @@ -3266,7 +3266,9 @@ export class OdooEditor extends EventTarget { _onClipboardCut(clipboardEvent) { this._onClipboardCopy(clipboardEvent); + this._recordHistorySelection(); this.deleteRange(); + this.historyStep(); } _onClipboardCopy(clipboardEvent) { if (!this.isSelectionInEditable()) { 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 5b154395f16..5b5c7aae742 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 @@ -2,6 +2,7 @@ import { BasicEditor, testEditor, triggerEvent, + undo, } from "../utils.js"; import {CLIPBOARD_WHITELISTS} from "../../src/OdooEditor.js"; @@ -122,6 +123,33 @@ describe('Cut', () => { contentAfter: '

[]

', }); }); + it('should cut selection and register it as a history step', async () => { + await testEditor(BasicEditor, { + contentBefore: '

a[bcd]e

', + stepFunction: async editor => { + const historyStepsCount = editor._historySteps.length; + triggerEvent(editor.editable, 'cut', { clipboardData: new DataTransfer() }); + window.chai.expect(editor._historySteps.length).to.be.equal(historyStepsCount + 1); + undo(editor); + }, + contentAfter: '

a[bcd]e

', + }); + }); + it('should not restore cut content when cut followed by delete forward', async () => { + await testEditor(BasicEditor, { + contentBefore: '

a[]bcde

', + stepFunction: async editor => { + // Set selection to a[bcd]e. + const selection = editor.document.getSelection(); + selection.extend(selection.anchorNode, 4); + triggerEvent(editor.editable, 'cut', { clipboardData: new DataTransfer() }); + triggerEvent(editor.editable, 'input', { + inputType: 'deleteContentForward' + }); + }, + contentAfter: '

a[]

', + }); + }); }); });