Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: focus codemirror view when ImportCurl component launched #3911

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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()

Expand All @@ -124,6 +125,7 @@ useCodemirror(
linter: null,
completer: null,
environmentHighlights: false,
onInit: (view: EditorView) => view.focus(),
})
)

Expand Down
9 changes: 8 additions & 1 deletion packages/hoppscotch-common/src/composables/codemirror.ts
Expand Up @@ -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 => {
Expand Down Expand Up @@ -208,7 +211,9 @@ export function useCodemirror(
el: Ref<any | null>,
value: Ref<string | undefined>,
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
Expand Down Expand Up @@ -383,6 +388,8 @@ export function useCodemirror(
extensions,
}),
})

options.onInit?.(view.value)
}

onMounted(() => {
Expand Down