Skip to content

Commit

Permalink
Refactored handlers into reusable functions for readability. (usebrun…
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliecarey authored Aug 2, 2024
1 parent 8f920a9 commit 7c33fd4
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions packages/bruno-app/src/components/SingleLineEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand All @@ -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
Expand Down

0 comments on commit 7c33fd4

Please sign in to comment.