Continue markup for indented code in Markdown?

Markdown in code mirror supports two types of code:

  1. One with the ticks
    ```
    code
    code
    ```
    
  2. One that is indented with 4 spaces
        code
        code
    

One has lezer type FencedCode and the other CodeBlock.

If I have the indented code, and I have cursor in the last line, and I run Enter, insertNewLineContinueMarkup(),

    code|
    code

I get this

    code
|
    code

Wouldn’t it be better if the new line started with the indent?

What I’m seeing in this case is that the new line is indented (loading basicSetup and markdown()).

What package version, if I may ask? I have 0.19.4

I have taken a look with the debugger in the code, in the lang-markdown, and I found, that for state " code" (4 spaces and "code"), and cursor at the end, in this code:

const insertNewlineContinueMarkup = ({ state, dispatch }) => {
    let tree = syntaxTree(state), { doc } = state;
    let dont = null, changes = state.changeByRange(range => {
        if (!range.empty || !markdownLanguage.isActiveAt(state, range.from)) {
            return dont = { range };
        }
        let pos = range.from, line = doc.lineAt(pos);
        let context = getContext(tree.resolveInner(pos, -1), line.text, doc);
        while (context.length && context[context.length - 1].from > pos - line.from)
            context.pop();
        if (!context.length)
            return dont = { range };
        let inner = context[context.length - 1];
        if (inner.to - inner.spaceAfter.length > pos - line.from) {
            return dont = { range };
        }

It comes into the second if,

 if (!context.length)
   return dont = { range };

and returns from the insertNewlineContinueMarkup() command. context.length is 0. Then the native Enter kicks in and adds a native new line, not the indented one.

Same for state

    code
    code

with the cursor in the 8 position

    code|
    code

The behavior is coming from insertNewlineAndIndent (via basicSetup), not insertNewlineContinueMarkup.

1 Like

The behavior is coming from insertNewlineAndIndent (via basicSetup ), not insertNewlineContinueMarkup .

Okay, cool.

And what command is used as a reverse of insertNewlineAndIndent()? Because deleteMarkupBackward() is reverse of insertNewlineContinueMarkup(), right?

No, those commands are not really reverses of each other.

1 Like

No, those commands are not really reverses of each other.

Okay, let me put it this way.

Is there a command that from this

    code
    |
    code

could make

    code|
    code

No, there isn’t. You could write one, if you want, though.

1 Like