Heya, I’m from Replit and I’ve been working on an extension for adding indentation preserving line wrapping to our editor. The WIP extension is technically functional, but there are just a lot of fundamental problems I don’t think I can resolve through an extension.
Example (cherry-picked) of our extension in action:
Basically, me and other people at Replit have come up with… maybe 5 or more methods to add this feature and all of them have serious problems. They depend on CSS hacks, widget/mark decorations which require particular DOM layouts, etc. I’ve completely lost confidence in the idea that an extension that does this reliably can be made, as every time we’ve tried an approach we find some “gotcha” with it, such as browser bugs or unexpected interactions with other extensions.
Even if a basic, reliable hanging indent extension is possible, it would still place control of where line breaks are in control of the browser. And with that you only get two choices (basically), which is breaking on every character, or breaking on what the browser considers a “word”. I think most users would rather lines not break in the middle of words, but often the browser makes terrible choices with word based line breaks.
These examples are somewhat contrived, as in many cases bad line wrapping can just be blamed on the editor being too narrow to even use. What I’m trying to get at is that there is a complete lack of control with line wrapping. If I wanted to make it so that line wrapping treated JS accessors (like the dot in
foo.bar) as a word break point, I think I’d have to make mark decorations which displayed them as
inline-block elements, which seems a little absurd.
Decorations in general mess with line wrapping, as the browser will treat the edge of an
inline-block (and others) as a word break point, which causes some problems. An example scenario would be placing a checkmark widget before a word, with the word being a label. Unless you wrapped both the checkmark and the label word in another decoration, the browser might choose to line wrap directly after the checkmark, which would be confusing.
Indentation preserving line wrapping is one of our most requested features, especially since we had it at one point. Even if we add it back somehow with an extension, I feel that “intelligent” wrapping will then become one of our next most requested features, and that’s another can of worms.
With that all in mind, I ask that you consider making CodeMirror handle line wrapping itself though whatever means, and to make it at least mildly extensible. I know that this is substantial request but I think we’re totally out of options here.