load snippet files automatically
This commit is contained in:
parent
af2a2e272b
commit
156d9a7eeb
3 changed files with 61 additions and 30 deletions
|
|
@ -517,17 +517,9 @@ net.loadScript("https://rawgithub.com/nightwing/emmet-core/master/emmet.js", fun
|
|||
})
|
||||
|
||||
|
||||
require("ace/placeholder").PlaceHolder;
|
||||
// require("ace/placeholder").PlaceHolder;
|
||||
|
||||
var snippetManager = require("ace/snippets").snippetManager
|
||||
var jsSnippets = require("ace/snippets/javascript");
|
||||
window.snippetManager = snippetManager
|
||||
saveSnippets()
|
||||
|
||||
function saveSnippets() {
|
||||
jsSnippets.snippets = snippetManager.parseSnippetFile(jsSnippets.snippetText);
|
||||
snippetManager.register(jsSnippets.snippets, "javascript")
|
||||
}
|
||||
var snippetManager = require("ace/snippets").snippetManager;
|
||||
|
||||
env.editSnippets = function() {
|
||||
var sp = env.split;
|
||||
|
|
@ -538,28 +530,32 @@ env.editSnippets = function() {
|
|||
sp.setSplits(1);
|
||||
sp.setSplits(2);
|
||||
sp.setOrientation(sp.BESIDE);
|
||||
var editor = sp.$editors[1]
|
||||
if (!env.snippetSession) {
|
||||
var file = jsSnippets.snippetText;
|
||||
env.snippetSession = doclist.initDoc(file, "", {});
|
||||
env.snippetSession.setMode("ace/mode/tmsnippet");
|
||||
env.snippetSession.setUseSoftTabs(false);
|
||||
var editor = sp.$editors[1];
|
||||
var id = sp.$editors[0].session.$mode.$id || "";
|
||||
var m = snippetManager.files[id];
|
||||
if (!doclist["snippets/" + id]) {
|
||||
var text = m.snippetText;
|
||||
var s = doclist.initDoc(text, "", {});
|
||||
s.setMode("ace/mode/snippets");
|
||||
doclist["snippets/" + id] = s
|
||||
}
|
||||
editor.on("blur", function() {
|
||||
jsSnippets.snippetText = editor.getValue();
|
||||
saveSnippets();
|
||||
m.snippetText = editor.getValue();
|
||||
snippetManager.unregister(m.snippets);
|
||||
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
||||
snippetManager.register(m.snippets);
|
||||
})
|
||||
editor.setSession(env.snippetSession, 1);
|
||||
sp.$editors[0].once("changeMode", function() {
|
||||
sp.setSplits(1);
|
||||
})
|
||||
editor.setSession(doclist["snippets/" + id], 1);
|
||||
editor.focus();
|
||||
}
|
||||
|
||||
ace.commands.bindKey("Tab", function(editor) {
|
||||
var success = snippetManager.expandWithTab(editor);
|
||||
if (!success)
|
||||
editor.execCommand("indent");
|
||||
require("ace/ext/language_tools");
|
||||
env.editor.setOptions({
|
||||
enableBasicAutocompletion: true,
|
||||
enableSnippets: true
|
||||
})
|
||||
|
||||
require("ace/ext/language_tools");
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue