From 85506d81202a5d6f59945524639d0eb76ec3d467 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Tue, 19 Mar 2024 22:38:17 +0600 Subject: [PATCH 1/3] feat: onInit callback to useCodemirror function --- packages/hoppscotch-common/src/composables/codemirror.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/hoppscotch-common/src/composables/codemirror.ts b/packages/hoppscotch-common/src/composables/codemirror.ts index c8cc15f302..b09a644d28 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(() => { From 0a28d580f1fa9b920c001051618818a4711a1588 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Tue, 19 Mar 2024 22:39:59 +0600 Subject: [PATCH 2/3] feat: focus codemirror view when import curl modal launch --- .../hoppscotch-common/src/components/http/ImportCurl.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/hoppscotch-common/src/components/http/ImportCurl.vue b/packages/hoppscotch-common/src/components/http/ImportCurl.vue index cb60686c8c..78615e87ee 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,9 +125,14 @@ useCodemirror( linter: null, completer: null, environmentHighlights: false, + onInit: onInitView, }) ) +function onInitView(view: EditorView) { + view.focus() +} + watch( () => props.show, () => { From fbf5be27424735222903a52a645fa5f102c22841 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 22 Mar 2024 15:43:05 +0530 Subject: [PATCH 3/3] refactor: inline `onInit` handler --- .../hoppscotch-common/src/components/http/ImportCurl.vue | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/hoppscotch-common/src/components/http/ImportCurl.vue b/packages/hoppscotch-common/src/components/http/ImportCurl.vue index 78615e87ee..d9a319c329 100644 --- a/packages/hoppscotch-common/src/components/http/ImportCurl.vue +++ b/packages/hoppscotch-common/src/components/http/ImportCurl.vue @@ -125,14 +125,10 @@ useCodemirror( linter: null, completer: null, environmentHighlights: false, - onInit: onInitView, + onInit: (view: EditorView) => view.focus(), }) ) -function onInitView(view: EditorView) { - view.focus() -} - watch( () => props.show, () => {