Line attributes

I’m trying to add dir=auto to lines. CodeMirror 6 Reference Manual

Minimal code example:

const auto_dir = Decoration.line({
    attributes: {dir: 'auto'},
const editor = new EditorView({
    decorations: Decoration.set([auto_dir]),

This gives me: “Cannot read property ‘startSide’ of undefined”. See:

Thank you.

You’re passing a Decoration where a Range<Decoration> is expected. You line decorations apply to a specific line, and need to point at the start of the line (auto_dir.range(0) for the first line).

Thank you! I’m unfamiliar with the code base, but I’ll try to research and figure out what that means (I’d of course appreciate any more pointers!).

However, is there any simpler way to just add an attribute to all <div class=cm-line> elements?

Nope, that’s not a requirement that has come up before.

Also, the library assumes the editor has a single direction (from the computed style of the cm-content element). I don’t think putting dir=auto on every line should break anything in too hard a way, but you will probably, for lines different from the main editor’s direction, see some non-ideal behavior.

Ah, I had assumed that was supported. I did some testing now and yes, dir=auto does break caret movement and selection.