rennzhang / codemirror-editor-vue3

CodeMirror component for Vue3
https://rennzhang.github.io/codemirror-editor-vue3
MIT License
202 stars 41 forks source link

how to autoComplete code? #12

Closed zhoufanglu closed 2 years ago

zhoufanglu commented 2 years ago

Have a demo?

zhoufanglu commented 2 years ago

i slove it

// 引入代码自动提示插件
import "codemirror/addon/hint/show-hint.css";
import "codemirror/addon/hint/sql-hint";
import "codemirror/addon/hint/show-hint";
const opts = {
// ...
  extraKeys: {
    // 触发按键
    Ctrl: "autocomplete",
    Tab: "autocomplete",
  },
  hintOptions: {
    // 自定义提示选项
    completeSingle: false, // 当匹配只有一项的时候是否自动补全
  },
}

how to get codemitter instance?

const codeMirrorRef = ref(null);
  codeMirrorRef.value.showHint() // TypeError: codeMirrorRef.value.showHint is not a function
rennzhang commented 2 years ago

ready事件或者ref获取

refName.value.cminstance

zhoufanglu commented 2 years ago

ready事件或者ref获取

refName.value.cminstance codeMirrorRef.value.cminstance.showHint(); 谢谢大佬 确实可行

zhoufanglu commented 2 years ago

大佬我有个疑问, 我现在监听的codeChange, 一触发我就showHint(); 如何在输入回车的时候隐藏hint

rennzhang commented 2 years ago

这里应该有你需要的 Check out the official Codemirror documentation

tpoxa commented 2 years ago

does someone know how to take control over what exactly autocompleted? register own global variables and etc?

dik111 commented 2 years ago

大佬我有个疑问, 我现在监听的codeChange, 一触发我就showHint(); 如何在输入回车的时候隐藏hint

<Codemirror
    v-model:value="code"
    :options="cmOptions"
    border
    @change="onChange"
    @ready="onReady"
    @keypress="showEditorHint"
    ref="codeMirrorRef"
  >
...
const codeMirrorRef = ref()
function showEditorHint(e: KeyboardEvent, handle: Function){
  console.log('e',e)
  codeMirrorRef.value.cminstance.showHint();
}

我这样好像不会回车的时候出现代码提示