summaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2016-08-30 16:47:22 -0700
committerGitHub <noreply@github.com>2016-08-30 16:47:22 -0700
commitcd9b926af7d186c82997c26fea0bbdeed447b4dc (patch)
treed9b0e47314b291850f71b59477bce27eb577c4fa /public
parent8516dfcb6cb008f286ec84bed4243928acb94844 (diff)
parent9ac46fb983f31cfece76e2181a9fe73b71f02e2e (diff)
downloadgitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.tar.gz
gitea-cd9b926af7d186c82997c26fea0bbdeed447b4dc.zip
Support Editorconfig on web editor (#3512)
Diffstat (limited to 'public')
-rw-r--r--public/js/gogs.js28
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');
}