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

[Feature request] Clear undo/redo history #792

Closed
AgentSmith0 opened this issue Mar 6, 2022 · 12 comments
Closed

[Feature request] Clear undo/redo history #792

AgentSmith0 opened this issue Mar 6, 2022 · 12 comments
Labels

Comments

@AgentSmith0
Copy link

Jodit Version: 3.15.2

Browser: All
OS: All
Is React App: False

Is there any way to clear the undo/redo history? If not, is it possible to implement this feature?

@ulfw
Copy link

ulfw commented Mar 7, 2022

I have implemented this as an event that is fired externally

    editor.events.on('editor.clearHistory', () => {
        editor.observer.stack.clear();
    });

@xdan xdan added the question label Mar 7, 2022
@AgentSmith0
Copy link
Author

Thanks @ulfw, unfortunately, this doesn't work always in my case: When I set the editor value via editor.value, clear the stack, change the editors text to another value and clear the stack again, the undo button still appears, but doesn't do anything.

@xdan xdan added the bug label Mar 7, 2022
@xdan
Copy link
Owner

xdan commented Mar 7, 2022

@AgentSmith0
Try that

editor.events.on('editor.clearHistory', () => {
        editor.observer.clear();
});

@AgentSmith0
Copy link
Author

@xdan Hm, still the same problem...

@ulfw
Copy link

ulfw commented Mar 7, 2022

I had the same problem when reloading page with cleared history, but clicking into the editor window disabled the undo/redo buttons. Maybe setting focus to th editor again will solve?

@xdan
Copy link
Owner

xdan commented Mar 7, 2022

@AgentSmith0 @ulfw The Observer module is asynchronous, i.e. it does not process the change immediately, but only processes the last one in n milliseconds. This is done so that, for example, words when you enter them get into the history of changes, and not every letter.
The observer interface does not have methods to hang a handler on a change. I'll think about how best to do it, but for now you can do a little hack

const editor = Jodit.make({
    observer: {
       timeout: 100
    }
});
editor.value = 'test';
editor.async.setTimeout(() => {
     editor.observer.clear();
}, 150);

@xdan
Copy link
Owner

xdan commented Mar 7, 2022

Maybe when called

editor.value = 'test1';
editor.value = 'test2';

the history handler must be called immediately

@xdan xdan removed the bug label Mar 7, 2022
xdan added a commit that referenced this issue Mar 7, 2022
…of changes will be process immediately,

    without a timeout.

Issue: #792
@xdan
Copy link
Owner

xdan commented Mar 7, 2022

@ulfw @AgentSmith0
Look at this release https://github.com/xdan/jodit/releases/tag/3.15.3

@AgentSmith0
Copy link
Author

AgentSmith0 commented Mar 7, 2022

I seems to fail only when a specific string is set as value before...
I need some time to look at this, but I think it is definitely better than before. It works on every "normal" case.
Thank you very much for the new release!

@xdan
Copy link
Owner

xdan commented Mar 8, 2022

@AgentSmith0 Can you show this specific string?

@AgentSmith0
Copy link
Author

AgentSmith0 commented Mar 9, 2022

Sorry, I tested again and the string value is not the problem. It seems to be still a timing problem... I will test this behaviour.

@AgentSmith0
Copy link
Author

AgentSmith0 commented Mar 17, 2022

I tried again with version 3.16.1 and it works fine now...
I don't really know the reason for this, but I will keep my eye on it.
Thank you very much!

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

No branches or pull requests

3 participants