Extra indent when no semicolon after break/continue

This (possible) bug is subtle enough that I hesitate to report it, but when break or continue lack a trailing semicolon, the rest of the cell prefers an extra level of indentation. I fought it for a while before realizing I just needed semicolons. Could very well be a codemirror issue, but a quick check suggests the sample editor on the codemirror site doesn’t seem to exhibit this.

while (false) {
  continue // <--  lacks semicolon
} // place the cursor at the end of this line and hit enter
  // <-- indented one level too far

Adding a semicolon after continue leads to the expected indentation.

Example: https://observablehq.com/d/72e354f4e3295ae6

1 Like

Feature request: an opt-in choice to have indent after return always match the indent (first non-whitespace character) of the previous line.

I get wrong indentation all the time with the current “smart” indenter, and constantly needing to manually delete whitespace is a drag.

As an example, the indenter really doesn’t want me to indent my code like this:

// accurate to 4.4e-5 relative precision
erf = (x) => {
  x *= 1.1283791670955126;
  const xx = x*x;
  x += x * xx * (
    0.237547 + xx * (
    0.046296 + xx * (
    0.003331 + xx * (
  return x / Math.sqrt(1 + x*x);

Observable’s indentation is mostly out-of-the-box behavior from CodeMirror, which will likely get a boost in CodeMirror 6. It is, by effect of being very performant, also pretty rough: if you want deterministic, smart auto-formatting, I’d really recommend using the (beta) prettier support.

1 Like

if you want deterministic, smart auto-formatting,

I for one do not want this. In a web browser view I want “simple and predictable editor view that doesn’t put too-clever obstacles in my way”.

[This is one reason I would like to be able to have read/write API access and use an external editor. It’s unlikely any standardized web editor is ever going to match my specific preferences (or other picky peoples’); someone’s own personalized text editor is typically dramatically more productive and pleasant (for them) than anything built-in anywhere. But there is a huge variety in text editor preferences.]