Single-line codemirror?

Can I use CodeMirror as an input instead of textarea so it’s all on a single line?

1 Like

You can use a "beforeChange" filter to prevent any newline from being added, and style the editor to be only a single line high. Might also want to set scrollbarStyle: "null" to prevent scrollbars from showing up.

1 Like

Thanks, I’ll try that!

My solution to prevent new lines (its for a custom search query input field):

cm.on("beforeChange", function(cm, changeObj) {
    var typedNewLine = changeObj.origin == '+input' && typeof changeObj.text == "object" && changeObj.text.join("") == "";
    if (typedNewLine) {
        return changeObj.cancel();

    var pastedNewLine = changeObj.origin == 'paste' && typeof changeObj.text == "object" && changeObj.text.length > 1;
    if (pastedNewLine) {
        var newText = changeObj.text.join(" ");

        // trim
        //newText = $.trim(newText);

        return changeObj.update(null, null, [newText]);

    return null;
1 Like