Skip to content

Commit

Permalink
Fix deselecting lists. (#6080)
Browse files Browse the repository at this point in the history
Co-authored-by: Víctor Fernández de Alba <[email protected]>
  • Loading branch information
robgietema and sneridagh authored Jun 10, 2024
1 parent 4a2da78 commit f9e862a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/volto-slate/news/6080.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix removal of slate formatting applied to text when toggling the list buttons @robgietema
17 changes: 16 additions & 1 deletion packages/volto-slate/src/utils/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export const toggleBlock = (editor, format, allowedChildren) => {
} else if (!isListItem && !wantsList) {
toggleFormat(editor, format, allowedChildren);
} else if (isListItem && wantsList && isActive) {
clearFormatting(editor);
clearList(editor);
} else {
console.warn('toggleBlock case not covered, please examine:', {
wantsList,
Expand Down Expand Up @@ -298,6 +298,21 @@ export const switchListType = (editor, format) => {
Transforms.wrapNodes(editor, block);
};

/*
* Clear list by exploding the block
*/
export const clearList = (editor) => {
const { slate } = config.settings;
Transforms.unwrapNodes(editor, {
match: (n) => slate.listTypes.includes(n.type),
split: true,
});
Transforms.setNodes(editor, {
type: 'p',
});
Editor.normalize(editor);
};

export const changeBlockToList = (editor, format) => {
const { slate } = config.settings;
const [match] = Editor.nodes(editor, {
Expand Down

0 comments on commit f9e862a

Please sign in to comment.