1
- # Undo done the right way!
1
+ # Undo done the right way
2
2
3
- Via https://gitlab.com/okannen/undo_2/-/tree/b32c34edb2c15c266b946f0d82188624f3aa3fdc
3
+ Via [ original ] ( https://gitlab.com/okannen/undo_2/-/tree/b32c34edb2c15c266b946f0d82188624f3aa3fdc )
4
4
5
5
## Introduction
6
6
@@ -10,34 +10,33 @@ end of the Undo history as a precursor to your new change. I found the idea in
10
10
[ zaboople/klong] [ zaboople ] . This crate is an implementation
11
11
of this idea with a minor variation explained below.
12
12
13
- As an example consider the following sequence of commands:
13
+ As an example consider the following sequence of commands:
14
14
15
15
| Command | State |
16
16
| ------- | ----- |
17
- | Init | |
17
+ | Init | |
18
18
| Do A | A |
19
19
| Do B | A, B |
20
- | Undo | A |
21
- | Do C | A, C |
20
+ | Undo | A |
21
+ | Do C | A, C |
22
22
23
- With the ** classical undo** , repeated undo would lead to the sequence:
23
+ With the ** classical undo** , repeated undo would lead to the sequence:
24
24
25
25
| Command | State |
26
26
| ---------| -------|
27
27
| | A, C |
28
28
| Undo | A |
29
- | Undo | |
30
-
29
+ | Undo | |
31
30
32
- Starting from 5, with ** undo_2** , repeating undo would lead to the sequence:
31
+ Starting from 5, with ** undo_2** , repeating undo would lead to the sequence:
33
32
34
33
| Command | State |
35
34
| ---------| -------|
36
35
| | A, C |
37
36
| Undo | A |
38
- | Undo | A,B |
39
- | Undo | A |
40
- | Undo | |
37
+ | Undo | A,B |
38
+ | Undo | A |
39
+ | Undo | |
41
40
42
41
** undo_2** 's undo navigates back in history, while classical undo navigates back
43
42
through the sequence of command that builds the state.
@@ -53,11 +52,11 @@ and it is similar to vim :earlier.
53
52
4 . very lightweight, dumb and simple.
54
53
5 . possibility to merge and splice commands.
55
54
56
- ## How to use it
55
+ ## How to use it
57
56
58
57
Add the dependency to the cargo file:
59
58
60
- ``` [ toml]
59
+ ``` toml
61
60
[dependencies ]
62
61
undo_2 = " 0.1"
63
62
```
@@ -74,7 +73,7 @@ be interpreted by the application. This design pattern makes implementation
74
73
easier because it is not necessary to borrow data within the stored list of
75
74
commands.
76
75
77
- ```
76
+ ``` rs
78
77
use undo_2 :: {Commands ,Action };
79
78
use Action :: {Do ,Undo };
80
79
@@ -156,22 +155,22 @@ assert_eq!(editor.text, "a");
156
155
forming the sequence are merged. This makes the traversal of the undo
157
156
sequence more concise by avoiding state duplication.
158
157
159
- | Command | State | Comment |
158
+ | Command | State | Comment |
160
159
| ---------| ------- | ----------------------|
161
- | Init | | |
160
+ | Init | | |
162
161
| Do A | A | |
163
162
| Do B | A,B | |
164
163
| Do C | A, B, C | |
165
- | Undo | A, B | Merged |
166
- | Undo | A | Merged |
167
- | Do D | A, D | |
164
+ | Undo | A, B | Merged |
165
+ | Undo | A | Merged |
166
+ | Do D | A, D | |
168
167
| Undo | A | Redo the 2 Merged Undo|
169
- | Undo | A, B, C | |
170
- | Undo | A, B | |
171
- | Undo | A | |
172
- | Undo | | |
168
+ | Undo | A, B, C | |
169
+ | Undo | A, B | |
170
+ | Undo | A | |
171
+ | Undo | | |
173
172
174
- 2 . Each execution of an undos or redo may lead to the execution of a sequence of
173
+ 1 . Each execution of an undos or redo may lead to the execution of a sequence of
175
174
actions in the form ` Undo(a)+Do(b)+Do(c) ` . Basic arithmetic is implemented
176
175
assuming that ` Do(a)+Undo(a) ` is equivalent to not doing anything (here the
177
176
2 ` a ` 's designate the same entity, not to equal objects).
@@ -249,13 +248,14 @@ assert_eq!(editor.text, "az12");
249
248
```
250
249
251
250
## Release note
251
+
252
252
### Version 0.3
253
- - [ Action] is now an enum taking commands, the list of command to be
254
- executed is of the form [ Action<T >] ;
255
- - added [ Commands::can_undo] and [ Commands::can_redo] ;
256
- - added [ Commands::rebuild] , which correspond to the classical redo;
257
- - fixed a bug in [ Commands::undo_or_redo_to_index]
258
- - Added support for special commands that represent a state setting. See [ SetOrTransition] .
259
253
260
- [ zaboople ] : https://github.com/zaboople/klonk/blob/master/TheGURQ.md
254
+ - [ ` Action ` ] is now an enum taking commands, the list of command to be
255
+ executed is of the form [ ` Action<T> ` ] ;
256
+ - added [ ` Commands::can_undo ` ] and [ ` Commands::can_redo ` ] ;
257
+ - added [ ` Commands::rebuild ` ] , which correspond to the classical redo;
258
+ - fixed a bug in [ ` Commands::undo_or_redo_to_index ` ]
259
+ - Added support for special commands that represent a state setting. See [ ` SetOrTransition ` ] .
261
260
261
+ [ zaboople ] : https://github.com/zaboople/klonk/blob/master/TheGURQ.md
0 commit comments