[FIX] web_editor: save a historyStep upon cut
Before this commit, _onClipboardCut removed the selected text but did not register it as a history step. Other than not storing history properly, this caused unexpected behavior when followed by an action that leads to a historyRollback on the current step, such as those in _onInput. task-3142995 closes odoo/odoo#111927 X-original-commit: 451f1a2641b5b85ea75d9f1e8a8d1b528de031b6 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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: '<p>[]<br></p>',
|
||||
});
|
||||
});
|
||||
it('should cut selection and register it as a history step', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>a[bcd]e</p>',
|
||||
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: '<p>a[bcd]e</p>',
|
||||
});
|
||||
});
|
||||
it('should not restore cut content when cut followed by delete forward', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>a[]bcde</p>',
|
||||
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: '<p>a[]</p>',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user