logue / vue-codemirror6

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

Wrong "automatic bracket closing" behaviour? #21

Open MrCoder opened 1 year ago

MrCoder commented 1 year ago

According to the specification (https://codemirror.net/docs/ref/#autocomplete.closeBrackets), the default "automatic bracket closing" should be like this:

  1. type (, then ) is automatically inserted;
  2. type ), the cursor moves over that bracket.

The example has the same behaviour as explained: https://codemirror.net/try/

It does not seem to work in the same way at https://logue.dev/vue-codemirror6/ with basic lang=javascript.

Specifically, the second step, when you type ), the character is inserted.

logue commented 1 year ago

It's still under testing, but it seems to work in the "Linter and cross binding demo" with the update I just committed.

dyon21 commented 1 year ago

Currently, when you input "()", you get "())", which does not follow the specification.

https://github.com/logue/vue-codemirror6/blob/master/src/components/CodeMirror.ts#L442 I found that this watcher updates the CodeMirror content even if the update is exactly caused by CodeMirror itself, this might making CodeMirror think there are additional manipulations between the two input( ( and ) ), so it will not trigger the second step.

It is necessary to check the update source, If the update comes from CodeMirror, then don't dispatch the update back to CodeMirror.

I have fixed it in #22

MrCoder commented 1 year ago

Hi @logue, do mind merging @dyon21 's PR #22 ? I have tested it and that works very well. I have a product that uses this component. It is much appreciated if the fix is released as soon as possible.

logue commented 1 year ago

Merged. There are also cases where you use it to customize the line separator, so we also fixed that.