文件树快捷键

This commit is contained in:
Liang Ding 2014-09-14 00:07:03 +08:00
parent 1be309b08a
commit 5e5d13965a
6 changed files with 73 additions and 41 deletions

View File

@ -19,7 +19,7 @@
<li>Ctrl+]: 缩进</li>
<li>Ctrl+[: 反缩进</li>
</ul>
TBD:
<ul>
<li>Alt+F7查找使用</li>
@ -27,6 +27,7 @@
<li>Ctrl+0焦点切换到编辑器</li>
<li>Ctrl+W关闭当前编辑器</li>
<li>Ctrl+4焦点切换到 Output</li>
<li>Alt+Shift+F格式化</li>
</ul>
</body>
</html>

View File

@ -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

View File

@ -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());

View File

@ -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) {

View File

@ -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();

View File

@ -103,7 +103,7 @@
<div class="content">
<div class="side">
<div class="side-1">
<ul id="files" class="ztree"></ul>
<ul id="files" tabindex="-1" class="ztree"></ul>
<!-- 目录右键菜单 -->
<div id="dirRMenu" class="frame">