Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: handle tab key press on editors - resolved #2185

liyasthomas4ec56c6300c4
diff --git a/packages/hoppscotch-app/helpers/editor/codemirror.ts b/packages/hoppscotch-app/helpers/editor/codemirror.ts
index 16f0730a5..a93c459c4 100644
--- a/packages/hoppscotch-app/helpers/editor/codemirror.ts
+++ b/packages/hoppscotch-app/helpers/editor/codemirror.ts
@@ -12,7 +12,7 @@ import {
EditorSelection,
} from "@codemirror/state"
import { Language, LanguageSupport } from "@codemirror/language"
-import { defaultKeymap } from "@codemirror/commands"
+import { defaultKeymap, indentLess, insertTab } from "@codemirror/commands"
import { Completion, autocompletion } from "@codemirror/autocomplete"
import { linter } from "@codemirror/lint"
@@ -240,7 +240,19 @@ export function useCodemirror(
? [EditorView.lineWrapping]
: []
),
- keymap.of(defaultKeymap),
+ keymap.of([
+ ...defaultKeymap,
+ {
+ key: "Tab",
+ preventDefault: true,
+ run: insertTab,
+ },
+ {
+ key: "Shift-Tab",
+ preventDefault: true,
+ run: indentLess,
+ },
+ ]),
]
if (environmentTooltip) extensions.push(environmentTooltip.extension)