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
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,23 @@ export class ProsemirrorAdapter {
return;
}

// Drop any pending debounced change so it cannot fire after this
// clear and resurrect the old content.
if (this.changeWaiting) {
this.changeEmitter.cancel();
this.changeWaiting = false;
}

const currentContent = this.contentConverter.serialize(
this.view,
this.schema
);
if (currentContent === '') {
// A pending change already reflects this empty content; let it
// emit so consumers still learn the document became empty.
return;
}

// Drop any pending debounced change so it cannot fire after this
// clear and resurrect the old content.
if (this.changeWaiting) {
this.changeEmitter.cancel();
this.changeWaiting = false;
}

await this.updateView('');
}

Expand Down
15 changes: 15 additions & 0 deletions src/components/text-editor/text-editor.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,20 @@ describe('limel-text-editor', () => {

expect(changes).toHaveLength(0);
});

test('clear on an already-empty editor keeps the pending empty change', async () => {
const { root, editor, changes } = await createEditor({
value: 'hello',
});

editor.focus();
document.execCommand('selectAll');
document.execCommand('delete');

await root.clear();
Comment on lines +356 to +359
await sleep(DEBOUNCE_WAIT);

expect(changes).toContain('');
});
});
});
Loading