2
2
'use strict'
3
3
4
4
import React from 'react'
5
+ import debounce from 'lodash/debounce'
5
6
import PropTypes from 'prop-types'
6
7
import { DecorationType } from '../utils/source-utils'
7
8
import { global_BackgroundColor_200 as globalBackground200 } from '@patternfly/react-tokens/dist/js/global_BackgroundColor_200'
@@ -32,8 +33,8 @@ class YamlEditor extends React.Component {
32
33
language : 'yaml' ,
33
34
height : '100%' ,
34
35
width : '100%' ,
36
+ theme : 'console' ,
35
37
options : {
36
- theme : 'console' ,
37
38
wordWrap : 'wordWrapColumn' ,
38
39
wordWrapColumn : 132 ,
39
40
wordWrapMinified : false ,
@@ -50,6 +51,7 @@ class YamlEditor extends React.Component {
50
51
editorWillMount : this . editorWillMount . bind ( this ) ,
51
52
onChange : onYamlChange ,
52
53
} ) ,
54
+ editorHasFocus : false ,
53
55
}
54
56
}
55
57
@@ -159,14 +161,31 @@ class YamlEditor extends React.Component {
159
161
}
160
162
} ) . bind ( this )
161
163
)
164
+
165
+ editor . onMouseDown (
166
+ debounce ( ( ) => {
167
+ const editorHasFocus = ! ! document . querySelector ( '.monaco-editor.focused' )
168
+ this . setState ( { editorHasFocus } )
169
+ } , 0 )
170
+ )
171
+
172
+ editor . onDidBlurEditorWidget ( ( ) => {
173
+ const editorHasFocus = ! ! document . querySelector ( '.monaco-editor.focused' )
174
+ const activeId = document . activeElement ?. id
175
+ if ( ! editorHasFocus && [ 'undo-button' , 'redo-button' ] . indexOf ( activeId ) === - 1 ) {
176
+ this . setState ( { editorHasFocus } )
177
+ }
178
+ } )
162
179
}
163
180
164
181
shouldComponentUpdate ( nextProps ) {
182
+ // if editor has focus, ignore form changes, since editor is doing all the changes
165
183
return (
166
- this . props . yaml !== nextProps . yaml ||
167
- this . props . hide !== nextProps . hide ||
168
- this . props . readOnly !== nextProps . readOnly ||
169
- this . props . showCondensed !== nextProps . showCondensed
184
+ ! this . state . editorHasFocus &&
185
+ ( this . props . yaml !== nextProps . yaml ||
186
+ this . props . hide !== nextProps . hide ||
187
+ this . props . readOnly !== nextProps . readOnly ||
188
+ this . props . showCondensed !== nextProps . showCondensed )
170
189
)
171
190
}
172
191
@@ -193,9 +212,9 @@ class YamlEditor extends React.Component {
193
212
{ editor &&
194
213
React . cloneElement ( editor , {
195
214
value : yaml ,
215
+ theme : 'console' ,
196
216
options : {
197
217
...this . state . editor . props . options ,
198
- theme : 'console' ,
199
218
wordWrapColumn : showCondensed ? 512 : 256 ,
200
219
minimap : {
201
220
enabled : ! showCondensed ,
0 commit comments