Enhance autocompletion

IDE & Playground
This commit is contained in:
Liang Ding 2015-06-15 21:50:51 +08:00
parent da9c6079f0
commit bb12838d1c
3 changed files with 31 additions and 5 deletions

View File

@ -359,6 +359,8 @@ var editors = {
return;
}
editors.autocompleteMutex = true;
$.ajax({
async: false, // 同步执行
type: 'POST',
@ -414,11 +416,13 @@ var editors = {
editor.doc.markClean();
$(".edit-panel .tabs > div.current > span").removeClass("changed");
editors.autocompleteMutex = false;
}
});
setTimeout(function () {
editors.autocompleteMutex = false;
}, 20);
return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
@ -863,7 +867,8 @@ var editors = {
if (config.autocomplete) {
var curLine = cm.doc.getLine(cm.getCursor().line).trim().replace(/\W/, "");
if (0.5 <= Math.random() && "" !== curLine && /^\w+$/.test(curLine)) {
if (1 === curLine.length || 0.5 <= Math.random() && "" !== curLine && /^\w+$/.test(curLine)) {
CodeMirror.commands.autocompleteAfterDot(cm);
}
}

View File

@ -15,6 +15,7 @@
*/
var playground = {
autocompleteMutex: false,
editor: undefined,
pid: undefined,
_resize: function () {
@ -82,6 +83,13 @@ var playground = {
var autocompleteHints = [];
if (playground.autocompleteMutex && editor.state.completionActive) {
console.log(1);
return;
}
playground.autocompleteMutex = true;
$.ajax({
async: false, // 同步执行
type: 'POST',
@ -137,6 +145,10 @@ var playground = {
}
});
setTimeout(function () {
playground.autocompleteMutex = false;
}, 20);
return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
@ -224,6 +236,14 @@ var playground = {
playground.editor.on('changes', function (cm) {
$("#url").html("");
if (config.autocomplete) {
var curLine = cm.doc.getLine(cm.getCursor().line).trim().replace(/\W/, "");
if (1 === curLine.length || 0.5 <= Math.random() && "" !== curLine && /^\w+$/.test(curLine)) {
CodeMirror.commands.autocompleteAfterDot(cm);
}
}
});
this._initWS();

View File

@ -102,6 +102,7 @@
"channel": "{{.conf.Channel}}",
"wideSessionId": "{{.session.ID}}",
"label": {{.i18n}},
"autocomplete": {{.conf.Autocomplete}},
"embed": {{.embed}},
"disqus": {{.disqus}}
};