diff options
Diffstat (limited to 'public/js/gogs.js')
-rw-r--r-- | public/js/gogs.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/public/js/gogs.js b/public/js/gogs.js index 6faa71e739..d7fca17423 100644 --- a/public/js/gogs.js +++ b/public/js/gogs.js @@ -827,6 +827,34 @@ function initEditor() { else { codeMirrorEditor.setOption("lineWrapping", false); } + + // get the filename without any folder + var value = $editFilename.val(); + if (value.length === 0) { + return; + } + value = value.split('/'); + value = value[value.length - 1]; + + $.getJSON($editFilename.data('ec-url-prefix')+value, function(editorconfig) { + if (editorconfig.indent_style === 'tab') { + codeMirrorEditor.setOption("indentWithTabs", true); + codeMirrorEditor.setOption('extraKeys', {}); + } else { + codeMirrorEditor.setOption("indentWithTabs", false); + // required because CodeMirror doesn't seems to use spaces correctly for {"indentWithTabs": false}: + // - https://github.com/codemirror/CodeMirror/issues/988 + // - https://codemirror.net/doc/manual.html#keymaps + codeMirrorEditor.setOption('extraKeys', { + Tab: function(cm) { + var spaces = Array(parseInt(cm.getOption("indentUnit")) + 1).join(" "); + cm.replaceSelection(spaces); + } + }); + } + codeMirrorEditor.setOption("indentUnit", editorconfig.indent_size || 4); + codeMirrorEditor.setOption("tabSize", editorconfig.tab_width || 4); + }); }).trigger('keyup'); } |