Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const shouldCheckForHints = (code: string) =>
const MonacoStyleWrapper = styled.div`
height: 100%;
width: 100%;
overflow-x: auto;
.margin .margin-view-overlays {
margin-left: 10px;
Expand Down Expand Up @@ -91,7 +92,11 @@ const cypherEditorDefaultProps: CypherEditorDefaultProps = {
value: ''
}

type CypherEditorState = { currentHistoryIndex: number; draft: string }
type CypherEditorState = {
currentHistoryIndex: number
draft: string
isEditorFocusable: boolean
}
const UNRUN_CMD_HISTORY_INDEX = -1

export class CypherEditor extends React.Component<
Expand All @@ -100,15 +105,17 @@ export class CypherEditor extends React.Component<
> {
state: CypherEditorState = {
currentHistoryIndex: UNRUN_CMD_HISTORY_INDEX,
isEditorFocusable: true,
draft: ''
}
resizeObserver: ResizeObserver
editor?: monaco.editor.IStandaloneCodeEditor
container?: HTMLElement
wrapperRef = React.createRef<HTMLDivElement>()

constructor(props: CypherEditorProps) {
super(props)

this.wrapperRef = React.createRef()
// Wrapped in requestAnimationFrame to avoid the error "ResizeObserver loop limit exceeded"
this.resizeObserver = new ResizeObserver(() => {
window.requestAnimationFrame(() => {
Expand Down Expand Up @@ -391,6 +398,10 @@ export class CypherEditor extends React.Component<
this.props.onDisplayHelpKeys
)

this.editor.addCommand(KeyCode.Escape, () => {
this.wrapperRef.current?.focus()
})

keys(this.props.additionalCommands).forEach(key => {
const command = this.props.additionalCommands[key]
if (!command) {
Expand Down Expand Up @@ -435,6 +446,14 @@ export class CypherEditor extends React.Component<
<MonacoStyleWrapper
id={this.getMonacoId()}
className={this.props.className}
ref={this.wrapperRef}
tabIndex={-1}
onFocus={() => {
this.setState({ isEditorFocusable: false })
}}
onBlur={() => {
this.setState({ isEditorFocusable: true })
}}
/>
)
}
Expand All @@ -458,9 +477,9 @@ export class CypherEditor extends React.Component<
this.onContentUpdate()
}

if (tabIndex !== prevProps.tabIndex) {
this.editor?.updateOptions({ tabIndex: this.props.tabIndex })
}
this.editor?.updateOptions({
tabIndex: this.state.isEditorFocusable ? this.props.tabIndex : -1
})
}

componentWillUnmount = (): void => {
Expand Down
2 changes: 1 addition & 1 deletion src/neo4j-arc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neo4j-devtools/arc",
"version": "0.0.39",
"version": "0.0.40",
"main": "dist/neo4j-arc.js",
"author": "Neo4j Inc.",
"license": "GPL-3.0",
Expand Down