Pressing [tab] does not align to next tab position


Wondering if there is any way to achieve tab alignment to next tab position.

-- expected:
s |
ss  |
sss |
ssss  |
-- expected:
1  |
12 |
123   |
1234  |

-- status quo:
1   |
12   |
123   |
1234   |

By default, pressing tab moves focus out of the editor. If you bound something else to tab, you’ll have to look into what your code is doing there.

Hi @marijn,

I hope you’re doing well.
I’m using the example here - CodeMirror Language Config Example

That binds tab to indentMore, which inserts an indent unit at the start of the line, but your screenshots show space added to the end of the lines.

OK my bad, sorry for incomplete information.

This is command which we’ve added based on existing codemirror code. It essentially will indent the complete line only if selection exists. Otherwise add add indent at cursor.

function insertTabWithUnit({ state, dispatch }) {
  if (state.selection.ranges.some(r => !r.empty))
    return indentMore({ state, dispatch });
  dispatch(state.update(state.replaceSelection(state.facet(indentUnit)), { scrollIntoView: true, userEvent: 'input' }));
  return true;

And in using keymap I’ve bind:

    key: 'Tab',
    preventDefault: true,
    run: insertTabWithUnit,
    shift: indentLess,

CodeMirror 5 used to work as expected. What do you suggest?

Hi, Any suggestions please?