Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor position not updated #17

Open
am-den opened this issue Mar 17, 2023 · 5 comments
Open

Cursor position not updated #17

am-den opened this issue Mar 17, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@am-den
Copy link

am-den commented Mar 17, 2023

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

@logue
Copy link
Owner

logue commented Mar 18, 2023

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.

@am-den
Copy link
Author

am-den commented Mar 18, 2023

I did try that too, yet the cursor position is not updated.

const getCursor = (e) => {
  console.debug(mirror.value.cursor)
}
vue-codemirror.webm

@logue logue added the bug Something isn't working label Mar 18, 2023
@logue
Copy link
Owner

logue commented Mar 21, 2023

The cause was that the change of EditorState in EditorView could not be detected.
Currently investigating countermeasures.

logue added a commit that referenced this issue Mar 23, 2023
TODO: diagnosticCount does not work properly.
@NikoArtz
Copy link

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

@logue
Copy link
Owner

logue commented May 16, 2023

I don't have much time for development resources, but I made it work only to get the cursor position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants