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