From e6570693013bb334e4ed4947967e4dd75a7142ad Mon Sep 17 00:00:00 2001 From: sbbh-odoo Date: Wed, 17 Sep 2025 11:05:55 +0000 Subject: [PATCH] [FIX] html_editor: fix backward table selection in Firefox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to Reproduce: 1. Create a table in the editor (Firefox). 2. Select table cells backward (right → left or bottom → top). Before this commit: - The first selected cell does not remain selected in Firefox when extending the selection backward. After this commit: - Backward table cell selection works consistently in Firefox. task-5094832 X-original-commit: 2720b5368904ff07e3321d15327815000aab590c --- addons/html_editor/static/src/main/table/table_plugin.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/html_editor/static/src/main/table/table_plugin.js b/addons/html_editor/static/src/main/table/table_plugin.js index 3302d422e5b1a..c8f595104417d 100644 --- a/addons/html_editor/static/src/main/table/table_plugin.js +++ b/addons/html_editor/static/src/main/table/table_plugin.js @@ -581,14 +581,18 @@ export class TablePlugin extends Plugin { // To solve the issue we merge the ranges of the selection together the first time we find // selection.rangeCount > 1. Morover, when hitting a double click on a cell, it spans a row // inside selection which needs to be simplified here. - const [anchorNode, anchorOffset] = getDeepestPosition( + let [anchorNode, anchorOffset] = getDeepestPosition( selection.getRangeAt(0).startContainer, selection.getRangeAt(0).startOffset ); - const [focusNode, focusOffset] = getDeepestPosition( + let [focusNode, focusOffset] = getDeepestPosition( selection.getRangeAt(selection.rangeCount - 1).startContainer, selection.getRangeAt(selection.rangeCount - 1).startOffset ); + if (this.selectionDirection === "backward") { + [anchorNode, focusNode] = [focusNode, anchorNode]; + [anchorOffset, focusOffset] = [focusOffset, anchorOffset]; + } this.dependencies.selection.setSelection({ anchorNode, anchorOffset, @@ -611,6 +615,7 @@ export class TablePlugin extends Plugin { focusNode: ev.target, focusOffset: 0, }); + this.selectionDirection = selection.direction; return true; } }