flat assembler
Message board for the users of flat assembler.
  
       
      Index
      > Main > Any thoughts on implementing undo/redo in an editor? | 
  
| Author | 
  | 
              
| 
                  
                   tthsqe 06 Aug 2018, 12:52 
                  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.  | 
              |||
                  
  | 
              
| 
                  
                   tthsqe 07 Aug 2018, 06:11 
                  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. 
                  
                 | 
              |||
                  
  | 
              
| 
                  
                   Tomasz Grysztar 07 Aug 2018, 06:16 
                  No, fedit breaks lines into segments, too. Though insertion/deletion is not handled very well. 
                  
                 | 
              |||
                  
  | 
              
| 
                  
                   tthsqe 21 Aug 2018, 10:22 
                  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  | 
              |||
                  
  | 
              
| 
                  
                   Furs 21 Aug 2018, 14:43 
                  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) 
                  
                 | 
              |||
                  
  | 
              
| 
                  
                   idle 26 Aug 2018, 15:22 
                  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 
                  
                 | 
              |||
                  
  | 
              
< Last Thread | Next Thread >  | 
    
Forum Rules: 
  | 
    
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.