mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 06:01:37 +03:00
f96e5dddd6
Related to https://github.com/enso-org/enso/issues/8518 These tests already caught one regression in nav breadcrumbs: https://github.com/enso-org/enso/issues/8756 It also provides API for mocking expression updates for arbitrary nodes on the screen. The implementation is a bit convoluted and includes setting a callback on `window`, but it looks like the only possible solution given our architecture and playwright restrictions.
38 lines
1.1 KiB
Vue
38 lines
1.1 KiB
Vue
<script setup lang="ts">
|
|
import { useProjectStore } from '@/stores/project'
|
|
import { useObserveYjs } from '@/util/crdt'
|
|
import { computed, watchEffect } from 'vue'
|
|
|
|
const props = defineProps<{ modelValue: string }>()
|
|
const emit = defineEmits<{ 'update:modelValue': [modelValue: string] }>()
|
|
|
|
const projectStore = useProjectStore()
|
|
const mod = projectStore.projectModel.createNewModule('Main.enso')
|
|
projectStore.setObservedFileName('Main.enso')
|
|
mod.doc.ydoc.emit('load', [])
|
|
|
|
function applyEdits(module: NonNullable<typeof projectStore.module>, newText: string) {
|
|
module.transact(() => {
|
|
projectStore.module?.doc.setCode(newText)
|
|
})
|
|
}
|
|
|
|
watchEffect(() => projectStore.module && applyEdits(projectStore.module, props.modelValue))
|
|
|
|
const data = computed(() => projectStore.module?.doc.data)
|
|
const text = computed(() => projectStore.module?.doc.getCode())
|
|
|
|
useObserveYjs(data, () => {
|
|
if (text.value) {
|
|
const newValue = text.value?.toString()
|
|
if (newValue !== props.modelValue) {
|
|
emit('update:modelValue', newValue)
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<slot></slot>
|
|
</template>
|