Fix #25
This commit is contained in:
parent
fef4a30801
commit
0062f92da8
|
@ -64,15 +64,16 @@ var editors = {
|
|||
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
||||
|
||||
var start = cur.ch, end = start;
|
||||
while (end < curLine.length && word.test(curLine.charAt(end)))
|
||||
while (end < curLine.length && word.test(curLine.charAt(end))) {
|
||||
++end;
|
||||
while (start && word.test(curLine.charAt(start - 1)))
|
||||
}
|
||||
while (start && word.test(curLine.charAt(start - 1))) {
|
||||
--start;
|
||||
|
||||
}
|
||||
var request = {
|
||||
code: editor.getValue(),
|
||||
cursorLine: editor.getCursor().line,
|
||||
cursorCh: editor.getCursor().ch
|
||||
cursorLine: cur.line,
|
||||
cursorCh: cur.ch
|
||||
};
|
||||
|
||||
var autocompleteHints = [];
|
||||
|
@ -110,6 +111,36 @@ 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;
|
||||
};
|
||||
},
|
||||
newEditor: function(data) {
|
||||
$(".ico-fullscreen").show();
|
||||
|
@ -142,7 +173,12 @@ var editors = {
|
|||
},
|
||||
"F11": function(cm) {
|
||||
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
||||
}
|
||||
},
|
||||
"'('": "autocompleteRightPart",
|
||||
"'['": "autocompleteRightPart",
|
||||
"'{'": "autocompleteRightPart",
|
||||
"'\"'": "autocompleteRightPart",
|
||||
"'''": "autocompleteRightPart",
|
||||
}
|
||||
});
|
||||
editor.setSize('100%', 430);
|
||||
|
|
Loading…
Reference in New Issue