From 77afacc3b1143224395d8c65643af855c4380fbb Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 3 Sep 2014 00:05:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=A9=E8=BF=9B=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/zh_CN/keyboard_shortcuts.html | 6 +- static/js/editor.js | 91 ++++++++++++++++--------------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/doc/zh_CN/keyboard_shortcuts.html b/doc/zh_CN/keyboard_shortcuts.html index c7a0225..c942992 100644 --- a/doc/zh_CN/keyboard_shortcuts.html +++ b/doc/zh_CN/keyboard_shortcuts.html @@ -9,11 +9,13 @@

键盘快捷键

diff --git a/static/js/editor.js b/static/js/editor.js index 8f7b7c1..cb0384b 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -66,10 +66,10 @@ var editors = { var start = cur.ch, end = start; while (end < curLine.length && word.test(curLine.charAt(end))) { ++end; - } + } while (start && word.test(curLine.charAt(start - 1))) { --start; - } + } var request = { code: editor.getValue(), cursorLine: cur.line, @@ -111,42 +111,45 @@ var editors = { CodeMirror.commands.autocompleteAnyWord = function(cm) { cm.showHint({hint: CodeMirror.hint.auto}); }; - - CodeMirror.commands.autocompleteRightPart = function(cm) { - setTimeout(function() { - var cur = cm.getCursor(); - var curLine = cm.getLine(cur.line); - var curChar = curLine.charAt(cur.ch - 1); - - replacement = ''; - - switch (curChar) { - case '(': - replacement = ')'; - break; - case '[': - replacement = ']'; - break; - case '{': - replacement = '}'; - break; - default: // " or ' - replacement = curChar; - break; - } - - cm.replaceRange(replacement, CodeMirror.Pos(cur.line, cur.ch)); - cm.setCursor(CodeMirror.Pos(cur.line, cur.ch)); - }, 50); - - return CodeMirror.Pass; - }; - - CodeMirror.commands.gotoLine = function(cm) { - var line = prompt("Go To Line: ", "0"); - + + CodeMirror.commands.autocompleteRightPart = function(cm) { + setTimeout(function() { + var cur = cm.getCursor(); + var curLine = cm.getLine(cur.line); + var curChar = curLine.charAt(cur.ch - 1); + + replacement = ''; + + switch (curChar) { + case '(': + replacement = ')'; + break; + case '[': + replacement = ']'; + break; + case '{': + replacement = '}'; + break; + default: // " or ' + replacement = curChar; + break; + } + + cm.replaceRange(replacement, CodeMirror.Pos(cur.line, cur.ch)); + cm.setCursor(CodeMirror.Pos(cur.line, cur.ch)); + }, 50); + + return CodeMirror.Pass; + }; + + CodeMirror.commands.gotoLine = function(cm) { + var line = prompt("Go To Line: ", "0"); + cm.setCursor(CodeMirror.Pos(line - 1, 0)); }; + + CodeMirror.commands.doNothing = function(cm) { + }; }, newEditor: function(data) { $(".ico-fullscreen").show(); @@ -167,7 +170,7 @@ var editors = { var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), { lineNumbers: true, - styleActiveLine: true, + styleActiveLine: true, theme: 'lesser-dark', indentUnit: 4, extraKeys: { @@ -181,12 +184,14 @@ var editors = { "F11": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, - "'('": "autocompleteRightPart", - "'['": "autocompleteRightPart", - "'{'": "autocompleteRightPart", - "'\"'": "autocompleteRightPart", - "'''": "autocompleteRightPart", - "Ctrl-G": "gotoLine" + "'('": "autocompleteRightPart", + "'['": "autocompleteRightPart", + "'{'": "autocompleteRightPart", + "'\"'": "autocompleteRightPart", + "'''": "autocompleteRightPart", + "Ctrl-G": "gotoLine", + "Ctrl-E": "deleteLine", + "Ctrl-D": "doNothing" // 取消默认的 deleteLine } }); editor.setSize('100%', $(".edit-panel").height() - $(".edit-header").height());