From 1c65147a7783a2b7f7431fbcafeb0ba690e518ff Mon Sep 17 00:00:00 2001 From: nivedin Date: Thu, 22 Feb 2024 14:37:19 +0530 Subject: [PATCH] fix: autocomplete env bug --- .../src/components/smart/EnvInput.vue | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/hoppscotch-common/src/components/smart/EnvInput.vue b/packages/hoppscotch-common/src/components/smart/EnvInput.vue index 8bb99223b..2d39d0b44 100644 --- a/packages/hoppscotch-common/src/components/smart/EnvInput.vue +++ b/packages/hoppscotch-common/src/components/smart/EnvInput.vue @@ -93,6 +93,7 @@ import IconEyeoff from "~icons/lucide/eye-off" import { CompletionContext, autocompletion } from "@codemirror/autocomplete" import { useService } from "dioc/vue" import { RESTTabService } from "~/services/tab/rest" +import { syntaxTree } from "@codemirror/language" const t = useI18n() @@ -405,16 +406,14 @@ function envAutoCompletion(context: CompletionContext) { } }) : [] - - const textBefore = context.state.sliceDoc(context.pos - 2, context.pos) - - const tagBefore = /<<\w*/.exec(textBefore) - - if (!tagBefore) return null - + const nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1) + const textBefore = context.state.sliceDoc(nodeBefore.from, context.pos) + const tagBefore = /<<\w*$/.exec(textBefore) + if (!tagBefore && !context.explicit) return null return { - from: context.pos - 2, + from: tagBefore ? nodeBefore.from + tagBefore.index : context.pos, options: options, + validFor: /^(<<\w*)?$/, } }