Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codemirror tabs to spaces

I'm using Codemirror in an app. Has anyone found a way to make it uses spaces when using tab? When I press enter to go to a new line it uses spaces. However, if I backspace to the beginning of the line, and use a tab instead, it inserts it as a tab instead of 2 or 4 spaces or whatever I have it set to. Then, when I view the rendered view, my code has like 8 spaces for indentations in the areas where I used the tab key. Is there some option or way to convert actual tabs to spaces in Codemirror?

I'm also using the codemirror-rails gem, which may not be as up-to-date as the actual Codemirror version.

like image 410
jthomas Avatar asked Mar 03 '13 07:03

jthomas


1 Answers

I would override the default tab key functionality and replace it with this function. Add this to your Codemirror configurations.

extraKeys: {
            "Tab": function(cm){
              cm.replaceSelection("   " , "end");
            }
           }

Demo jsfiddle

like image 62
aljordan82 Avatar answered Sep 18 '22 04:09

aljordan82