logue / vue-codemirror6

⌨️ @codemirror 6 component for @vuejs. Vue2 & Vue3 both supported.
https://logue.dev/vue-codemirror6/
MIT License
123 stars 16 forks source link

Bug: RangeError: Selection points outside of document #27

Open jonkad opened 7 months ago

jonkad commented 7 months ago

Hello,

When I update the v-model value from another function, then I got this error: Uncaught (in promise) RangeError: Selection points outside of document

image

Versions: vue: 3.3.4 codemirror: 6.0.1 vue-codemirror6: 1.1.31 @codemirror/lang-css: 6.2.1

Maybe someone have an Idea?

<template>
  <button @click="restoreCustomStyleCss()">restore</button>
  <button @click="cearCustomStyleCss()">clear</button>
  <code-mirror
    v-model="customStyleCss"
    :lang="[lang]"
    :basic="true"
    :gutter="true"
  />
</template>

<script lang="ts">
import { defineComponent, defineAsyncComponent } from "vue";

import CodeMirror from "vue-codemirror6";
import { css } from "@codemirror/lang-css";
export default defineComponent({
  name: "EventStyle",
  components: {
    CodeMirror,
  },
  setup() {
    const lang = css();
    return { lang };
  },
  data() {
    return {
      customStyleCss: "",
      restoreCustomStyleCss = "body {color: red;}",
    };
  },
  methods: {
    restoreCustomStyleCss() {
      this.customStyleCss = this.restoreCustomStyleCss;
    },
    cearCustomStyleCss() {
      this.customStyleCss = "";
    },
  },
});
</script>
jonkad commented 7 months ago

I have temporarily solved the error as follows: this.$refs.cm.setCursor(0);

<template>
  <button @click="restoreCustomStyleCss()">restore</button>
  <button @click="cearCustomStyleCss()">clear</button>
  <code-mirror
    v-model="customStyleCss"
    :lang="[lang]"
    :basic="true"
    :gutter="true"
    ref="cm"
  />
</template>

<script lang="ts">
import { defineComponent, defineAsyncComponent } from "vue";

import CodeMirror from "vue-codemirror6";
import { css } from "@codemirror/lang-css";
export default defineComponent({
  name: "EventStyle",
  components: {
    CodeMirror,
  },
  setup() {
    const lang = css();
    return { lang };
  },
  data() {
    return {
      customStyleCss: "",
      restoreCustomStyleCss = "body {color: red;}",
    };
  },
  methods: {
    restoreCustomStyleCss() {
      //@ts-expect-error
      this.$refs.cm.setCursor(0);
      this.customStyleCss = this.restoreCustomStyleCss;
    },
    cearCustomStyleCss() {
      //@ts-expect-error
      this.$refs.cm.setCursor(0);
      this.customStyleCss = "";
    },
  },
});
</script>
redisviewer commented 1 month ago

https://github.com/josdejong/svelte-jsoneditor/issues/423

refer to this issues? @logue