@@ -11,19 +11,22 @@ describe('<Editor />', () => {
11
11
return aceEditor . instance ( ) . editor as any ;
12
12
} ;
13
13
14
- const execCommandBoundTo = ( aceEditor : any , key : string ) : void => {
14
+ const execCommandBoundTo = (
15
+ aceEditor : any ,
16
+ key : { win : string ; mac : string }
17
+ ) : void => {
15
18
const commands = Object . values ( aceEditor . commands . commands ) ;
16
- const command : any = commands . find ( ( { bindKey } ) => {
19
+ const command : any = commands . find ( ( { name , bindKey } ) => {
17
20
if ( ! bindKey ) {
18
21
return false ;
19
22
}
20
-
21
- if ( typeof bindKey === 'string' ) {
22
- return key === bindKey ;
23
+ if ( name === 'gotoline' ) {
24
+ // Ignore gotoline - our command overrides.
25
+ return false ;
23
26
}
24
27
25
- const { win, mac } = bindKey as { win : string ; mac : string } ;
26
- return win === key && mac === key ;
28
+ const { win, mac } = bindKey as { win : string ; mac : string } ;
29
+ return win === key . win && mac === key . mac ;
27
30
} ) ;
28
31
29
32
if ( ! command ) {
@@ -58,7 +61,24 @@ describe('<Editor />', () => {
58
61
const aceEditor = getAceEditorInstance ( wrapper ) ;
59
62
expect ( spy ) . not . to . have . been . called ;
60
63
61
- execCommandBoundTo ( aceEditor , 'Return' ) ;
64
+ execCommandBoundTo ( aceEditor , {
65
+ win : 'Return' ,
66
+ mac : 'Return'
67
+ } ) ;
68
+ expect ( spy ) . to . have . been . calledOnce ;
69
+ } ) ;
70
+
71
+ it ( 'calls onClearCommand when command/ctrl+L is pressed' , ( ) => {
72
+ const spy = sinon . spy ( ) ;
73
+ const wrapper = mount ( < Editor onClearCommand = { spy } /> ) ;
74
+
75
+ const aceEditor = getAceEditorInstance ( wrapper ) ;
76
+
77
+ expect ( spy ) . not . to . have . been . called ;
78
+ execCommandBoundTo ( aceEditor , {
79
+ win : 'Ctrl-L' ,
80
+ mac : 'Command-L'
81
+ } ) ;
62
82
expect ( spy ) . to . have . been . calledOnce ;
63
83
} ) ;
64
84
@@ -69,7 +89,10 @@ describe('<Editor />', () => {
69
89
const aceEditor = getAceEditorInstance ( wrapper ) ;
70
90
71
91
expect ( spy ) . not . to . have . been . called ;
72
- execCommandBoundTo ( aceEditor , 'Up' ) ;
92
+ execCommandBoundTo ( aceEditor , {
93
+ win : 'Up' ,
94
+ mac : 'Up'
95
+ } ) ;
73
96
expect ( spy ) . to . have . been . calledOnce ;
74
97
} ) ;
75
98
@@ -82,7 +105,10 @@ describe('<Editor />', () => {
82
105
aceEditor . moveCursorToPosition ( { row : 1 , column : 0 } ) ;
83
106
aceEditor . clearSelection ( ) ;
84
107
85
- execCommandBoundTo ( aceEditor , 'Up' ) ;
108
+ execCommandBoundTo ( aceEditor , {
109
+ win : 'Up' ,
110
+ mac : 'Up'
111
+ } ) ;
86
112
expect ( spy ) . not . to . have . been . called ;
87
113
} ) ;
88
114
@@ -96,7 +122,10 @@ describe('<Editor />', () => {
96
122
aceEditor . clearSelection ( ) ;
97
123
98
124
expect ( spy ) . not . to . have . been . called ;
99
- execCommandBoundTo ( aceEditor , 'Down' ) ;
125
+ execCommandBoundTo ( aceEditor , {
126
+ win : 'Down' ,
127
+ mac : 'Down'
128
+ } ) ;
100
129
expect ( spy ) . to . have . been . calledOnce ;
101
130
} ) ;
102
131
@@ -107,7 +136,10 @@ describe('<Editor />', () => {
107
136
const aceEditor = getAceEditorInstance ( wrapper ) ;
108
137
aceEditor . setValue ( 'row 0\nrow 1' ) ;
109
138
110
- execCommandBoundTo ( aceEditor , 'Down' ) ;
139
+ execCommandBoundTo ( aceEditor , {
140
+ win : 'Down' ,
141
+ mac : 'Down'
142
+ } ) ;
111
143
expect ( spy ) . not . to . have . been . called ;
112
144
} ) ;
113
145
@@ -119,7 +151,10 @@ describe('<Editor />', () => {
119
151
aceEditor . setValue ( 'text' ) ;
120
152
aceEditor . selectAll ( ) ;
121
153
122
- execCommandBoundTo ( aceEditor , 'Up' ) ;
154
+ execCommandBoundTo ( aceEditor , {
155
+ win : 'Up' ,
156
+ mac : 'Up'
157
+ } ) ;
123
158
expect ( spy ) . not . to . have . been . called ;
124
159
} ) ;
125
160
@@ -131,7 +166,10 @@ describe('<Editor />', () => {
131
166
aceEditor . setValue ( 'text' ) ;
132
167
aceEditor . selectAll ( ) ;
133
168
134
- execCommandBoundTo ( aceEditor , 'Down' ) ;
169
+ execCommandBoundTo ( aceEditor , {
170
+ win : 'Down' ,
171
+ mac : 'Down'
172
+ } ) ;
135
173
expect ( spy ) . not . to . have . been . called ;
136
174
} ) ;
137
175
0 commit comments