fix: send-request shortcut (#7853)

* fix: send-request shortcut

* fix: test cases

---------

Co-authored-by: shubh-bruno <shubh-bruno@shubh-bruno.local>
Co-authored-by: phubadeepjs <ID+phubadeepjs@users.noreply.github.com>
This commit is contained in:
shubh-bruno
2026-04-27 19:19:54 +05:30
committed by GitHub
parent 9361393a49
commit 87aefe9849
4 changed files with 295 additions and 3 deletions

View File

@@ -50,6 +50,13 @@ export default class CodeEditor extends React.Component {
componentDidMount() {
const variables = getAllVariables(this.props.collection, this.props.item);
const runShortcut = () => {
if (this.props.onRun) {
this.props.onRun();
return;
}
return CodeMirror.Pass;
};
const editor = (this.editor = CodeMirror(this._node, {
value: this.props.value || '',
@@ -86,6 +93,8 @@ export default class CodeEditor extends React.Component {
},
'Cmd-H': this.props.readOnly ? false : 'replace',
'Ctrl-H': this.props.readOnly ? false : 'replace',
'Cmd-Enter': runShortcut,
'Ctrl-Enter': runShortcut,
'Tab': function (cm) {
cm.getSelection().includes('\n') || editor.getLine(cm.getCursor().line) == cm.getSelection()
? cm.execCommand('indentMore')

View File

@@ -30,6 +30,13 @@ class MultiLineEditor extends Component {
// Initialize CodeMirror as a single line editor
/** @type {import("codemirror").Editor} */
const variables = getAllVariables(this.props.collection, this.props.item);
const runShortcut = () => {
if (this.props.onRun) {
this.props.onRun();
return;
}
return CodeMirror.Pass;
};
this.editor = CodeMirror(this.editorRef.current, {
lineWrapping: false,
@@ -47,6 +54,8 @@ class MultiLineEditor extends Component {
extraKeys: {
'Cmd-F': () => {},
'Ctrl-F': () => {},
'Cmd-Enter': runShortcut,
'Ctrl-Enter': runShortcut,
// Tabbing disabled to make tabindex work
'Tab': false,
'Shift-Tab': false

View File

@@ -61,7 +61,9 @@ const RequestTabPanel = () => {
const isConsoleOpen = useSelector((state) => state.logs.isConsoleOpen);
const isRequestTab = focusedTab && ['request', 'grpc-request', 'ws-request', 'graphql-request'].includes(focusedTab.type);
useKeybinding('sendRequest', () => {
useKeybinding('sendRequest', (e) => {
e?.preventDefault?.();
e?.stopPropagation?.();
handleRun();
return false;
}, { enabled: !!isRequestTab, deps: [isRequestTab] });