-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ensure focus set back to active editor when dialog closed (#344)
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
import { getState } from '../../store'; | ||
import { shouldPrioritizeJsonEditor } from '../interface'; | ||
import { IEditorRefs } from './types'; | ||
|
||
export { EditorPane } from './components/editor-pane'; | ||
export { | ||
JsonEditorContextProvider, | ||
useJsonEditorContext | ||
} from './components/json-editor-context-provider'; | ||
export * from './types'; | ||
|
||
/** | ||
* Ensure that we have the correct ref for an Ace editor, based on the current editor role in the store. This will | ||
* allow us to access the editor instance from other components. | ||
*/ | ||
const getActiveEditorRef = (editorRefs: IEditorRefs) => { | ||
const { editorSelectedOperation } = getState(); | ||
switch (editorSelectedOperation) { | ||
case 'Spec': | ||
return editorRefs.spec; | ||
case 'Config': | ||
return editorRefs.config; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Set focus to the active editor, based on the current editor role in the store. | ||
*/ | ||
export const setFocusToActiveEditor = (editorRefs: IEditorRefs) => { | ||
if (shouldPrioritizeJsonEditor()) { | ||
getActiveEditorRef(editorRefs)?.current.editor?.focus(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters