From 3b7413a680cbf4c3ff3a4b9e486b53dce509f987 Mon Sep 17 00:00:00 2001 From: Van Date: Fri, 10 Oct 2014 18:04:03 +0800 Subject: [PATCH] Ctrl+I --- conf/wide.json | 18 +++++++++++++++--- static/css/wide.css | 24 ++++++++++++++++++++++++ static/js/editors.js | 23 ++++++++++++++--------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/conf/wide.json b/conf/wide.json index 1b0f0d3..765a0ab 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -15,9 +15,21 @@ "Password": "admin", "Workspace": "{pwd}/data/user_workspaces/admin", "LatestSessionContent": { - "FileTree": [], - "Files": [], - "CurrentFile": "" + "FileTree": [ + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest", + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello", + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time", + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\pkg", + "D:\\go\\src\\pkg", + "D:\\go\\src\\pkg\\archive", + "D:\\go\\src\\pkg\\archive\\tar", + "D:\\go\\src\\pkg\\archive\\tar\\testdata" + ], + "Files": [ + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello\\main.go", + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go" + ], + "CurrentFile": "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go" } } ] diff --git a/static/css/wide.css b/static/css/wide.css index 4ae63ae..2aa8911 100644 --- a/static/css/wide.css +++ b/static/css/wide.css @@ -192,6 +192,30 @@ width: 16px; } +/* 统一为 static/js/lib/codemirror-4.5/addon/hint/show-hint.css 中的.CodeMirror-hints */ +.edit-exprinfo { + position: absolute; + z-index: 10; + overflow: hidden; + list-style: none; + + margin: 0; + padding: 2px; + + -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); + -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); + box-shadow: 2px 3px 5px rgba(0,0,0,.2); + border-radius: 3px; + border: 1px solid silver; + + background: white; + font-size: 90%; + font-family: monospace; + + max-height: 20em; + overflow-y: auto; +} + .CodeMirror-focused .cm-matchhighlight { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==); background-position: bottom; diff --git a/static/js/editors.js b/static/js/editors.js index 6b4360b..a6b4912 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -107,6 +107,7 @@ var editors = { for (var i = 0; i < autocompleteArray.length; i++) { var displayText = ''; + // TODO: 图标 switch (autocompleteArray[i].class) { case "type": case "const": @@ -125,13 +126,11 @@ var editors = { break; default: console.warn("Can't handle autocomplete [" + autocompleteArray[i].class + "]"); - + break; } autocompleteHints[i] = { - // TODO: 添加类型、图标 - displayText: displayText, text: autocompleteArray[i].name }; @@ -164,7 +163,7 @@ var editors = { // 用于覆盖 cm 默认绑定的某些快捷键功能. CodeMirror.commands.doNothing = function (cm) { }; - + CodeMirror.commands.exprInfo = function (cm) { var cur = wide.curEditor.getCursor(); @@ -180,12 +179,13 @@ var editors = { data: JSON.stringify(request), dataType: "json", success: function (data) { - // TODO: V - console.log(data); - if (!data.succ) { return; } + var position = wide.curEditor.cursorCoords(); + $("body").append('
' + data.info + '
'); } }); }; @@ -331,6 +331,7 @@ var editors = { }); editor.on('cursorActivity', function (cm) { + $(".edit-exprinfo").remove(); var cursor = cm.getCursor(); $(".footer .cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |'); @@ -341,9 +342,13 @@ var editors = { windows.clearFloat(); }); + editor.on('blur', function (cm) { + $(".edit-exprinfo").remove(); + }); + editor.setSize('100%', $(".edit-panel").height() - $(".edit-panel .tabs").height()); editor.setValue(data.content); - editor.setOption("mode", data.mode); + editor.setOption("mode", data.mode); editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]); if ("text/x-go" === data.mode || "application/json" === data.mode) { @@ -353,7 +358,7 @@ var editors = { if ("application/xml" === data.mode || "text/html" === data.mode) { editor.setOption("autoCloseTags", true); } - + editor.setCursor(cursor); wide.curEditor = editor;