How to remove indentation on newline


#1

Does anyone know how to remove indentation on newline event?

My current config is:

{ lineNumbers: true, mode: "javascript", smartIndent: false, tabSize: 2 }

When i enter

function() {
  alert("test");

then press enter, the newly added line will keep the indentation of two spaces.
However i want every line to start with zero indentation when i press enter.

How to achieve this?

Thanks in advance
Benjamin


#2

Bind Enter to a command like cm => cm.replaceSelection("\n") rather than the default, the newlineAndIndent command.


#3

perfect, thx!


#4

But in my case, cursor jump through one empty line. How fix this? Thanks in advance
In Angular 5 + Electron
html:

   <codemirror
     [config]="{
       lineWrapping: true, 
       autofocus: true, 
       showCursorWhenSelecting: true,
       smartIndent: false
     }"
     (keyup.enter)="removeIndentation()"
     #novelEditor>
   </codemirror>

ts:

import { CodemirrorComponent } from 'ng2-codemirror';
...
@ViewChild('novelEditor') private novelEditor: CodemirrorComponent;
...
  removeIndentation() {
    const cm = this.novelEditor.instance;
    cm.replaceSelection("\n");
  }

Screenshot_11


#5

I solved it

removeIndentation() {
   const cm = this.novelEditor.instance;
   cm.execCommand('delLineLeft');
}