vue-codemirror
vue-codemirror copied to clipboard
How can i insert something in the cursor position thought JS
Hi guy! I have a question, how can i add something in the cursor in the codemirror I have a button, when i click it , it can give me a string like '
I know the answer about it ,it has q api ,please view this page: http://blog.sina.com.cn/s/blog_607787d30102xisw.html replaceSelection It's amazing to do it.
I know the answer about it ,it has q api ,please view this page: http://blog.sina.com.cn/s/blog_607787d30102xisw.html replaceSelection It's amazing to do it.
unable to view page
I also encountered this problem. The address failed. Can you send it again? thank you
try it
<template>
<codemirror
...
@ready="handleReady"
...
/>
</template>
<script>
import { defineComponent } from 'vue'
import { Codemirror, shallowRef } from 'vue-codemirror'
export default defineComponent({
components: {
Codemirror
},
setup() {
const view = shallowRef();
const handleReady = (payload) => {
view.value = payload.view
};
//here
//@param text string
const insertText = (text) => {
const state = view.state;
const ranges = state.selection.ranges;
const cursor = ranges[0].anchor;
view.value.dispatch({
changes: { from: cursor, insert: text }
});
}
return {
handleReady
}
}
})
</script>