refactor
This commit is contained in:
parent
ec477b5e7a
commit
1c84934a1e
|
@ -5,16 +5,17 @@ var editors = {
|
||||||
editors._initTabs();
|
editors._initTabs();
|
||||||
},
|
},
|
||||||
_initAutocomplete: function() {
|
_initAutocomplete: function() {
|
||||||
CodeMirror.registerHelper("hint", "go", function(editor, options) {
|
CodeMirror.registerHelper("hint", "go", function(editor) {
|
||||||
var word = /[\w$]+/
|
var word = /[\w$]+/;
|
||||||
|
|
||||||
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
||||||
|
|
||||||
var start = cur.ch, end = start;
|
var start = cur.ch, end = start;
|
||||||
while (end < curLine.length && word.test(curLine.charAt(end))) ++end;
|
while (end < curLine.length && word.test(curLine.charAt(end)))
|
||||||
while (start && word.test(curLine.charAt(start - 1))) --start;
|
++end;
|
||||||
var curWord = start != end && curLine.slice(start, end);
|
while (start && word.test(curLine.charAt(start - 1)))
|
||||||
|
--start;
|
||||||
|
|
||||||
var request = {
|
var request = {
|
||||||
code: editor.getValue(),
|
code: editor.getValue(),
|
||||||
cursorLine: editor.getCursor().line,
|
cursorLine: editor.getCursor().line,
|
||||||
|
@ -34,36 +35,31 @@ var editors = {
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var autocompleteArray = data[1];
|
var autocompleteArray = data[1];
|
||||||
|
|
||||||
if (autocompleteArray) {
|
if (autocompleteArray) {
|
||||||
for (var i = 0; i < autocompleteArray.length; i++) {
|
for (var i = 0; i < autocompleteArray.length; i++) {
|
||||||
autocompleteHints[i] = autocompleteArray[i].name;
|
autocompleteHints[i] = autocompleteArray[i].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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)};
|
||||||
});
|
});
|
||||||
|
|
||||||
CodeMirror.commands.autocompleteAfterDot = function(cm) {
|
CodeMirror.commands.autocompleteAfterDot = function(cm) {
|
||||||
var cur = cm.getCursor();
|
setTimeout(function() {
|
||||||
// console.log(cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur));
|
if (!cm.state.completionActive) {
|
||||||
|
cm.showHint({hint: CodeMirror.hint.go, completeSingle: false});
|
||||||
// var token = cm.getTokenAt(cm.getCursor());
|
}
|
||||||
|
}, 50);
|
||||||
setTimeout(function() {
|
|
||||||
if (!cm.state.completionActive) {
|
return CodeMirror.Pass;
|
||||||
cm.showHint({hint: CodeMirror.hint.go, completeSingle: false});
|
};
|
||||||
}
|
|
||||||
}, 50)
|
CodeMirror.commands.autocompleteAnyWord = function(cm) {
|
||||||
|
cm.showHint({hint: CodeMirror.hint.auto});
|
||||||
return CodeMirror.Pass;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
CodeMirror.commands.autocompleteAnyWord = function(cm) {
|
|
||||||
cm.showHint({hint: CodeMirror.hint.auto});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_initTabs: function() {
|
_initTabs: function() {
|
||||||
var $tabsPanel = $(".edit-panel .tabs-panel"),
|
var $tabsPanel = $(".edit-panel .tabs-panel"),
|
||||||
|
@ -90,7 +86,7 @@ var editors = {
|
||||||
|
|
||||||
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
||||||
if (editors.data[i].id === id) {
|
if (editors.data[i].id === id) {
|
||||||
wide.curEditor = editors.data[i].editor;
|
wide.curEditor = editors.data[i].editor;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,10 +129,10 @@ var editors = {
|
||||||
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), {
|
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
theme: 'lesser-dark',
|
theme: 'lesser-dark',
|
||||||
indentUnit: 4,
|
indentUnit: 4,
|
||||||
extraKeys: {
|
extraKeys: {
|
||||||
"Ctrl-\\": "autocompleteAnyWord",
|
"Ctrl-\\": "autocompleteAnyWord",
|
||||||
".": "autocompleteAfterDot"
|
".": "autocompleteAfterDot"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
editor.setSize('100%', 450);
|
editor.setSize('100%', 450);
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
var tabs = function () {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
$.extend(tabs.prototype, {
|
||||||
|
add: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
remove: function () {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue