From 9b40507c01677b4293794c8a7afd9880f60f8abd Mon Sep 17 00:00:00 2001 From: maad-odoo Date: Fri, 11 Aug 2023 11:22:54 +0000 Subject: [PATCH] [FIX] web_editor: checkbox direction does not switched for nested checklist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: When creating a nested checklist within another checklist and subsequently changing the direction of the parent list, the direction of the parent element would reverse alongside the pseudo element. However, in the case of nested checklists, only the content's direction would change, while the pseudo element's direction remained unaffected. Afte this commit: When altering the direction of the parent checklist's content, both the content itself and the associated pseudo element's direction is changed alongwith the nested checklist. task-3461806 closes odoo/odoo#152890 X-original-commit: f46e1f0c5b00f2e289feef5e35f3fea6fb477104 Signed-off-by: Geelen Sébastien (sge) --- .../odoo-editor/src/commands/commands.js | 6 +- .../editor/odoo-editor/test/spec/list.test.js | 91 +++++++++++++++++++ .../src/js/editor/odoo-editor/test/utils.js | 4 + 3 files changed, 100 insertions(+), 1 deletion(-) 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: `
  1. a
  2. b[]
  3. c
`, + stepFunction: switchDirection, + contentAfter: `
  1. a
  2. b[]
  3. 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: `
  1. a[]
    1. b
    2. c
  2. d
`, + stepFunction: switchDirection, + contentAfter: `
  1. a[]
    1. b
    2. c
  2. 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: `
  1. a
  2. b[]
  3. c
`, + stepFunction: switchDirection, + contentAfter: `
  1. a
  2. b[]
  3. 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: `
  1. a[]
    1. b
    2. c
  2. d
`, + stepFunction: switchDirection, + contentAfter: `
  1. a[]
    1. b
    2. c
  2. 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'); }