1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

Support Editorconfig on web editor

This commit is contained in:
Andrey Nering 2016-08-30 20:18:40 -03:00
parent 47a3243ff1
commit 9ac46fb983
7 changed files with 53 additions and 3 deletions

View File

@ -48,7 +48,7 @@ golang.org/x/text = commit:2910a50
gopkg.in/alexcesaro/quotedprintable.v3 = commit:2caba25
gopkg.in/asn1-ber.v1 = commit:4e86f43
gopkg.in/bufio.v1 = commit:567b2bf
gopkg.in/editorconfig/editorconfig-core-go.v1 = commit:737b8e4
gopkg.in/editorconfig/editorconfig-core-go.v1 = commit:a872f05
gopkg.in/gomail.v2 = commit:81ebce5
gopkg.in/ini.v1 = commit:cf53f92
gopkg.in/ldap.v2 = commit:d0a5ced

2
glide.lock generated
View File

@ -138,7 +138,7 @@ imports:
- name: gopkg.in/bufio.v1
version: 567b2bfa514e796916c4747494d6ff5132a1dfce
- name: gopkg.in/editorconfig/editorconfig-core-go.v1
version: 737b8e4491939fe2277d99b8e726a086266e549e
version: a872f05c2e34b37b567401384d202aff11ba06d4
- name: gopkg.in/gomail.v2
version: 81ebce5c23dfd25c6c67194b37d3dd3f338c98b1
- name: gopkg.in/ini.v1

View File

@ -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');
}

View File

@ -290,6 +290,7 @@ func RegisterRoutes(m *macaron.Macaron) {
Patch(reqRepoWriter(), bind(api.EditMilestoneOption{}), repo.EditMilestone).
Delete(reqRepoWriter(), repo.DeleteMilestone)
})
m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
}, repoAssignment())
}, reqToken())

View File

@ -45,3 +45,23 @@ func GetArchive(ctx *context.APIContext) {
repo.Download(ctx.Context)
}
func GetEditorconfig(ctx *context.APIContext) {
ec, err := ctx.Repo.GetEditorconfig()
if err != nil {
if git.IsErrNotExist(err) {
ctx.Error(404, "GetEditorconfig", err)
} else {
ctx.Error(500, "GetEditorconfig", err)
}
return
}
fileName := ctx.Params("filename")
def := ec.GetDefinitionForFilename(fileName)
if def == nil {
ctx.Error(404, "GetDefinitionForFilename", err)
return
}
ctx.JSON(200, def)
}

View File

@ -98,6 +98,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
ctx.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubUrl, ctx.Repo.Repository.FullName())
ctx.HTML(200, EDIT_FILE)
}

View File

@ -15,7 +15,7 @@
{{range $i, $v := .TreeNames}}
<div class="divider"> / </div>
{{if eq $i $l}}
<input id="file-name" value="{{$v}}" placeholder="{{$.i18n.Tr "repo.editor.name_your_file"}}" required autofocus>
<input id="file-name" value="{{$v}}" placeholder="{{$.i18n.Tr "repo.editor.name_your_file"}}" data-ec-url-prefix="{{$.EditorconfigURLPrefix}}" required autofocus>
<span class="octicon octicon-info poping up" data-content="{{$.i18n.Tr "repo.editor.filename_help"}}" data-position="bottom center" data-variation="tiny inverted"></span>
{{else}}
<span class="section"><a href="{{EscapePound $.BranchLink}}/{{EscapePound $v}}">{{$v}}</a></span>