flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Any thoughts on implementing undo/redo in an editor?

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 720
A while back, I posted an example of a calculator with a simple one-dimensional editor. Now, I am working on a two-dimensional editor and am wondering how one might implement redo/undo.

Specifically, if the user types "hello", we do not want this to become 5 undoable actions, but would rather have these fused into a single undoable action.
Post 06 Aug 2018, 12:52
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7003
Location: Kraków, Poland
You can look at the fedit sources as an example of one possible approach. Usually any editing operation makes a new undo point (with "store_status_for_undo" function), but if there are several letters typed in succession, they do not make new points, they just add to the existing one (with "store_segment_for_undo").

There are also some other specific commands, like backspace, that are grouped this way. Using any other command, even one that does not edit text (like arrow keys) breaks the sequence and causes the next character (or backspace etc.) to make a new undo point.
Post 06 Aug 2018, 13:42
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 720
It sounds like the undo buffer would then contain whole lines? For 1D sources the text is usually broken into many short (~80 char) lines. However, for 2D sources this is not the case and storing whole "lines" would become too expensive.
Post 07 Aug 2018, 06:11
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7003
Location: Kraków, Poland
No, fedit breaks lines into segments, too. Though insertion/deletion is not handled very well.
Post 07 Aug 2018, 06:16
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 720
So then what do you think is a good way to handle it?
In a 1D source we might have
Code:
a+b/(c+d/e)+f    

and it is just a 1D array of chars. For example the position of the "d" is simply 7. The basic operations could be something like
1. insert m characters at position n
2. delete m characters from position n
3. move m characters from position n1 to position n2


In a 2D source, we now have
Code:
      b
a + ----- + f
        d
    c + -
        e
    

stored in a tree something like
Code:
0: ROW
    0: a
    1: +
    2: FRAC
       0: ROW
            0: b
       1: ROW
            0: c
            1: +
            2: FRAC
                0: ROW
                    0: d
                1: ROW
                    0: e

    3: f
    

The address of the "d" is now 0,2,1,2,0,0
Post 21 Aug 2018, 10:22
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1318
Maybe if nothing was written for half a second, place what was written until last undo point into the undo history. Exceptions would be stuff like backspace (or moving the cursor) I guess, which might always have to create an undo point? (unless in succession, same rule as above)
Post 21 Aug 2018, 14:43
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 356
Location: ukraina
tthsqe, from personal experience i recommend you plug-in fedit and focus on the main dev line except you are planing inclusion of multiline math symbols
Post 26 Aug 2018, 15:22
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.