Code editor with automatic height that has a minimum and maximum height?

You can do this in V6:

function updateToMinNumberOfLines(editor, minNumOfLines) {

    const currentNumOfLines = editor.state.doc.lines;
    const currentStr = editor.state.doc.toString();

    if (currentNumOfLines >= minNumOfLines) {
        return;
    }

    const lines = minNumOfLines - currentNumOfLines;

    const appendLines = "\n".repeat(lines);


    editor.dispatch({
        changes: {from: currentStr.length, insert: appendLines}
    })

}
1 Like