add includeScopes for velocity mode
This commit is contained in:
parent
a0ab8baa56
commit
c2b097b825
3 changed files with 47 additions and 21 deletions
|
|
@ -46,10 +46,9 @@ var keyWordCompleter = {
|
|||
|
||||
var snippetCompleter = {
|
||||
getCompletions: function(editor, session, pos, prefix, callback) {
|
||||
var scope = snippetManager.$getScope(editor);
|
||||
var snippetMap = snippetManager.snippetMap;
|
||||
var completions = [];
|
||||
[scope, "_"].forEach(function(scope) {
|
||||
snippetManager.getActiveScopes(editor).forEach(function(scope) {
|
||||
var snippets = snippetMap[scope] || [];
|
||||
for (var i = snippets.length; i--;) {
|
||||
var s = snippets[i];
|
||||
|
|
@ -80,22 +79,39 @@ var expandSnippet = {
|
|||
editor.execCommand("indent");
|
||||
},
|
||||
bindKey: "tab"
|
||||
}
|
||||
};
|
||||
|
||||
var onChangeMode = function(e, editor) {
|
||||
var mode = editor.session.$mode;
|
||||
var id = mode.$id
|
||||
if (!snippetManager.files) snippetManager.files = {};
|
||||
if (id && !snippetManager.files[id]) {
|
||||
var snippetFilePath = id.replace("mode", "snippets");
|
||||
config.loadModule(snippetFilePath, function(m) {
|
||||
if (m) {
|
||||
snippetManager.files[id] = m;
|
||||
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
||||
snippetManager.register(m.snippets, m.scope);
|
||||
loadSnippetsForMode(editor.session.$mode);
|
||||
};
|
||||
|
||||
var loadSnippetsForMode = function(mode) {
|
||||
var id = mode.$id;
|
||||
if (!snippetManager.files)
|
||||
snippetManager.files = {};
|
||||
loadSnippetFile(id);
|
||||
if (mode.modes)
|
||||
mode.modes.forEach(loadSnippetsForMode);
|
||||
};
|
||||
|
||||
var loadSnippetFile = function(id) {
|
||||
if (!id || snippetManager.files[id])
|
||||
return;
|
||||
var snippetFilePath = id.replace("mode", "snippets");
|
||||
snippetManager.files[id] = {};
|
||||
config.loadModule(snippetFilePath, function(m) {
|
||||
if (m) {
|
||||
snippetManager.files[id] = m;
|
||||
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
||||
snippetManager.register(m.snippets, m.scope);
|
||||
if (m.includeScopes) {
|
||||
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
|
||||
m.includeScopes.forEach(function(x) {
|
||||
loadSnippetFile("ace/mode/" + x);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var Editor = require("../editor").Editor;
|
||||
|
|
@ -103,7 +119,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
enableBasicAutocompletion: {
|
||||
set: function(val) {
|
||||
if (val) {
|
||||
this.completers = completers
|
||||
this.completers = completers;
|
||||
this.commands.addCommand(Autocomplete.startCommand);
|
||||
} else {
|
||||
this.commands.removeCommand(Autocomplete.startCommand);
|
||||
|
|
@ -116,7 +132,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
if (val) {
|
||||
this.commands.addCommand(expandSnippet);
|
||||
this.on("changeMode", onChangeMode);
|
||||
onChangeMode(null, this)
|
||||
onChangeMode(null, this);
|
||||
} else {
|
||||
this.commands.removeCommand(expandSnippet);
|
||||
this.off("changeMode", onChangeMode);
|
||||
|
|
|
|||
|
|
@ -396,16 +396,26 @@ var SnippetManager = function() {
|
|||
return scope;
|
||||
};
|
||||
|
||||
this.getActiveScopes = function(editor) {
|
||||
var scope = this.$getScope(editor);
|
||||
var scopes = [scope];
|
||||
var snippetMap = this.snippetMap;
|
||||
if (snippetMap[scope] && snippetMap[scope].includeScopes) {
|
||||
scopes.push.apply(scopes, snippetMap[scope].includeScopes);
|
||||
}
|
||||
scopes.push("_");
|
||||
return scopes;
|
||||
};
|
||||
|
||||
this.expandWithTab = function(editor) {
|
||||
var cursor = editor.getCursorPosition();
|
||||
var line = editor.session.getLine(cursor.row);
|
||||
var before = line.substring(0, cursor.column);
|
||||
var after = line.substr(cursor.column);
|
||||
|
||||
var scope = this.$getScope(editor);
|
||||
var snippetMap = this.snippetMap;
|
||||
var snippet;
|
||||
[scope, "_"].some(function(scope) {
|
||||
this.getActiveScopes(editor).some(function(scope) {
|
||||
var snippets = snippetMap[scope];
|
||||
if (snippets)
|
||||
snippet = this.findMatchingSnippet(snippets, before, after);
|
||||
|
|
@ -562,10 +572,9 @@ var SnippetManager = function() {
|
|||
return list;
|
||||
};
|
||||
this.getSnippetByName = function(name, editor) {
|
||||
var scope = editor && this.$getScope(editor);
|
||||
var snippetMap = this.snippetNameMap;
|
||||
var snippet;
|
||||
[scope, "_"].some(function(scope) {
|
||||
this.getActiveScopes(editor).some(function(scope) {
|
||||
var snippets = snippetMap[scope];
|
||||
if (snippets)
|
||||
snippet = snippets[name];
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ define(function(require, exports, module) {
|
|||
|
||||
exports.snippetText = require("../requirejs/text!./velocity.snippets");
|
||||
exports.scope = "velocity";
|
||||
exports.includeScopes = ["html", "javascript", "css"];
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue