Search code examples
javascriptnewlineace-editorentercarriage-return

Ace editor pressing enter key does not add a newline


No newline is inserted when pressing the enter key in the editor field of an ace editor instance. Nothing happens.

Example initiation:

let codeEditor = ace.edit('someElementId', {
    minLines: 6,
    maxLines: 20,
    showLineNumbers: false,
    readOnly: false,
    newLineMode: 'auto',
});
codeEditor.setTheme('ace/theme/chrome');
codeEditor.session.setMode('ace/mode/json');

Solution

  • Something else on your page is catching the event On a page without other code your example works

    <form>
        <div id="someElementId"></div>
    </form>
    
    <script src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.3/ace.js></script>
    <script>
    let codeEditor = ace.edit('someElementId', {
        minLines: 6,
        maxLines: 20,
        showLineNumbers: false,
        readOnly: false,
        newLineMode: 'auto',
    });
    codeEditor.setTheme('ace/theme/chrome');
    codeEditor.session.setMode('ace/mode/json');
    </script>