Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
WIP on joining bold paragraph with previous block
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed Oct 18, 2021
1 parent 64f53a4 commit f765120
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/utils/volto-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ export function mergeSlateWithBlockBackward(editor, prevBlock, event) {
const source = pathRef.current;
const endPath = Editor.end(editor, [0]);

const prevv = Editor.previous(editor, { at: endPath, mode: 'all' });
const prevv = Editor.previous(editor, { at: endPath, mode: 'lowest' });
const [, prevPath] = prevv;
const commonPath = Path.common(source, prevPath);

const levels = Array.from(Editor.levels(editor, { at: source }), ([n]) => n)
const levels = Array.from(Editor.levels(editor, { at: [1] }), ([n]) => n)
.slice(commonPath.length)
.slice(0, -1);

// Determine if the merge will leave an ancestor of the path empty as a
// result, in which case we'll want to remove it after merging.
const emptyAncestor = Editor.above(editor, {
at: source,
at: [1],
mode: 'highest',
match: (n) => levels.includes(n) && hasSingleChildNest(editor, n),
});
Expand All @@ -97,16 +97,23 @@ export function mergeSlateWithBlockBackward(editor, prevBlock, event) {
at: source,
to: endPath.path,
mode: 'all',
match: matchPath(editor, source),
match: ((editor, source) => {
const [, path] = Editor.node(editor, source);
return (n, p) => {
return Path.isDescendant(path, p);
};
})(editor, source),
};

Transforms.moveNodes(editor, opts);
Editor.withoutNormalizing(editor, () => {
Transforms.moveNodes(editor, opts);

const emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
const emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);

if (emptyRef) {
Transforms.removeNodes(editor, { at: emptyRef.current });
}
if (emptyRef) {
Transforms.removeNodes(editor, { at: emptyRef.current });
}
});

const pp = pathRef.unref();

Expand Down

0 comments on commit f765120

Please sign in to comment.