Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/editor/src/core/is-document-visually-empty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const schema = new Schema({
globalContent: { group: 'block', atom: true },
container: { group: 'block', content: 'block+' },
image: { group: 'block', atom: true },
hardBreak: { group: 'inline', inline: true, selectable: false },
},
});

Expand Down Expand Up @@ -62,6 +63,25 @@ describe('isDocumentVisuallyEmpty', () => {
expect(isDocumentVisuallyEmpty(doc)).toBe(false);
});

it('returns false when paragraph contains only a hardBreak', () => {
const doc = schema.node('doc', null, [
schema.node('paragraph', null, [schema.node('hardBreak')]),
]);

expect(isDocumentVisuallyEmpty(doc)).toBe(false);
});

it('returns false when paragraph contains a hardBreak alongside text', () => {
const doc = schema.node('doc', null, [
schema.node('paragraph', null, [
schema.text('hello'),
schema.node('hardBreak'),
]),
]);

expect(isDocumentVisuallyEmpty(doc)).toBe(false);
});

it('considers just white spaces as not empty', () => {
const doc = schema.node('doc', null, [
schema.node('paragraph', null, [schema.text(' ')]),
Expand Down Expand Up @@ -110,6 +130,16 @@ describe('isDocumentVisuallyEmpty', () => {
expect(isDocumentVisuallyEmpty(doc)).toBe(false);
});

it('returns false when container holds a paragraph with only a hardBreak', () => {
const doc = schema.node('doc', null, [
schema.node('container', null, [
schema.node('paragraph', null, [schema.node('hardBreak')]),
]),
]);

expect(isDocumentVisuallyEmpty(doc)).toBe(false);
});

it('returns false when container holds an image node', () => {
const doc = schema.node('doc', null, [
schema.node('container', null, [schema.node('image')]),
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/core/is-document-visually-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ function hasOnlyEmptyParagraph(node: Node): boolean {
}

function isEmptyParagraph(node: Node): boolean {
return node.type.name === 'paragraph' && node.textContent.length === 0;
return node.type.name === 'paragraph' && node.childCount === 0;
}
Loading