Is there a way I can save and restore the cursor position?

Last post 04-03-2009, 10:58 AM by davinci0428. 2 replies.
Sort Posts: Previous Next
  •  04-02-2009, 5:24 PM 50735

    Is there a way I can save and restore the cursor position?

    I'd like to be able to read the HTML content into a buffer, modify the HTML, then put it back in the editor AND have the cursor at the same place, or as close as possible to where it was before the HTML changes were made. My problem is when I use the setHTML() method it always places the cursor at the end of the editor content. How can I put the cursor back where it was before the setHTML() method is executed?
  •  04-03-2009, 12:12 AM 50746 in reply to 50735

    Re: Is there a way I can save and restore the cursor position?

    davinci0428,
     
    Can you tell me why you don't use PasteHTML method. It will store the cursor position.
     
    PasteHTML()

    This method is used for pasting the specified HTML into a range within an editor document. If anything is selected, the selection is replaced with the new HTML and text.

    Example:

    // get the cute editor instance
    var editor1 = document.getElementById('CE_Editor1_ID);

    // pasting the specified HTML into a range within a editor document
    editor1.PasteHTML("Hello World");

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  04-03-2009, 10:58 AM 50760 in reply to 50746

    Re: Is there a way I can save and restore the cursor position?

    Thanks for the quick reply Adam.
     
    As you know, PasteHTML() places the content at the cursor location, or overwrites any selected content. I was hoping to use the CuteEditor_OnChange event to execute a custom HTML filter when any content changed, and do it on the fly while the user is typing. This means I need to get the entire HTML and filter it, not ask the user to select content then filter it, then put the entire HTML back in the editor and overwrite all the orignal HTML content in the process.
     
    The custom filter finds formatting problems that my CMS doesn't like and changes or removes them. Is there a better way to do what I need to do? My code now looks like this:
     
        function CuteEditor_OnChange(editor)
        {    
            // retrieve the content
            var content = editor.getHTML();

             // Filter the content
             content = custom_filter( content );

            // set the content
            editor.setHTML( content );
        }

    If I can't do the filtering on the fly, then my alternative is to run the custom filter when the content is previewed or saved.
     
    Thanks for any advice.
    Jeff
     
View as RSS news feed in XML