refactor: refer directly to editor when possible

This commit is contained in:
Oliver Eyton-Williams
2020-03-30 17:41:34 +02:00
committed by Mrugesh Mohapatra
parent 457dbe13be
commit db4b94f5ad

View File

@ -128,15 +128,15 @@ class Editor extends Component {
editorDidMount = (editor, monaco) => { editorDidMount = (editor, monaco) => {
this._editor = editor; this._editor = editor;
this._editor.updateOptions({ editor.updateOptions({
accessibilitySupport: this.props.inAccessibilityMode ? 'on' : 'auto' accessibilitySupport: this.props.inAccessibilityMode ? 'on' : 'auto'
}); });
// Users who are using screen readers should not have to move focus from // Users who are using screen readers should not have to move focus from
// the editor to the description every time they open a challenge. // the editor to the description every time they open a challenge.
if (this.props.canFocus && !this.props.inAccessibilityMode) { if (this.props.canFocus && !this.props.inAccessibilityMode) {
this._editor.focus(); editor.focus();
} else this.focusOnHotkeys(); } else this.focusOnHotkeys();
this._editor.addAction({ editor.addAction({
id: 'execute-challenge', id: 'execute-challenge',
label: 'Run tests', label: 'Run tests',
keybindings: [ keybindings: [
@ -145,7 +145,7 @@ class Editor extends Component {
], ],
run: this.props.executeChallenge run: this.props.executeChallenge
}); });
this._editor.addAction({ editor.addAction({
id: 'leave-editor', id: 'leave-editor',
label: 'Leave editor', label: 'Leave editor',
keybindings: [monaco.KeyCode.Escape], keybindings: [monaco.KeyCode.Escape],
@ -154,7 +154,7 @@ class Editor extends Component {
this.props.setEditorFocusability(false); this.props.setEditorFocusability(false);
} }
}); });
this._editor.addAction({ editor.addAction({
id: 'save-editor-content', id: 'save-editor-content',
label: 'Save editor content to localStorage', label: 'Save editor content to localStorage',
keybindings: [ keybindings: [
@ -162,7 +162,7 @@ class Editor extends Component {
], ],
run: this.props.saveEditorContent run: this.props.saveEditorContent
}); });
this._editor.addAction({ editor.addAction({
id: 'toggle-accessibility', id: 'toggle-accessibility',
label: 'Toggle Accessibility Mode', label: 'Toggle Accessibility Mode',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F1], keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F1],
@ -171,16 +171,14 @@ class Editor extends Component {
// The store needs to be updated first, as onDidChangeConfiguration is // The store needs to be updated first, as onDidChangeConfiguration is
// called before updateOptions returns // called before updateOptions returns
this.props.setAccessibilityMode(!currentAccessibility); this.props.setAccessibilityMode(!currentAccessibility);
this._editor.updateOptions({ editor.updateOptions({
accessibilitySupport: currentAccessibility ? 'auto' : 'on' accessibilitySupport: currentAccessibility ? 'auto' : 'on'
}); });
} }
}); });
this._editor.onDidFocusEditorWidget(() => editor.onDidFocusEditorWidget(() => this.props.setEditorFocusability(true));
this.props.setEditorFocusability(true)
);
// This is to persist changes caused by the accessibility tooltip. // This is to persist changes caused by the accessibility tooltip.
this._editor.onDidChangeConfiguration(event => { editor.onDidChangeConfiguration(event => {
if ( if (
event.hasChanged(monaco.editor.EditorOption.accessibilitySupport) && event.hasChanged(monaco.editor.EditorOption.accessibilitySupport) &&
editor.getRawOptions().accessibilitySupport === 'on' && editor.getRawOptions().accessibilitySupport === 'on' &&