Marketplace products

Multiple Undo/Redo

Cost
Free
Version
1

Overview

This source code allows you to add multiple undo/redo to your text editor, while keeping full control over when to record events or not. The code also 'remembers' what type of edit occurred (i.e. delete text, paste text etc), and allows you to go back in multiple stages, like in Office 97. You can also specify the Undo limit, and clear its memory too! 

Comments

  1. 03 May 2002 at 18:31

    This code is excellent. Most people should find it simple to understand and very easy to integrate with an application.


    Found one bug. If you highlight a block of text, then press the TAB key, the text is properly replaced. However, you can't undo the action. This bug can be fixed as follows:


    In rtDoc_KeyPress(KeyAscii As Integer)


    Change this line:


       ElseIf KeyAscii >= 32 Or KeyAscii = 13 Then


    To this:
       
       ElseIf KeyAscii >= 32 Or KeyAscii = 13 Or KeyAscii = vbKeyTab Then


  2. 14 Feb 2002 at 19:20

    This is very useful code.  Thanks.  I fixed what seem to me to be a couple of bugs.


    Bug 1


    If the Delete key is used to delete the next character, status will not get updated.


    Fix For Bug 1


    In

    Code:
    RichTextBox1_KeyDown
    , after


           

    Code:
    .ModifyType = urDeleteText
           AddToUndoStack cUndo


    I added


           

    Code:
    UpdateStatus


    This is necessary because, if you just delete the next character, you have not changed the selection start point or the selection length (0), so

    Code:
    RichTextBox1_SelChange
    , which includes a call of Code:
    UpdateStatus
    , will not get triggered.


    Bug 2


    After a redo followed by an undo, the redo could not be done again.


    Maybe this is supposed to be a feature rather than a bug, but I think it is a bug:  that is not how Microsoft Word or the VB6 editor behave, and I do not want it to happen in my program.


    Fix For Bug 2


    Delete the following code.


    Code:
    Private Sub RichTextBox1_Change()
    If bRedoing Then
       bRedoing = False
       ClearStack RedoStack
    End If
    End Sub

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Multiple Undo/Redo.

Leave a comment

Sign in or Join us (it's free).