diff --git a/conf/user.go b/conf/user.go index 3a27a23..2717f8c 100644 --- a/conf/user.go +++ b/conf/user.go @@ -58,9 +58,10 @@ type User struct { FontFamily string FontSize string Theme string - Created int64 // user create time in unix nano - Updated int64 // preference update time in unix nano - Lived int64 // the latest session activity in unix nano + Keymap string // wide/vim + Created int64 // user create time in unix nano + Updated int64 // preference update time in unix nano + Lived int64 // the latest session activity in unix nano Editor *editor LatestSessionContent *LatestSessionContent } @@ -87,6 +88,7 @@ func NewUser(username, password, email, workspace string) *User { return &User{Name: username, Password: password, Salt: salt, Email: email, Gravatar: gravatar, Workspace: workspace, Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default", + Keymap: "wide", Created: now, Updated: now, Lived: now, Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px", Theme: "wide", TabSize: "4"}} diff --git a/conf/users/admin.json b/conf/users/admin.json index 4818c5d..f7baee7 100644 --- a/conf/users/admin.json +++ b/conf/users/admin.json @@ -10,6 +10,7 @@ "FontFamily": "Helvetica", "FontSize": "13px", "Theme": "default", + "Keymap": "wide", "Created": 1414080000000000000, "Updated": 1414080000000000000, "Lived": 1414080000000000000, diff --git a/conf/wide.go b/conf/wide.go index a3ee158..bd903ca 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -126,6 +126,11 @@ func initUsers() { os.Exit(-1) } + // Compatibility upgrade (1.3.0): https://github.com/b3log/wide/issues/83 + if "" == user.Keymap { + user.Keymap = "wide" + } + Users = append(Users, user) } diff --git a/i18n/en_US.json b/i18n/en_US.json index aabe531..ae175f5 100644 --- a/i18n/en_US.json +++ b/i18n/en_US.json @@ -177,5 +177,6 @@ "git_clone": "Git Clone", "terms": "Terms", "download": "Download", - "decompress": "Decompress" + "decompress": "Decompress", + "keymap": "Keymap" } \ No newline at end of file diff --git a/i18n/ja_JP.json b/i18n/ja_JP.json index e7fe0d4..b62794d 100644 --- a/i18n/ja_JP.json +++ b/i18n/ja_JP.json @@ -177,5 +177,6 @@ "git_clone": "Git クローン", "terms": "利用規約", "download": "ダウンロード", - "decompress": "解凍する" + "decompress": "解凍する", + "keymap": "キーマップ" } diff --git a/i18n/zh_CN.json b/i18n/zh_CN.json index d5e2b7e..5dd6ed7 100644 --- a/i18n/zh_CN.json +++ b/i18n/zh_CN.json @@ -177,5 +177,6 @@ "git_clone": "Git 克隆", "terms": "使用条款", "download": "下载", - "decompress": "解压缩" + "decompress": "解压缩", + "keymap": "快捷键" } \ No newline at end of file diff --git a/i18n/zh_TW.json b/i18n/zh_TW.json index 210716e..914bb6b 100644 --- a/i18n/zh_TW.json +++ b/i18n/zh_TW.json @@ -177,5 +177,6 @@ "git_clone": "Git 克隆", "terms": "使用條款", "download": "下載", - "decompress": "解壓縮" + "decompress": "解壓縮", + "keymap": "快捷鍵" } \ No newline at end of file diff --git a/session/users.go b/session/users.go index 8ffacb4..07d8c67 100644 --- a/session/users.go +++ b/session/users.go @@ -96,6 +96,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { FontFamily string FontSize string GoFmt string + Keymap string Workspace string Username string Password string @@ -119,6 +120,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { user.FontFamily = args.FontFamily user.FontSize = args.FontSize user.GoFormat = args.GoFmt + user.Keymap = args.Keymap // XXX: disallow change workspace at present // user.Workspace = args.Workspace if user.Password != args.Password { diff --git a/static/js/editors.js b/static/js/editors.js index 7d796b2..4f9c4f8 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -133,7 +133,7 @@ var editors = { } // set tree node selected - var tId = tree.getTIdByPath(id); + var tId = tree.getTIdByPath(id); var node = tree.fileTree.getNodeByTId(tId); tree.fileTree.selectNode(node); wide.curNode = node; @@ -835,8 +835,7 @@ var editors = { }); editor.on('changes', function (cm) { - if (cm.doc.isClean()) { - // 没有修改过 + if (cm.doc.isClean()) { // no modification $(".edit-panel .tabs > div").each(function () { var $span = $(this).find("span:eq(0)"); if ($span.attr("title") === cm.options.path) { @@ -844,7 +843,6 @@ var editors = { } }); } else { - // 修改过 $(".edit-panel .tabs > div").each(function () { var $span = $(this).find("span:eq(0)"); if ($span.attr("title") === cm.options.path) { @@ -858,6 +856,10 @@ var editors = { editor.setOption("mode", data.mode); editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]); + if ("wide" !== config.keymap) { + editor.setOption("keyMap", config.keymap); + } + if ("text/x-go" === data.mode || "application/json" === data.mode) { editor.setOption("lint", true); } diff --git a/static/js/menu.js b/static/js/menu.js index e70f09a..1a827c7 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -426,7 +426,8 @@ var menu = { $editorFontSize = $dialogPreference.find("input[name=editorFontSize]"), $editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"), $editorTheme = $dialogPreference.find("select[name=editorTheme]"), - $editorTabSize = $dialogPreference.find("input[name=editorTabSize]"); + $editorTabSize = $dialogPreference.find("input[name=editorTabSize]"), + $keymap = $dialogPreference.find("select[name=keymap]"); $.extend(request, { "fontFamily": $fontFamily.val(), @@ -441,8 +442,13 @@ var menu = { "editorFontSize": $editorFontSize.val(), "editorLineHeight": $editorLineHeight.val(), "editorTheme": $editorTheme.val(), - "editorTabSize": $editorTabSize.val() + "editorTabSize": $editorTabSize.val(), + "keymap": $keymap.val() }); + + if (config.keymap !== $keymap.val()) { + window.location.reload(); + } $.ajax({ type: 'POST', @@ -466,6 +472,10 @@ var menu = { $editorLineHeight.data("value", $editorLineHeight.val()); $editorTheme.data("value", $editorTheme.val()); $editorTabSize.data("value", $editorTabSize.val()); + $keymap.data("value", $keymap.val()); + + // update the config + config.keymap = $keymap.val(); var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); $okBtn.prop("disabled", true); diff --git a/views/index.html b/views/index.html index a0ffb45..a3af2dd 100644 --- a/views/index.html +++ b/views/index.html @@ -608,7 +608,8 @@ "wideSessionId": '{{.session.ID}}', "editorTheme": '{{.user.Editor.Theme}}', "latestSessionContent": {{.latestSessionContent}}, - "editorTabSize": '{{.user.Editor.TabSize}}' + "editorTabSize": '{{.user.Editor.TabSize}}', + "keymap": '{{.user.Keymap}}' }; // 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数. function newWideRequest() { @@ -657,6 +658,8 @@ + + diff --git a/views/preference.html b/views/preference.html index 49526d6..f5040c0 100644 --- a/views/preference.html +++ b/views/preference.html @@ -9,6 +9,9 @@