feat: focus codemirror view when ImportCurl component launched (#3911)

Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
Anwarul Islam
2024-03-22 18:51:16 +06:00
committed by GitHub
parent 6f4455ba03
commit 2c5b0dcd1b
2 changed files with 10 additions and 1 deletions

View File

@@ -98,6 +98,7 @@ import { RESTTabService } from "~/services/tab/rest"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { useNestedSetting } from "~/composables/settings" import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings" import { toggleNestedSetting } from "~/newstore/settings"
import { EditorView } from "@codemirror/view"
const t = useI18n() const t = useI18n()
@@ -124,6 +125,7 @@ useCodemirror(
linter: null, linter: null,
completer: null, completer: null,
environmentHighlights: false, environmentHighlights: false,
onInit: (view: EditorView) => view.focus(),
}) })
) )

View File

@@ -68,6 +68,9 @@ type CodeMirrorOptions = {
// callback on editor update // callback on editor update
onUpdate?: (view: ViewUpdate) => void onUpdate?: (view: ViewUpdate) => void
// callback on view initialization
onInit?: (view: EditorView) => void
} }
const hoppCompleterExt = (completer: Completer): Extension => { const hoppCompleterExt = (completer: Completer): Extension => {
@@ -208,7 +211,9 @@ export function useCodemirror(
el: Ref<any | null>, el: Ref<any | null>,
value: Ref<string | undefined>, value: Ref<string | undefined>,
options: CodeMirrorOptions options: CodeMirrorOptions
): { cursor: Ref<{ line: number; ch: number }> } { ): {
cursor: Ref<{ line: number; ch: number }>
} {
const { subscribeToStream } = useStreamSubscriber() const { subscribeToStream } = useStreamSubscriber()
// Set default value for contextMenuEnabled if not provided // Set default value for contextMenuEnabled if not provided
@@ -383,6 +388,8 @@ export function useCodemirror(
extensions, extensions,
}), }),
}) })
options.onInit?.(view.value)
} }
onMounted(() => { onMounted(() => {