@@ -43,6 +43,7 @@ interface ICodeState {
43
43
export class Code extends React . Component < ICodeProps , ICodeState > {
44
44
private subscriptions : monacoEditor . IDisposable [ ] = [ ] ;
45
45
private lastCleanVersionId : number = 0 ;
46
+ private editorRef : React . RefObject < MonacoEditor > = React . createRef < MonacoEditor > ( ) ;
46
47
47
48
constructor ( prop : ICodeProps ) {
48
49
super ( prop ) ;
@@ -102,6 +103,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
102
103
editorMounted = { this . editorDidMount }
103
104
options = { options }
104
105
openLink = { this . props . openLink }
106
+ ref = { this . editorRef }
105
107
/>
106
108
< div className = { waterMarkClass } > { this . getWatermarkString ( ) } </ div >
107
109
</ div >
@@ -135,9 +137,11 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
135
137
// Listen for model changes
136
138
this . subscriptions . push ( editor . onDidChangeModelContent ( this . modelChanged ) ) ;
137
139
138
- // List for key up/down events.
139
- this . subscriptions . push ( editor . onKeyDown ( this . onKeyDown ) ) ;
140
- this . subscriptions . push ( editor . onKeyUp ( this . onKeyUp ) ) ;
140
+ // List for key up/down events if not read only
141
+ if ( ! this . props . readOnly ) {
142
+ this . subscriptions . push ( editor . onKeyDown ( this . onKeyDown ) ) ;
143
+ this . subscriptions . push ( editor . onKeyUp ( this . onKeyUp ) ) ;
144
+ }
141
145
142
146
// Indicate we're ready
143
147
this . props . onCreated ( this . props . code , model ! . id ) ;
@@ -203,8 +207,15 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
203
207
return '' ;
204
208
}
205
209
210
+ private isAutoCompleteOpen ( ) : boolean {
211
+ if ( this . editorRef . current ) {
212
+ return this . editorRef . current . isSuggesting ( ) ;
213
+ }
214
+ return false ;
215
+ }
216
+
206
217
private arrowUp ( e : monacoEditor . IKeyboardEvent ) {
207
- if ( this . state . editor && this . state . model ) {
218
+ if ( this . state . editor && this . state . model && ! this . isAutoCompleteOpen ( ) ) {
208
219
const cursor = this . state . editor . getPosition ( ) ;
209
220
if ( cursor && cursor . lineNumber === 1 && this . props . history ) {
210
221
const currentValue = this . getContents ( ) ;
@@ -220,7 +231,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
220
231
}
221
232
222
233
private arrowDown ( e : monacoEditor . IKeyboardEvent ) {
223
- if ( this . state . editor && this . state . model ) {
234
+ if ( this . state . editor && this . state . model && ! this . isAutoCompleteOpen ( ) ) {
224
235
const cursor = this . state . editor . getPosition ( ) ;
225
236
if ( cursor && cursor . lineNumber === this . state . model . getLineCount ( ) && this . props . history ) {
226
237
const currentValue = this . getContents ( ) ;
0 commit comments