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

Client-side management of undo stack?

3 Answers 122 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Mark Davis
Top achievements
Rank 1
Mark Davis asked on 08 Apr 2008, 11:27 PM
When a user begins an edit operation, we set the appropriate content by calling set_Html on the client. However, this action appears in the Undo dropdown. Is there a way to clear the Undo stack, or prevent the set_Html call from adding to the Undo stack?

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 09 Apr 2008, 10:13 AM
Hi Mark,

Here is the requested example demonstrating how to reset the Undo list of RadEditor "Prometheus":

<telerik:radeditor runat="server" ID="RadEditor1"></telerik:radeditor>
<div onclick="SetContent(this);" id="Div1">sample content DIV 1</div>
<div onclick="SetContent(this);" id="Div2">sample content DIV 2</div>
<script type="text/javascript">
function SetContent(oDiv)
{
    var editor = $find("<%=RadEditor1.ClientID%>");
  
    editor.get_CommandsManager()._clearCommandsToRedo();

    var manager = editor.get_CommandsManager();
    var length = manager.getCommandsToUndo().length;
    for (var i=0; i < length; i++)
    {
        manager.removeCommandAt(0);
    }

   editor.get_Document().body.innerHTML = oDiv.innerHTML;
}
</script>



Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tad Orman
Top achievements
Rank 1
answered on 20 Oct 2008, 08:53 PM
Hello Rumen,

There is a side-effect here that the Undo button will remain enabled even though there is an empty undo stack.

I can work around this problem by calling the "Undo" command:

editor.fire("Undo");

This has the side-effect of setting focus to the control, which I may not want.
0
Tervel
Telerik team
answered on 22 Oct 2008, 08:33 AM
Hello Tad,

Having all that you mention in mind, the originally provided code can be rewritten in a much simple manner, yet still fullfilling your needs. Here is how

<script>
function OnClientLoad(editor)
{         
   //Set content into the editor without logging it into the Undo/Redo, and without gaining focus
   editor.get_document().body.innerHTML = "Some content";
  
   //Raise selection change event that will update the Undo/Redo buttons (which will be disabled, since no commands are in the stack
   editor.raiseEvent("selectionChange"); 
}
</script>


<telerik:radeditor runat="server" ID="RadEditor1"
  OnClientLoad = "OnClientLoad"

Greetings,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Mark Davis
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Tad Orman
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or