diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/editor-test.html b/addons/web_editor/static/src/js/editor/odoo-editor/test/editor-test.html deleted file mode 100644 index c3e7b0cea36..00000000000 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/editor-test.html +++ /dev/null @@ -1,31 +0,0 @@ - - -
- - - - -a[]b
`, + stepFunction: async editor => { + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + }, + contentAfterEdit: `a${oeTab('32.8906px', false)}[]b
`, + contentAfter: `a${oeTab('32.8906px')}[]b
`, + }); + }); + it('should clear selection and insert a tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[xxx]b
`, + stepFunction: async editor => { + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + }, + contentAfterEdit: `a${oeTab('32.8906px', false)}[]b
`, + contentAfter: `a${oeTab('32.8906px')}[]b
`, + }); + }); + it('should insert two tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[]b
`, + stepFunction: async editor => { + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + }, + contentAfterEdit: `a${oeTab('32.8906px', false)}${oeTab('40px', false)}[]b
`, + contentAfter: `a${oeTab('32.8906px')}${oeTab()}[]b
`, + }); + }); + it('should insert two tab character with one char between', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[]b
`, + stepFunction: async editor => { + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + await insertText(editor,'a'); + await triggerEvent(editor.editable, 'keydown', { key: 'Tab'}); + }, + contentAfterEdit: `a${oeTab('32.8906px', false)}a${oeTab('32.8906px', false)}[]b
`, + contentAfter: `a${oeTab('32.8906px')}a${oeTab('32.8906px')}[]b
`, + }); + }); + }); + describe('delete backward Tabulation', () => { + it('should remove one tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]b
`, + stepFunction: async editor => { + await deleteBackward(editor); + }, + contentAfter: `a[]b
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}b
`, + stepFunction: async editor => { + await deleteBackward(editor); + }, + contentAfter: `a[]${oeTab('32.8906px')}b
`, + }); + }); + it('should remove two tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}${oeTab()}[]b
`, + stepFunction: async editor => { + await deleteBackward(editor); + await deleteBackward(editor); + }, + contentAfter: `a[]b
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}${oeTab()}[]${oeTab()}b
`, + stepFunction: async editor => { + await deleteBackward(editor); + await deleteBackward(editor); + }, + contentAfter: `a[]${oeTab('32.8906px')}b
`, + }); + }); + it('should remove three tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}${oeTab()}${oeTab()}[]b
`, + stepFunction: async editor => { + await deleteBackward(editor); + await deleteBackward(editor); + await deleteBackward(editor); + }, + contentAfter: `a[]b
`, + }); + }); + }); + describe('delete forward Tabulation', () => { + it('should remove one tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[]${oeTab('32.8906px')}b1
`, + stepFunction: async editor => { + await deleteForward(editor); + }, + contentAfter: `a[]b1
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}b2
`, + stepFunction: async editor => { + await deleteForward(editor); + }, + contentAfter: `a${oeTab('32.8906px')}[]b2
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a[]${oeTab('32.8906px')}${oeTab()}b3
`, + stepFunction: async editor => { + await deleteForward(editor); + }, + contentAfter: `a[]${oeTab('32.8906px')}b3
`, + }); + }); + it('should remove two tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[]${oeTab('32.8906px')}${oeTab()}b1
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteForward(editor); + }, + contentAfter: `a[]b1
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a[]${oeTab('32.8906px')}${oeTab()}${oeTab()}b2
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteForward(editor); + }, + contentAfter: `a[]${oeTab('32.8906px')}b2
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}${oeTab()}b3
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteForward(editor); + }, + contentAfter: `a${oeTab('32.8906px')}[]b3
`, + }); + }); + it('should remove three tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a[]${oeTab('32.8906px')}${oeTab()}${oeTab()}b
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteForward(editor); + await deleteForward(editor); + }, + contentAfter: `a[]b
`, + }); + }); + }); + describe('delete mixxed Tabulation', () => { + it('should remove all tab character', async () => { + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}b1
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteBackward(editor); + }, + contentAfter: `a[]b1
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}b2
`, + stepFunction: async editor => { + await deleteBackward(editor); + await deleteForward(editor); + }, + contentAfter: `a[]b2
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}${oeTab()}[]${oeTab()}b3
`, + stepFunction: async editor => { + await deleteBackward(editor); + await deleteForward(editor); + await deleteBackward(editor); + }, + contentAfter: `a[]b3
`, + }); + await testEditor(BasicEditor, { + contentBefore: `a${oeTab('32.8906px')}[]${oeTab()}${oeTab()}b4
`, + stepFunction: async editor => { + await deleteForward(editor); + await deleteBackward(editor); + await deleteForward(editor); + }, + contentAfter: `a[]b4
`, + }); + }); + }); +}); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js index a29a988c99c..ef5b4d8ea0c 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js @@ -264,8 +264,11 @@ export function renderTextualSelection() { */ export function customErrorMessage(assertLocation, value, expected) { const zws = '//zws//'; - value = value.replace('\u200B', zws); - expected = expected.replace('\u200B', zws); + value = value.replaceAll('\u200B', zws); + expected = expected.replaceAll('\u200B', zws); + const tab = '//TAB//'; + value = value.replaceAll('\u0009', tab); + expected = expected.replaceAll('\u0009', tab); return `[${assertLocation}]\nactual : '${value}'\nexpected: '${expected}'\n\nStackTrace `; } diff --git a/addons/web_editor/views/editor.xml b/addons/web_editor/views/editor.xml index 8b1ca8078d2..8fa05b0a832 100644 --- a/addons/web_editor/views/editor.xml +++ b/addons/web_editor/views/editor.xml @@ -175,14 +175,17 @@