Skip to content
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

Undo replaces previous state if we delete an empty text #4554

Open
vinodgubbala opened this issue Jan 3, 2025 · 0 comments
Open

Undo replaces previous state if we delete an empty text #4554

vinodgubbala opened this issue Jan 3, 2025 · 0 comments

Comments

@vinodgubbala
Copy link

Please describe the a concise description and fill out the details below. It will help others efficiently understand your request and get to an answer instead of repeated back and forth. Providing a minimal, complete and verifiable example will further increase your chances that someone can help.

Steps for Reproduction

const quill = render(<Editor />
await userEvent.type(document.querySelector('.ql-editor'), 'foo');

// after a delay
await new Promise(res => setTimeout(res, 2000));
quill.deleteText(2, 0, 'user');
await userEvent.type(document.querySelector('.ql-editor'), 'abc');
expect(document.body).toHaveTextContent('foo'); //but the editor is empty

Expected behavior: To have text content "foo"

Actual behavior: But the text is empty

Platforms: Mac

Version: 2.0.3

In history.ts, we return if the delta is empty.
But the timestamp is still recorded. This makes the next record replace the previous stack.

}
} else {
this.lastRecorded = timestamp;
}
if (undoDelta.length() === 0) return;
this.stack.undo.push({ delta: undoDelta, range: undoRange });
// @ts-expect-error Fix me later

Moving this line

if (undoDelta.length() === 0) return;

above the if condition should fix it.

const timestamp = Date.now();
if (
// @ts-expect-error Fix me later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant