diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js
index efc9c0049cd..55121cb58b4 100644
--- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js
+++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js
@@ -403,7 +403,11 @@ export const editorCommands = {
const changedElements = [];
const defaultDirection = editor.options.direction;
const shouldApplyStyle = !isSelectionFormat(editor.editable, 'switchDirection');
- for (const block of new Set(selectedTextNodes.map(textNode => closestElement(textNode, 'ul,ol') || closestBlock(textNode)))) {
+ let blocks = new Set(selectedTextNodes.map(textNode => closestElement(textNode, 'ul,ol') || closestBlock(textNode)));
+ blocks.forEach(block => {
+ blocks = [...blocks, ...block.querySelectorAll('ul,ol')];
+ })
+ for (const block of blocks) {
if (!shouldApplyStyle) {
block.removeAttribute('dir');
} else {
diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js
index 8bd7e368438..398dd24c0da 100644
--- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js
+++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js
@@ -16,6 +16,7 @@ import {
toggleUnorderedList,
triggerEvent,
unformat,
+ switchDirection
} from '../utils.js';
describe('List', () => {
@@ -8434,4 +8435,94 @@ describe('List', () => {
});
});
});
+ describe('switchDirection', () => {
+ describe('switch direction form left to right', () => {
+ it('should properly switch the direction of the single level list (ltr).', async () => {
+ await testEditor(BasicEditor, {
+ contentBefore: `
`,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ contentBefore: `- a
- b[]
- c
`,
+ stepFunction: switchDirection,
+ contentAfter: `- a
- b[]
- c
`,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ });
+ it('should properly switch the direction of nested list (ltr).', async () => {
+ await testEditor(BasicEditor, {
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ contentBefore: `- a[]
- b
- c
- d
`,
+ stepFunction: switchDirection,
+ contentAfter: `- a[]
- b
- c
- d
`,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ });
+ });
+ describe('switch direction form right to left', () => {
+ it('should properly switch the direction of the single level list (rtl).', async () => {
+ await testEditor(BasicEditor, {
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ contentBefore: `- a
- b[]
- c
`,
+ stepFunction: switchDirection,
+ contentAfter: `- a
- b[]
- c
`,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ });
+ it('should properly switch the direction of nested list (rtl).', async () => {
+ await testEditor(BasicEditor, {
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ contentBefore: `- a[]
- b
- c
- d
`,
+ stepFunction: switchDirection,
+ contentAfter: `- a[]
- b
- c
- d
`,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ await testEditor(BasicEditor, {
+ removeCheckIds: true,
+ contentBefore: ``,
+ stepFunction: switchDirection,
+ contentAfter: ``,
+ });
+ });
+ });
+ });
});
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 c1e2cc99661..c7f3ca992a7 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
@@ -521,6 +521,10 @@ export async function insertParagraphBreak(editor) {
editor.execCommand('oEnter');
}
+export async function switchDirection(editor) {
+ editor.execCommand('switchDirection');
+}
+
export async function insertLineBreak(editor) {
editor.execCommand('oShiftEnter');
}