justcaliturner / simple-code-editor

Simple code editor for Vue.js
https://simple-code-editor.vicuxd.com
154 stars 30 forks source link

Isuue with copy functionality #15

Closed akshayreddy closed 2 years ago

akshayreddy commented 2 years ago

Description

The copy code functionality stopped working. Basically, what happens is, the previous information copied stays forever, no matter the changes to the binded value attribute. Also, the copy feature does not work if something else is already copied.

I investigated and found that it might be an issue caused due to a recent Chrome update because the functionality was working perfectly on the previous versions and interestingly it works fine on Firefox browser.

Sample code that I tested on vue sandbox

import the simple-code-editor by adding the dependency
<template>
  <span>static value</span>
  <code-editor value="console.log(10)"></code-editor>
  <br />
  <span>value keeps changing</span>
  <code-editor :value="somevalue"></code-editor>
</template>

<script>
import CodeEditor from "simple-code-editor";

export default {
  name: "App",
  components: {
    CodeEditor: CodeEditor,
  },
  data() {
    return {
      somevalue: "console.log(1)",
    };
  },

  mounted() {
    setInterval(this.changevalue, 10000);
  },

  methods: {
    changevalue() {
      this.somevalue = `console.log(${Math.random()})`;
    },
  },
};
</script>

versions

justcaliturner commented 2 years ago

@akshayreddy Thanks for the feedback, I found this error was just thrown in the CodeSandbox, and the reason is maybe for the browser permissions about the clipboard API in the CodeSandbox. But anyway, I have put the clipboard API behind the execCommand API, and it will use the old way to copy the content first, you can update the npm package to 1.2.2 and try it, and this is the demo in the CodeSandbox: https://codesandbox.io/s/confident-clarke-8h5u1s?file=/src/components/HelloWorld.vue:600-609

akshayreddy commented 2 years ago

@justcaliturner I have made the update and looks like it is working pretty well. Thank you for the fix. 👍