-
Notifications
You must be signed in to change notification settings - Fork 22
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
Bug in wrapList() if selection is inside a table cell. #42
Comments
Thanks for filing the issue! I don't use tables, so I'm unlikely to spend a bunch of time looking into this, but if you have any ideas, I'm definitely open to a PR. |
The problem is this line in the wrapList funktion that doesn't choose the immetiate parant of the selection.
I'm yet not so familiar with all available select commands in SlateJS, but there is probably a better way to find the parent. Not sure what edge cases must be handled, and perhaps it's not obvious what should be a valid parent. |
I have tried re-writing the const isList = (blocks, block) =>
block.type == blocks.unordered_list || block.type == blocks.ordered_list;
export default ({ blocks }, editor, options = {}) => {
const type = options.type || blocks.unordered_list;
const blocksAtRange = editor.value.document
.getDescendantsAtRange(editor.value.selection)
.filter((node) => {
return node.object === 'text';
})
.map((node) => {
return editor.value.document.getClosestBlock(node.key);
})
.toSet()
.toList();
if (blocksAtRange.size > 0) {
const groupedByParent = blocksAtRange.reduce((agg, node) => {
const parent = editor.value.document.getParent(node.key);
return parent
? {
...agg,
[parent.key]: agg.hasOwnProperty(parent.key)
? [...agg[parent.key], ...[node]]
: [node],
}
: agg;
}, {});
editor.withoutNormalizing(() => {
Object.keys(groupedByParent).forEach((groupId) => {
groupedByParent[groupId].forEach((block) => {
if (isList(blocks, block)) return;
editor.wrapBlockByKey(block.key, type);
editor.wrapBlockByKey(block.key, blocks.list_item);
editor.setNodeByKey(block.key, blocks.list_item_child);
});
});
});
}
}; I figured we need all the text nodes' distinct parents in the selection (hence toSet > toList operation), group the blocks up by parent, and wrap them up. |
The whole table becomes a list item instead of the selection in the table cell.
Here is a CodeSandbox example: https://codesandbox.io/s/slate-1evfo
Perhaps I'm the only one using an online editor that allows editing of tables and lists inside of them :-O
The text was updated successfully, but these errors were encountered: