diff options
author | 无闻 <u@gogs.io> | 2016-08-30 16:47:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-30 16:47:22 -0700 |
commit | cd9b926af7d186c82997c26fea0bbdeed447b4dc (patch) | |
tree | d9b0e47314b291850f71b59477bce27eb577c4fa /public | |
parent | 8516dfcb6cb008f286ec84bed4243928acb94844 (diff) | |
parent | 9ac46fb983f31cfece76e2181a9fe73b71f02e2e (diff) | |
download | gitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.tar.gz gitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.zip |
Support Editorconfig on web editor (#3512)
Diffstat (limited to 'public')
-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'); } |