summaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2016-08-30 20:18:40 -0300
committerAndrey Nering <andrey.nering@gmail.com>2016-08-30 20:30:47 -0300
commit9ac46fb983f31cfece76e2181a9fe73b71f02e2e (patch)
tree6499c69d94fcbeb71c144295c6df1ccc1883f8b9 /public
parent47a3243ff1b3da1b435d9390e578752f3a74ae8e (diff)
downloadgitea-9ac46fb983f31cfece76e2181a9fe73b71f02e2e.tar.gz
gitea-9ac46fb983f31cfece76e2181a9fe73b71f02e2e.zip
Support Editorconfig on web editor
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 c9f621745b..d04b5d64d0 100644
--- a/public/js/gogs.js
+++ b/public/js/gogs.js
@@ -850,6 +850,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');
}