@@ -40,17 +40,15 @@ export class WebUndo implements UndoManager, UiLifeCycles {
40
40
const activeElement = document . activeElement ;
41
41
try {
42
42
this . _push = true ;
43
- const style = el . style ;
44
- this . undo . push ( undo as UndoItem ) ;
45
43
this . redo = [ ] ;
46
44
el . setAttribute ( 'aria-hidden' , 'false' ) ;
47
- style . visibility = 'visible' ;
48
45
el . focus ( ) ;
49
- document . execCommand ?.( 'insertText' , false , '|' ) ;
46
+ document . execCommand ?.( 'insertText' , false , '.' ) ;
47
+ const tlen = this . el . innerText . length ;
48
+ if ( tlen - 1 === this . undo . length ) this . undo . push ( undo as UndoItem ) ;
50
49
} finally {
51
50
el . blur ( ) ;
52
51
this . _push = false ;
53
- // style.visibility = 'hidden';
54
52
el . setAttribute ( 'aria-hidden' , 'true' ) ;
55
53
( activeElement as HTMLElement ) ?. focus ?.( ) ;
56
54
}
@@ -64,15 +62,11 @@ export class WebUndo implements UndoManager, UiLifeCycles {
64
62
el . contentEditable = 'true' ;
65
63
el . setAttribute ( 'aria-hidden' , 'true' ) ;
66
64
const style = el . style ;
67
- // style.opacity = '0';
68
- style . position = 'fixed' ;
69
- // style.top = '-1000px';
70
- style . top = '10px' ;
71
- style . left = '10px' ;
72
65
style . pointerEvents = 'none' ;
73
- // style.fontSize = '2px';
74
- style . fontSize = '8px' ;
75
- // style.visibility = 'hidden';
66
+ style . position = 'fixed' ;
67
+ style . fontSize = '1px' ;
68
+ style . top = '-1000px' ;
69
+ style . opacity = '0' ;
76
70
document . body . appendChild ( el ) ;
77
71
el . addEventListener ( 'focus' , this . onFocus ) ;
78
72
el . addEventListener ( 'input' , this . onInput ) ;
@@ -86,14 +80,16 @@ export class WebUndo implements UndoManager, UiLifeCycles {
86
80
}
87
81
88
82
public readonly onFocus = ( ) => {
89
- setTimeout ( ( ) => this . el . blur ( ) , 0 ) ;
83
+ const el = this . el ;
84
+ setTimeout ( ( ) => el . blur ( ) , 0 ) ;
90
85
} ;
91
86
92
87
public readonly onInput = ( ) => {
93
88
const tlen = this . el . innerText . length ;
94
89
if ( ! this . _push ) {
95
- while ( this . undo . length && this . undo . length > tlen ) this . _undo ( ) ;
96
- while ( this . redo . length && this . undo . length < tlen ) this . _redo ( ) ;
90
+ const { undo, redo} = this ;
91
+ while ( undo . length && undo . length > tlen ) this . _undo ( ) ;
92
+ while ( redo . length && undo . length < tlen ) this . _redo ( ) ;
97
93
}
98
94
} ;
99
95
}
0 commit comments