[FIX] web_editor: fix newline bug in code sections
This commit fixes a bug that was occurring in the code sections when using Shift+Enter (soft return) for new lines. Steps to reproduce: - in a code section (a `<pre>` node) - write two or more lines separated with Shift+Enter - make the last line at least two characters long - place the cursor at the end of the section and press backspace, or before the last character of the section and press delete Example (in a code section): ABC DEF ^ cursor before or after "F" (for delete or backspace respectively) Unexpected behaviors: - an extra line is inserted before the current line - the cursor is teleported at the beginning of the current line The bug originated from method `enforceWhitespace` which iterates over the dom from the cursor's position. There, the conditions unintendedly allowed the iteration to pursue until a `BR` node was found, in which case a rule which should not have been enforced would add another `BR` node, which also had the side effect of teleporting the cursor. This commit adds a break statement such that if none of the "main" conditions are met in the first iteration, it is stopped right away instead. Meeting those conditions still allows the iteration to proceed as before. Not meeting any of those conditions only happened in code sections as far as we can tell, as they are explicitly excluded because of their lower-level management of spaces. Should other cases occur, they should have their own conditions added and not rely on a top-level "else-by-default" to continue the iteration indefinitely. task-3239097 closes odoo/odoo#119390 X-original-commit: e47c2eddb3b675324c181593a3243175a1095732 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -2374,6 +2374,8 @@ export function enforceWhitespace(el, offset, direction, rule) {
|
||||
} else if (!isWhitespace(node)) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user