Cursor position not updated
Hi,
I'm trying to get the cursor position (using either the getCursor method or the cursor property)
but it always returns the same value.
I slightly modified one of the provided example to demonstrate this behavior.
Clicking on the getCursor button for the first time will output the correct cursor position.
But after that, it will always output the same position, whatever the cursor position is.
<!-- eslint-disable import/no-duplicates -->
<script setup>
import CodeMirror from 'vue-codemirror6';
import { vue } from '@codemirror/lang-vue';
import {ref} from 'vue'
const content = ref('hello world')
const mirror = ref(null);
const getCursor = (e) => {
console.debug(mirror.value.getCursor())
}
const updateContent = (e) => {
console.debug(e.doc.length)
}
</script>
<template>
<div class="container">
<section class="mb-5">
<p>
<button type="button" @click="getCursor">getCursor</button>
</p>
<code-mirror
ref="mirror"
v-model="content"
@change="updateContent"
:lang="vue()"
basic
wrap
/>
</section>
</div>
</template>
<style>
.vue-codemirror * {
font-family: var(--bs-font-monospace);
}
</style>
Here the expected result
getCursor reproduces the old CodeMirror5 API and its use is not recommended.
To get the cursor just call the cursor variable. In this case, you should be able to get it with mirror.value.cursor. Since this is a WritableComputedRef, it can be treated like a variable.
I did try that too, yet the cursor position is not updated.
const getCursor = (e) => {
console.debug(mirror.value.cursor)
}
The cause was that the change of EditorState in EditorView could not be detected.
Currently investigating countermeasures.
Hi @logue, if there are any updates for that issue? I see that you added fix, but for me behavior is still the same as @mimnot described. We are using v1.1.19
I don't have much time for development resources, but I made it work only to get the cursor position.