antonmedv / codejar

An embeddable code editor for the browser 🍯
https://medv.io/codejar/
MIT License
1.8k stars 116 forks source link

Bug: autoClosing Braces and Parentheses have incorrect indent #76

Closed tuckergordon closed 2 years ago

tuckergordon commented 2 years ago

It looks like the behavior of the auto closing braces and parentheses does not match that of the brackets.

Consider the following options:

let options = {
  indentOn: /[{\\([]$/,  // indent on {, (, and [
  addClosing: true
}

If I have this code in my editor

{
  "a": 1,
  "b": {}
}

then place my cursor inside the {} and press return, it results in this:

{
  "a": 1,
  "b": {

  }
}

which is expected. However, following a similar procedure with braces or parentheses results in this:

{
  "a": 1,
  "b": [
    ]
}

I would expect that, because braces and parentheses are included in the behaivor of addClosing, that they would indent in the same way as braces:

{
  "a": 1,
  "b": [

  ]
}
antonmedv commented 2 years ago

Fixed! Now there is a separate regexp to test which lines to move on:

    indentOn: /[({\[]$/,
    moveToNewLine: /^[)}\]]/,