diff --git a/packages/hoppscotch-common/src/components/http/ImportCurl.vue b/packages/hoppscotch-common/src/components/http/ImportCurl.vue index cb60686c8..d9a319c32 100644 --- a/packages/hoppscotch-common/src/components/http/ImportCurl.vue +++ b/packages/hoppscotch-common/src/components/http/ImportCurl.vue @@ -98,6 +98,7 @@ import { RESTTabService } from "~/services/tab/rest" import { useService } from "dioc/vue" import { useNestedSetting } from "~/composables/settings" import { toggleNestedSetting } from "~/newstore/settings" +import { EditorView } from "@codemirror/view" const t = useI18n() @@ -124,6 +125,7 @@ useCodemirror( linter: null, completer: null, environmentHighlights: false, + onInit: (view: EditorView) => view.focus(), }) ) diff --git a/packages/hoppscotch-common/src/composables/codemirror.ts b/packages/hoppscotch-common/src/composables/codemirror.ts index c8cc15f30..b09a644d2 100644 --- a/packages/hoppscotch-common/src/composables/codemirror.ts +++ b/packages/hoppscotch-common/src/composables/codemirror.ts @@ -68,6 +68,9 @@ type CodeMirrorOptions = { // callback on editor update onUpdate?: (view: ViewUpdate) => void + + // callback on view initialization + onInit?: (view: EditorView) => void } const hoppCompleterExt = (completer: Completer): Extension => { @@ -208,7 +211,9 @@ export function useCodemirror( el: Ref, value: Ref, options: CodeMirrorOptions -): { cursor: Ref<{ line: number; ch: number }> } { +): { + cursor: Ref<{ line: number; ch: number }> +} { const { subscribeToStream } = useStreamSubscriber() // Set default value for contextMenuEnabled if not provided @@ -383,6 +388,8 @@ export function useCodemirror( extensions, }), }) + + options.onInit?.(view.value) } onMounted(() => {