File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ import throttle from 'lodash/throttle';
33import { environment } from './environment' ;
44
55const maxHistory = 1000 ;
6- let past = [ ] ;
7- let now = undefined ;
8- let future = [ ] ;
6+ const past = [ ] ;
7+ const future = [ ] ;
8+ let now ;
99let timeTravelling = false ;
1010
1111export function initHistory ( ) {
@@ -43,13 +43,15 @@ function setCurrent() {
4343}
4444
4545const addHistory = ( ) => {
46- if ( ! timeTravelling ) {
46+ if ( timeTravelling ) {
47+ timeTravelling = false ;
48+ } else {
4749 console . log ( 'add history' ) ;
4850 now && past . push ( now ) ;
4951
5052 now = getCurrent ( ) ;
5153
52- future = [ ] ;
54+ future . splice ( 0 , future . length ) ;
5355
5456 if ( past . length >= maxHistory ) {
5557 past . shift ( ) ;
@@ -59,7 +61,6 @@ const addHistory = () => {
5961
6062export const undo = throttle ( ( ) => {
6163 timeTravelling = true ;
62- console . log ( true ) ;
6364
6465 if ( past . length ) {
6566 future . push ( now ) ;
@@ -68,9 +69,6 @@ export const undo = throttle(() => {
6869
6970 setCurrent ( ) ;
7071 }
71-
72- console . log ( false ) ;
73- timeTravelling = false ;
7472} , 100 ) ;
7573
7674export const redo = throttle ( ( ) => {
@@ -83,6 +81,4 @@ export const redo = throttle(() => {
8381
8482 setCurrent ( ) ;
8583 }
86-
87- timeTravelling = false ;
8884} , 100 ) ;
You can’t perform that action at this time.
0 commit comments