Skip to content

Commit

Permalink
fix: handle list in texteditor widget
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Nov 29, 2023
1 parent d91115d commit db0c167
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/config/Slate/extensions/breakList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const breakList = (editor) => {
editor.insertBreak = () => {
// If the selection does not exist or is expanded, handle with the default
// behavior.

if (!(editor.selection && Range.isCollapsed(editor.selection))) {
insertBreak();
return false;
Expand Down
27 changes: 20 additions & 7 deletions src/config/Slate/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getNextVoltoBlock,
getPreviousVoltoBlock,
createDefaultBlock,
getCurrentListItem,
} from '@plone/volto-slate/utils';
import config from '@plone/volto/registry';

Expand Down Expand Up @@ -107,6 +108,13 @@ const focusNext = (props) => {
onAddBlock,
index,
} = props.editor.getBlockProps();

const [listItem, listItemPath] = getCurrentListItem(props.editor);
if (listItem) {
//managed by breaklist extension
return true;
}

props.event.preventDefault();
props.event.stopPropagation();
let isAtEnd = false;
Expand Down Expand Up @@ -177,13 +185,18 @@ const handleBreak = (props) => {
} else {
let ret = softBreak(props);
if (!ret) {
props.event.preventDefault();
props.event.stopPropagation();
Editor.insertNode(props.editor, {
type: 'paragraph',
children: [{ text: '' }],
});
ret = true;
const [listItem, listItemPath] = getCurrentListItem(props.editor);
if (listItem) {
//managed by breaklist extension
} else {
props.event.preventDefault();
props.event.stopPropagation();
Editor.insertNode(props.editor, {
type: 'paragraph',
children: [{ text: '' }],
});
ret = true;
}
}
return ret;
}
Expand Down

0 comments on commit db0c167

Please sign in to comment.