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