Skip to content

Commit

Permalink
[FIX] html_editor: traceback when pressing enter in unsplittable block
Browse files Browse the repository at this point in the history
Steps to Reproduce:

1. Navigate to Project.
2. Open Studio and go to Reports -> Timesheets Report.
3. Place the cursor before the text "Expression" and press Enter.
4. Next, place the cursor before the text "Name" and press Enter.
5. A traceback occurs.

Before this commit:

When pressing Enter with the cursor inside an unsplittable block,
instead of creating a new tag, the `insertLineBreakElement`is called
which adds a `<br>` and returns `undefined`. Consequently, in
`handleSplitBlockHeading`, `newElement` is `undefined`, leading
to a traceback when attempting to access its `tagName`.

After this commit:

The traceback no longer occurs when pressing Enter in an unsplittable block.

task-4334925

closes odoo#188905

X-original-commit: ef976bd
Signed-off-by: David Monjoie (dmo) <[email protected]>
Signed-off-by: Adnan Chaudhary (adch) <[email protected]>
  • Loading branch information
adch-odoo committed Nov 28, 2024
1 parent f9b91ec commit 114ad34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/html_editor/static/src/main/font/font_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export class FontPlugin extends Plugin {
// @todo @phoenix: if this condition can be anticipated before the split,
// handle the splitBlock only in such case.
if (
newElement &&
headingTags.includes(newElement.tagName) &&
!descendants(newElement).some(isVisibleTextNode)
) {
Expand Down
22 changes: 22 additions & 0 deletions addons/html_editor/static/tests/insert/paragraph_break.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { press } from "@odoo/hoot-dom";
import { tick } from "@odoo/hoot-mock";
import { testEditor } from "../_helpers/editor";
import { insertText, splitBlock } from "../_helpers/user_actions";
import { unformat } from "../_helpers/format";
import { MAIN_PLUGINS } from "@html_editor/plugin_sets";
import { QWebPlugin } from "@html_editor/others/qweb_plugin";

describe("Selection collapsed", () => {
describe("Basic", () => {
Expand Down Expand Up @@ -89,6 +92,25 @@ describe("Selection collapsed", () => {
contentAfter: `<p>abc<a href="#" title="document" data-mimetype="application/pdf" class="o_image"></a></p><p>[]<br></p>`,
});
});
test("should not split block with conditional template", async () => {
await testEditor({
contentBefore: unformat(`
<h1 t-if="true">
<t t-out="Hello"></t>
[]<t t-out="World"></t>
</h1>
`),
stepFunction: splitBlock,
contentAfter: unformat(`
<h1 t-if="true">
<t t-out="Hello"></t>
<br>
[]<t t-out="World"></t>
</h1>
`),
config: { Plugins: [...MAIN_PLUGINS, QWebPlugin] },
});
});
});

describe("Pre", () => {
Expand Down

0 comments on commit 114ad34

Please sign in to comment.