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

How to format code #35

Open STofone opened 3 months ago

STofone commented 3 months ago

I want to format selected code (or auto format after save or after setValue). The solutions i found is to use indentLine. But when i print the reference of CodeMirror Component, there's no method indentLine.

<CodeMirror
  ref="codeMirror"
  v-model="code"
  :extensions="extensions"
  :tab="true"
  placeholder="Please enter the code."
  style="height: 100%"
  @change="save"
></CodeMirror>
......
console.log(codeMirror)

image

logue commented 3 months ago

It seems that this function does not exist in the CodeMirror standard, but it seems possible to do it by implementing the process described on the following site.

https://discuss.codemirror.net/t/adding-indentation/5622/7

In this program, I think you can do this by putting this function in @update.