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
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%>");
var manager = editor.get_CommandsManager();
var length = manager.getCommandsToUndo().length;
for (var i=0; i < length; i++)
{
manager.removeCommandAt(0);
}
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>