mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
Removing the first node from the pasted slice kept the original open depths, which are no longer valid for the remaining content. When the clipboard held a single top-level node the content became empty while openEnd stayed above zero, and ProseMirror walked into a null child. Fixes OUTLINE-CLOUD-51V
29 lines
805 B
TypeScript
29 lines
805 B
TypeScript
import { Slice } from "prosemirror-model";
|
|
|
|
/**
|
|
* Removes the first top-level node from a slice. The open depths are clamped to
|
|
* the remaining content, as the removed node may have been the one that they
|
|
* referred to.
|
|
*
|
|
* @param slice the slice to remove the first node from.
|
|
* @returns a new slice, or undefined if no content remains.
|
|
*/
|
|
export function sliceWithoutFirstNode(slice: Slice): Slice | undefined {
|
|
const { firstChild } = slice.content;
|
|
if (!firstChild) {
|
|
return undefined;
|
|
}
|
|
|
|
const content = slice.content.cut(firstChild.nodeSize);
|
|
if (content.childCount === 0) {
|
|
return undefined;
|
|
}
|
|
|
|
const maxOpen = Slice.maxOpen(content);
|
|
return new Slice(
|
|
content,
|
|
Math.min(slice.openStart, maxOpen.openStart),
|
|
Math.min(slice.openEnd, maxOpen.openEnd)
|
|
);
|
|
}
|