This is a migrated thread and some comments may be shown as answers.

Add to Undo Stack

2 Answers 20 Views
Documentation and Tutorials
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 24 May 2016, 07:08 PM

Hello,

I am writing a number of custom shortcut commands activated by button clicks.  While the commands are firing properly, most of them are not being recognized in the undo stack - i.e. user cannot press the undo button to reverse the command.  When they do press it, they undo a command prior to running the custom command, stepping back to a document version they were not expecting.  My question is, how do I have the undo stack recognize my custom commands and allow the user to undo them?  Here's an example of a function with this issue.

            Telerik.Web.UI.Editor.CommandList["DoubleBottomBorder"] = function(commandName, editor, args) {
                         var elem = editor.getSelectedElement();
                         elem.style.borderBottom = "3px double #000000";
            };

Most of my functions are setting the style attribute of an element and are not using the pasteHtml() method (use of pasteHTML() method seems to work fine with the undo function).

Thanks,

Andrew

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 27 May 2016, 08:10 AM
Hi Andrew,

To add a custom command to Undo stack, you should initialize a RadEditor's GenericCommand before your command logic and execute it after that. Here is an example for the DoubleBottomBorder command:
Telerik.Web.UI.Editor.CommandList["DoubleBottomBorder"] = function(commandName, editor, args) {
    var command = new Telerik.Web.UI.Editor.GenericCommand(commandName, editor.get_contentWindow(), editor);
     
     var elem = editor.getSelectedElement();
     elem.style.borderBottom = "3px double #000000";
      
     editor.executeCommand(command);
};


Regards,
Nikolay
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Andrew
Top achievements
Rank 1
answered on 27 May 2016, 11:55 PM
Works like a charm, thank you!
Tags
Documentation and Tutorials
Asked by
Andrew
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or