@@ -37,6 +37,7 @@ const shouldCheckForHints = (code: string) =>
3737const MonacoStyleWrapper = styled . div `
3838 height: 100%;
3939 width: 100%;
40+ overflow-x: auto;
4041
4142 .margin .margin-view-overlays {
4243 margin-left: 10px;
@@ -91,7 +92,11 @@ const cypherEditorDefaultProps: CypherEditorDefaultProps = {
9192 value : ''
9293}
9394
94- type CypherEditorState = { currentHistoryIndex : number ; draft : string }
95+ type CypherEditorState = {
96+ currentHistoryIndex : number
97+ draft : string
98+ isEditorFocusable : boolean
99+ }
95100const UNRUN_CMD_HISTORY_INDEX = - 1
96101
97102export class CypherEditor extends React . Component <
@@ -100,15 +105,17 @@ export class CypherEditor extends React.Component<
100105> {
101106 state : CypherEditorState = {
102107 currentHistoryIndex : UNRUN_CMD_HISTORY_INDEX ,
108+ isEditorFocusable : true ,
103109 draft : ''
104110 }
105111 resizeObserver : ResizeObserver
106112 editor ?: monaco . editor . IStandaloneCodeEditor
107113 container ?: HTMLElement
114+ wrapperRef = React . createRef < HTMLDivElement > ( )
108115
109116 constructor ( props : CypherEditorProps ) {
110117 super ( props )
111-
118+ this . wrapperRef = React . createRef ( )
112119 // Wrapped in requestAnimationFrame to avoid the error "ResizeObserver loop limit exceeded"
113120 this . resizeObserver = new ResizeObserver ( ( ) => {
114121 window . requestAnimationFrame ( ( ) => {
@@ -391,6 +398,10 @@ export class CypherEditor extends React.Component<
391398 this . props . onDisplayHelpKeys
392399 )
393400
401+ this . editor . addCommand ( KeyCode . Escape , ( ) => {
402+ this . wrapperRef . current ?. focus ( )
403+ } )
404+
394405 keys ( this . props . additionalCommands ) . forEach ( key => {
395406 const command = this . props . additionalCommands [ key ]
396407 if ( ! command ) {
@@ -435,6 +446,14 @@ export class CypherEditor extends React.Component<
435446 < MonacoStyleWrapper
436447 id = { this . getMonacoId ( ) }
437448 className = { this . props . className }
449+ ref = { this . wrapperRef }
450+ tabIndex = { - 1 }
451+ onFocus = { ( ) => {
452+ this . setState ( { isEditorFocusable : false } )
453+ } }
454+ onBlur = { ( ) => {
455+ this . setState ( { isEditorFocusable : true } )
456+ } }
438457 />
439458 )
440459 }
@@ -458,9 +477,9 @@ export class CypherEditor extends React.Component<
458477 this . onContentUpdate ( )
459478 }
460479
461- if ( tabIndex !== prevProps . tabIndex ) {
462- this . editor ?. updateOptions ( { tabIndex : this . props . tabIndex } )
463- }
480+ this . editor ?. updateOptions ( {
481+ tabIndex : this . state . isEditorFocusable ? this . props . tabIndex : - 1
482+ } )
464483 }
465484
466485 componentWillUnmount = ( ) : void => {
0 commit comments