parent
da9c6079f0
commit
bb12838d1c
|
@ -359,6 +359,8 @@ var editors = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editors.autocompleteMutex = true;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
async: false, // 同步执行
|
async: false, // 同步执行
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
@ -414,11 +416,13 @@ var editors = {
|
||||||
|
|
||||||
editor.doc.markClean();
|
editor.doc.markClean();
|
||||||
$(".edit-panel .tabs > div.current > span").removeClass("changed");
|
$(".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)};
|
return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -863,7 +867,8 @@ var editors = {
|
||||||
|
|
||||||
if (config.autocomplete) {
|
if (config.autocomplete) {
|
||||||
var curLine = cm.doc.getLine(cm.getCursor().line).trim().replace(/\W/, "");
|
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);
|
CodeMirror.commands.autocompleteAfterDot(cm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var playground = {
|
var playground = {
|
||||||
|
autocompleteMutex: false,
|
||||||
editor: undefined,
|
editor: undefined,
|
||||||
pid: undefined,
|
pid: undefined,
|
||||||
_resize: function () {
|
_resize: function () {
|
||||||
|
@ -82,6 +83,13 @@ var playground = {
|
||||||
|
|
||||||
var autocompleteHints = [];
|
var autocompleteHints = [];
|
||||||
|
|
||||||
|
if (playground.autocompleteMutex && editor.state.completionActive) {
|
||||||
|
console.log(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
playground.autocompleteMutex = true;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
async: false, // 同步执行
|
async: false, // 同步执行
|
||||||
type: 'POST',
|
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)};
|
return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -184,7 +196,7 @@ var playground = {
|
||||||
".": "autocompleteAfterDot"
|
".": "autocompleteAfterDot"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
playground.editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);
|
playground.editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);
|
||||||
|
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
|
@ -196,7 +208,7 @@ var playground = {
|
||||||
} else {
|
} else {
|
||||||
playground.editor.setSize("auto", $("#editor").height() + "px");
|
playground.editor.setSize("auto", $("#editor").height() + "px");
|
||||||
}
|
}
|
||||||
|
|
||||||
var hovered = false;
|
var hovered = false;
|
||||||
$(".menu .ico-share").hover(function () {
|
$(".menu .ico-share").hover(function () {
|
||||||
$(".menu .share-panel").show();
|
$(".menu .share-panel").show();
|
||||||
|
@ -224,6 +236,14 @@ var playground = {
|
||||||
|
|
||||||
playground.editor.on('changes', function (cm) {
|
playground.editor.on('changes', function (cm) {
|
||||||
$("#url").html("");
|
$("#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();
|
this._initWS();
|
||||||
|
|
|
@ -102,6 +102,7 @@
|
||||||
"channel": "{{.conf.Channel}}",
|
"channel": "{{.conf.Channel}}",
|
||||||
"wideSessionId": "{{.session.ID}}",
|
"wideSessionId": "{{.session.ID}}",
|
||||||
"label": {{.i18n}},
|
"label": {{.i18n}},
|
||||||
|
"autocomplete": {{.conf.Autocomplete}},
|
||||||
"embed": {{.embed}},
|
"embed": {{.embed}},
|
||||||
"disqus": {{.disqus}}
|
"disqus": {{.disqus}}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue