From 5e5d13965a31fcc4d374956c0397d059f2b52db2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 14 Sep 2014 00:07:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=A0=91=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/zh_CN/keyboard_shortcuts.html | 3 +- editor/editors.go | 4 +- static/js/editor.js | 2 +- static/js/tree.js | 7 --- static/js/wide.js | 96 ++++++++++++++++++++++--------- view/index.html | 2 +- 6 files changed, 73 insertions(+), 41 deletions(-) diff --git a/doc/zh_CN/keyboard_shortcuts.html b/doc/zh_CN/keyboard_shortcuts.html index 4b6337b..651fb68 100644 --- a/doc/zh_CN/keyboard_shortcuts.html +++ b/doc/zh_CN/keyboard_shortcuts.html @@ -19,7 +19,7 @@
  • Ctrl+]: 缩进
  • Ctrl+[: 反缩进
  • - + TBD: diff --git a/editor/editors.go b/editor/editors.go index a359ac1..1f69886 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -191,7 +191,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { ch := int(args["cursorCh"].(float64)) offset := getCursorOffset(code, line, ch) - glog.Infof("offset [%d]", offset) + // glog.Infof("offset [%d]", offset) // TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现 argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."} @@ -221,8 +221,6 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")] cursorCh := found[strings.LastIndex(found, ":")+1:] - glog.Infof("Find Decl [path: %s, cursor(%s:%s)]", path, cursorLine, cursorCh) - data["path"] = path data["cursorLine"] = cursorLine data["cursorCh"] = cursorCh diff --git a/static/js/editor.js b/static/js/editor.js index ff63124..2c1af85 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -63,6 +63,7 @@ var editors = { }, fullscreen: function() { wide.curEditor.setOption("fullScreen", true); + wide.curEditor.focus(); }, _initAutocomplete: function() { CodeMirror.registerHelper("hint", "go", function(editor) { @@ -274,7 +275,6 @@ var editors = { $("#footer-cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |'); // TODO: 关闭 tab 的时候要重置 - // TODO: 保存当前编辑器光标位置,切换 tab 的时候要设置回来 }); editor.setSize('100%', $(".edit-panel").height() - $(".edit-header").height()); diff --git a/static/js/tree.js b/static/js/tree.js index f1297c0..f5e6d49 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -205,13 +205,6 @@ var tree = { }, _onClick: function(treeNode) { if (wide.curNode) { - var id = wide.curNode.tId; - if (id === treeNode.tId) { - // 再次点击当前选中节点 - return false; - } - - for (var i = 0, ii = editors.data.length; i < ii; i++) { // 该节点文件已经打开 if (editors.data[i].id === treeNode.tId) { diff --git a/static/js/wide.js b/static/js/wide.js index 874bd9a..a5efc0a 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -1,9 +1,9 @@ var outputWS = new WebSocket(config.channel.output + '/output/ws'); -outputWS.onopen = function() { +outputWS.onopen = function () { console.log('[output onopen] connected'); }; -outputWS.onmessage = function(e) { +outputWS.onmessage = function (e) { console.log('[output onmessage]' + e.data); var data = JSON.parse(e.data); @@ -43,37 +43,37 @@ outputWS.onmessage = function(e) { url: '/run', data: JSON.stringify(request), dataType: "json", - beforeSend: function(data) { + beforeSend: function (data) { $('#output').text(''); }, - success: function(data) { + success: function (data) { } }); } } }; -outputWS.onclose = function(e) { +outputWS.onclose = function (e) { console.log('[output onclose] disconnected (' + e.code + ')'); delete outputWS; }; -outputWS.onerror = function(e) { +outputWS.onerror = function (e) { console.log('[output onerror] ' + e); }; var wide = { curNode: undefined, curEditor: undefined, - _initLayout: function() { + _initLayout: function () { var mainH = $(window).height() - $(".menu").height() - $(".footer").height() - 2; $(".content, .ztree").height(mainH); $(".edit-panel").height(mainH - $(".output").height()); }, - init: function() { + init: function () { this._initLayout(); - $("body").bind("mousedown", function(event) { + $("body").bind("mousedown", function (event) { if (!(event.target.id === "dirRMenu" || $(event.target).closest("#dirRMenu").length > 0)) { $("#dirRMenu").hide(); } @@ -88,8 +88,10 @@ var wide = { menu.subMenu(); } }); + + this._bindKey(); }, - saveFile: function() { + saveFile: function () { var request = { file: $(".edit-header .current span:eq(0)").attr("title"), code: wide.curEditor.getValue() @@ -99,23 +101,23 @@ var wide = { url: '/file/save', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { } }); }, - saveAllFiles: function() { + saveAllFiles: function () { // TODO: save all }, - closeFile: function() { + closeFile: function () { // TODO: save all }, - closeAllFiles: function() { + closeAllFiles: function () { // TODO: save all }, - exit: function() { + exit: function () { // TODO: exit }, - run: function() { + run: function () { var request = { file: $(".edit-header .current span:eq(0)").attr("title"), code: wide.curEditor.getValue() @@ -126,14 +128,14 @@ var wide = { url: '/build', data: JSON.stringify(request), dataType: "json", - beforeSend: function(data) { + beforeSend: function (data) { $('#output').text(''); }, - success: function(data) { + success: function (data) { } }); }, - goget: function() { + goget: function () { var request = { file: $(".edit-header .current span:eq(0)").attr("title") }; @@ -143,14 +145,14 @@ var wide = { url: '/go/get', data: JSON.stringify(request), dataType: "json", - beforeSend: function(data) { + beforeSend: function (data) { $('#output').text(''); }, - success: function(data) { + success: function (data) { } }); }, - goinstall: function() { + goinstall: function () { var request = { file: $(".edit-header .current span:eq(0)").attr("title"), code: wide.curEditor.getValue() @@ -161,14 +163,14 @@ var wide = { url: '/go/install', data: JSON.stringify(request), dataType: "json", - beforeSend: function(data) { + beforeSend: function (data) { $('#output').text(''); }, - success: function(data) { + success: function (data) { } }); }, - fmt: function() { + fmt: function () { var path = $(".edit-header .current span:eq(0)").attr("title"); var mode = wide.curNode.mode; @@ -186,7 +188,7 @@ var wide = { url: '/go/fmt', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (data.succ) { wide.curEditor.setValue(data.code); } @@ -200,7 +202,7 @@ var wide = { url: '/html/fmt', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (data.succ) { wide.curEditor.setValue(data.code); } @@ -224,12 +226,50 @@ var wide = { // TODO: XML/JSON 格式化处理 break; } + }, + _bindKey: function () { + $("#files").keydown(function (event) { + if (!wide.curNode) { + return false; + } + switch (event.which) { + case 13: // 回车 + if (wide.curNode.iconSkin === "ico-ztree-dir ") { // 选中节点是目录 + // 不做任何处理 + return false; + } + // 模拟点击:打开文件 + tree._onClick(wide.curNode); + + break; + case 38: // 上 + tree.fileTree.selectNode(wide.curNode.getPreNode()); + wide.curNode = wide.curNode.getPreNode(); + $("#files").focus(); + break; + case 40: // 下 + // TODO: 处理滚动条,递归获取下一个 + tree.fileTree.selectNode(wide.curNode.getNextNode()); + wide.curNode = wide.curNode.getNextNode(); + $("#files").focus(); + break; + } + }); + + $(document).keydown(function (event) { + if (event.ctrlKey && event.which === 49) { // Ctrl+1 焦点切换到文件树 + + // 有些元素需设置 tabindex 为 -1 时才可以 focus + $("#files").focus(); + event.preventDefault(); + } + }); } }; -$(document).ready(function() { +$(document).ready(function () { wide.init(); tree.init(); menu.init(); diff --git a/view/index.html b/view/index.html index 5cab88f..48f4677 100644 --- a/view/index.html +++ b/view/index.html @@ -103,7 +103,7 @@
    -
      +