自动完成括号

This commit is contained in:
Liang Ding 2014-09-06 22:23:46 +08:00
parent 7d7d841505
commit 60c820697c
2 changed files with 2 additions and 35 deletions

View File

@ -117,36 +117,6 @@ var editors = {
cm.showHint({hint: CodeMirror.hint.auto}); 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) { CodeMirror.commands.gotoLine = function(cm) {
var line = prompt("Go To Line: ", "0"); var line = prompt("Go To Line: ", "0");
@ -178,6 +148,7 @@ var editors = {
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), { var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), {
lineNumbers: true, lineNumbers: true,
autoCloseBrackets: true,
highlightSelectionMatches: {showToken: /\w/}, highlightSelectionMatches: {showToken: /\w/},
rulers: rulers, rulers: rulers,
styleActiveLine: true, styleActiveLine: true,
@ -194,11 +165,6 @@ var editors = {
"F11": function(cm) { "F11": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen")); cm.setOption("fullScreen", !cm.getOption("fullScreen"));
}, },
"'('": "autocompleteRightPart",
"'['": "autocompleteRightPart",
"'{'": "autocompleteRightPart",
"'\"'": "autocompleteRightPart",
"'''": "autocompleteRightPart",
"Ctrl-G": "gotoLine", "Ctrl-G": "gotoLine",
"Ctrl-E": "deleteLine", "Ctrl-E": "deleteLine",
"Ctrl-D": "doNothing" // 取消默认的 deleteLine "Ctrl-D": "doNothing" // 取消默认的 deleteLine

View File

@ -101,6 +101,7 @@
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/hint/anyword-hint.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/hint/anyword-hint.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/display/fullscreen.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/display/fullscreen.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/display/rulers.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/display/rulers.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/edit/closebrackets.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/searchcursor.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/searchcursor.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/match-highlighter.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/match-highlighter.js"></script>
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/mode/go/go.js"></script> <script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/mode/go/go.js"></script>