From 7c33fd413e232188ac026c47c5a9ad2685807873 Mon Sep 17 00:00:00 2001 From: Natalie Carey Date: Fri, 2 Aug 2024 07:40:04 +0100 Subject: [PATCH] Refactored handlers into reusable functions for readability. (#2744) --- .../src/components/SingleLineEditor/index.js | 52 +++++++------------ 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/packages/bruno-app/src/components/SingleLineEditor/index.js b/packages/bruno-app/src/components/SingleLineEditor/index.js index dbb46191b..a817da782 100644 --- a/packages/bruno-app/src/components/SingleLineEditor/index.js +++ b/packages/bruno-app/src/components/SingleLineEditor/index.js @@ -26,6 +26,18 @@ class SingleLineEditor extends Component { /** @type {import("codemirror").Editor} */ const variables = getAllVariables(this.props.collection, this.props.item); + const runHandler = () => { + if (this.props.onRun) { + this.props.onRun(); + } + }; + const saveHandler = () => { + if (this.props.onSave) { + this.props.onSave(); + } + }; + const noopHandler = () => {}; + this.editor = CodeMirror(this.editorRef.current, { lineWrapping: false, lineNumbers: false, @@ -37,21 +49,9 @@ class SingleLineEditor extends Component { scrollbarStyle: null, tabindex: 0, extraKeys: { - Enter: () => { - if (this.props.onRun) { - this.props.onRun(); - } - }, - 'Ctrl-Enter': () => { - if (this.props.onRun) { - this.props.onRun(); - } - }, - 'Cmd-Enter': () => { - if (this.props.onRun) { - this.props.onRun(); - } - }, + Enter: runHandler, + 'Ctrl-Enter': runHandler, + 'Cmd-Enter': runHandler, 'Alt-Enter': () => { if (this.props.allowNewlines) { this.editor.setValue(this.editor.getValue() + '\n'); @@ -60,23 +60,11 @@ class SingleLineEditor extends Component { this.props.onRun(); } }, - 'Shift-Enter': () => { - if (this.props.onRun) { - this.props.onRun(); - } - }, - 'Cmd-S': () => { - if (this.props.onSave) { - this.props.onSave(); - } - }, - 'Ctrl-S': () => { - if (this.props.onSave) { - this.props.onSave(); - } - }, - 'Cmd-F': () => {}, - 'Ctrl-F': () => {}, + 'Shift-Enter': runHandler, + 'Cmd-S': saveHandler, + 'Ctrl-S': saveHandler, + 'Cmd-F': noopHandler, + 'Ctrl-F': noopHandler, // Tabbing disabled to make tabindex work Tab: false, 'Shift-Tab': false