feat: implement live updates for env update modal highlights

This commit is contained in:
Andrew Bastin
2022-02-12 01:46:10 +05:30
parent f34c89d87d
commit cd5b765ed1
3 changed files with 82 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import { watch, Ref } from "@nuxtjs/composition-api"
import { Compartment } from "@codemirror/state"
import { hoverTooltip } from "@codemirror/tooltip"
import {
@@ -6,7 +7,6 @@ import {
MatchDecorator,
ViewPlugin,
} from "@codemirror/view"
import { Ref } from "@nuxtjs/composition-api"
import { StreamSubscriberFunc } from "~/helpers/utils/composables"
import {
AggregateEnvironment,
@@ -144,3 +144,36 @@ export class HoppEnvironmentPlugin {
])
}
}
export class HoppReactiveEnvPlugin {
private compartment = new Compartment()
private envs: AggregateEnvironment[] = []
constructor(
envsRef: Ref<AggregateEnvironment[]>,
private editorView: Ref<EditorView | undefined>
) {
watch(
envsRef,
(envs) => {
this.envs = envs
this.editorView.value?.dispatch({
effects: this.compartment.reconfigure([
cursorTooltipField(this.envs),
environmentHighlightStyle(this.envs),
]),
})
},
{ immediate: true }
)
}
get extension() {
return this.compartment.of([
cursorTooltipField(this.envs),
environmentHighlightStyle(this.envs),
])
}
}