Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested blocks conversion to list #2934

Merged
merged 1 commit into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion addons/html_editor/static/src/editor/list/list_plugin.js
Expand Up @@ -4,7 +4,7 @@ import { Plugin } from "../plugin";
import { closestBlock, isBlock } from "../utils/blocks";
import { copyAttributes, removeClass, setTagName, toggleClass } from "../utils/dom";
import { isVisible } from "../utils/dom_info";
import { closestElement, getAdjacents } from "../utils/dom_traversal";
import { closestElement, descendants, getAdjacents } from "../utils/dom_traversal";
import { getTraversedBlocks } from "../utils/selection";
import { applyToTree, createList, getListMode, insertListAfter, mergeSimilarLists } from "./utils";

Expand Down Expand Up @@ -161,6 +161,13 @@ export class ListPlugin extends Plugin {
}
}

// Keep deepest blocks only.
for (const block of nonListBlocks) {
if (descendants(block).some((descendant) => nonListBlocks.has(descendant))) {
nonListBlocks.delete(block);
}
}

// Apply changes.
if (listsToSwitch.size || nonListBlocks.size) {
for (const list of listsToSwitch) {
Expand Down
34 changes: 34 additions & 0 deletions addons/html_editor/static/tests/editor/list/toggle_ul.test.js
Expand Up @@ -348,6 +348,40 @@ describe("Range not collapsed", () => {
'<ul><li>[ab</li></ul><p contenteditable="false">cd</p><ul><li>ef]</li></ul>',
});
});

test("should turn only the deepest blocks into lists", async () => {
await testEditor({
contentBefore: unformat(`
<div class="container o_text_columns">
<div class="row">
<div class="col-6">
<p>[<br></p>
</div>
<div class="col-6">
<p><br>]</p>
</div>
</div>
</div>
`),
stepFunction: toggleUnorderedList,
contentAfter: unformat(`
<div class="container o_text_columns">
<div class="row">
<div class="col-6">
<ul>
<li>[<br></li>
</ul>
</div>
<div class="col-6">
<ul>
<li>]<br></li>
</ul>
</div>
</div>
</div>
`),
});
});
});
describe("Remove", () => {
test("should turn a list into a paragraph", async () => {
Expand Down