@@ -43,6 +43,7 @@ interface ICodeState {
4343export class Code extends React . Component < ICodeProps , ICodeState > {
4444 private subscriptions : monacoEditor . IDisposable [ ] = [ ] ;
4545 private lastCleanVersionId : number = 0 ;
46+ private editorRef : React . RefObject < MonacoEditor > = React . createRef < MonacoEditor > ( ) ;
4647
4748 constructor ( prop : ICodeProps ) {
4849 super ( prop ) ;
@@ -102,6 +103,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
102103 editorMounted = { this . editorDidMount }
103104 options = { options }
104105 openLink = { this . props . openLink }
106+ ref = { this . editorRef }
105107 />
106108 < div className = { waterMarkClass } > { this . getWatermarkString ( ) } </ div >
107109 </ div >
@@ -135,9 +137,11 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
135137 // Listen for model changes
136138 this . subscriptions . push ( editor . onDidChangeModelContent ( this . modelChanged ) ) ;
137139
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+ }
141145
142146 // Indicate we're ready
143147 this . props . onCreated ( this . props . code , model ! . id ) ;
@@ -203,8 +207,15 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
203207 return '' ;
204208 }
205209
210+ private isAutoCompleteOpen ( ) : boolean {
211+ if ( this . editorRef . current ) {
212+ return this . editorRef . current . isSuggesting ( ) ;
213+ }
214+ return false ;
215+ }
216+
206217 private arrowUp ( e : monacoEditor . IKeyboardEvent ) {
207- if ( this . state . editor && this . state . model ) {
218+ if ( this . state . editor && this . state . model && ! this . isAutoCompleteOpen ( ) ) {
208219 const cursor = this . state . editor . getPosition ( ) ;
209220 if ( cursor && cursor . lineNumber === 1 && this . props . history ) {
210221 const currentValue = this . getContents ( ) ;
@@ -220,7 +231,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
220231 }
221232
222233 private arrowDown ( e : monacoEditor . IKeyboardEvent ) {
223- if ( this . state . editor && this . state . model ) {
234+ if ( this . state . editor && this . state . model && ! this . isAutoCompleteOpen ( ) ) {
224235 const cursor = this . state . editor . getPosition ( ) ;
225236 if ( cursor && cursor . lineNumber === this . state . model . getLineCount ( ) && this . props . history ) {
226237 const currentValue = this . getContents ( ) ;
0 commit comments