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

How to clear undo/redo history #900

Open
jagaxa opened this issue Aug 22, 2022 · 2 comments
Open

How to clear undo/redo history #900

jagaxa opened this issue Aug 22, 2022 · 2 comments
Milestone

Comments

@jagaxa
Copy link

jagaxa commented Aug 22, 2022

I'm currently using the undo plugin. Is there any way to clear the undo history after I empty the editor using .val("")?

If not, how can I implement something like

	function clear() {
		undoStates = []
	}
	sceditor.plugins.undo.clear = clear;
}(sceditor));
@jagaxa jagaxa changed the title How to clear undo history How to clear undo/redo history Aug 22, 2022
@samclarke
Copy link
Owner

This should really be part of the undo plugin so I'll leave this issue open.

For now, adding a method to the editor in the undo plugin init should work. Something like:

editor.clearUndo = function () {
  undoStates = [];
  redoPosition = 0;
  storeState();
};

Full file: https://gist.github.com/samclarke/4a53460692a0d8ecc55eadca861dbd57

Can then be called with:

instance.clearUndo();

@samclarke samclarke added this to the v3.2.0 milestone Aug 22, 2022
@huanacaraz
Copy link

I suggest also to add support to undo/redo commands (the translations already contains those keywords even if not used..)
I did it this way:

  1. modify the toolbar icons image - add undo and redo image (to the end...)

  2. modify the css - add icon definitions for the buttons:
    .sceditor-button-undo div{background-position:0 -659px} .sceditor-button-redo div{background-position:0 -675px}

  3. add this line to main plugin function: (just after "var base = this;")
    var utils = sceditor.utils;

  4. added this code to the plugin init method:
    ` var commands = this.commands;

     	commands.undo = utils.extend(commands.undo || {}, {
     		state: function () {
     			return redoPosition < undoStates.length - 1 ? 0 : -1;
     		},
     		exec: function () {
     			base.undo();
     		},
     		tooltip: 'Undo'
     	});
    
     	commands.redo = utils.extend(commands.redo || {}, {
     		state: function () {
     			return redoPosition > 0 ? 0 : -1;
     		},
     		exec: function () {
     			base.redo();
     		},
     		tooltip: 'Redo'
     	});
     	
     	editor.resetUndo = function() {
     		undoStates = [];
     		redoPosition = 0;
     		storeState();
     	}
    

`

@samclarke samclarke modified the milestones: v3.2.0, v3.3.0 Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants