From 1e1a0939abce59adfa21106aa938e7ea287e054c Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 12 Jun 2020 17:50:44 +0200 Subject: [PATCH] feat: highlight currently selected editor tab --- .../templates/Challenges/classic/Editor.js | 26 ++++++++++++------- .../templates/Challenges/classic/editor.css | 11 ++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/src/templates/Challenges/classic/Editor.js b/client/src/templates/Challenges/classic/Editor.js index 104dc92198..0d0410d977 100644 --- a/client/src/templates/Challenges/classic/Editor.js +++ b/client/src/templates/Challenges/classic/Editor.js @@ -136,9 +136,11 @@ class Editor extends Component { const { challengeFiles } = this.props; - // NOTE: for consitency with this.data (and this.options) currentFileKey - // is just a property, not state. - this.currentFileKey = sortFiles(challengeFiles)[0].key; + // NOTE: the ARIA state is controlled by fileKey, so changes to it must + // trigger a re-render. Hence state: + this.state = { + fileKey: sortFiles(challengeFiles)[0].key + }; this.options = { fontSize: '18px', @@ -192,7 +194,7 @@ class Editor extends Component { modeMap[challengeFiles[key].ext] ); }); - return { model: this.data[this.currentFileKey].model }; + return { model: this.data[this.state.fileKey].model }; }; // Updates the model if the contents has changed. This is only necessary for @@ -282,11 +284,11 @@ class Editor extends Component { onChange = editorValue => { const { updateFile } = this.props; - updateFile({ key: this.currentFileKey, editorValue }); + updateFile({ key: this.state.fileKey, editorValue }); }; - changeTab = fileKey => { - this.currentFileKey = fileKey; + changeTab = newFileKey => { + this.setState({ fileKey: newFileKey }); const editor = this._editor; const currentState = editor.saveViewState(); @@ -301,8 +303,8 @@ class Editor extends Component { this.data.indexjsx.state = currentState; } - editor.setModel(this.data[fileKey].model); - editor.restoreViewState(this.data[fileKey].state); + editor.setModel(this.data[newFileKey].model); + editor.restoreViewState(this.data[newFileKey].state); editor.focus(); }; @@ -319,7 +321,7 @@ class Editor extends Component { } componentWillUnmount() { - this.currentFileKey = null; + this.setState({ fileKey: null }); this.data = null; } @@ -335,6 +337,7 @@ class Editor extends Component {
{challengeFiles['indexjsx'] && (