commit
202ecaac90
4 changed files with 34 additions and 30 deletions
|
|
@ -129,9 +129,9 @@ env.editor.commands.addCommands([{
|
||||||
editor.cmdLine.focus();
|
editor.cmdLine.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var s = SnippetManager.getSnippetByName(needle, editor);
|
var s = snippetManager.getSnippetByName(needle, editor);
|
||||||
if (s)
|
if (s)
|
||||||
SnippetManager.insertSnippet(editor, s.content);
|
snippetManager.insertSnippet(editor, s.content);
|
||||||
},
|
},
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -471,15 +471,14 @@ 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 snippetManager = require("ace/snippets").snippetManager
|
||||||
var jsSnippets = require("ace/snippets/javascript");
|
var jsSnippets = require("ace/snippets/javascript");
|
||||||
window.SnippetManager = SnippetManager
|
window.snippetManager = snippetManager
|
||||||
saveSnippets()
|
saveSnippets()
|
||||||
|
|
||||||
function saveSnippets() {
|
function saveSnippets() {
|
||||||
jsSnippets.snippets = SnippetManager.parseSnippetFile(jsSnippets.snippetText);
|
jsSnippets.snippets = snippetManager.parseSnippetFile(jsSnippets.snippetText);
|
||||||
SnippetManager.snipp
|
snippetManager.register(jsSnippets.snippets, "javascript")
|
||||||
SnippetManager.register(jsSnippets.snippets, "javascript")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
env.editSnippets = function() {
|
env.editSnippets = function() {
|
||||||
|
|
@ -507,7 +506,7 @@ env.editSnippets = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.commands.bindKey("Tab", function(editor) {
|
ace.commands.bindKey("Tab", function(editor) {
|
||||||
var success = SnippetManager.expandWithTab(editor);
|
var success = snippetManager.expandWithTab(editor);
|
||||||
if (!success)
|
if (!success)
|
||||||
editor.execCommand("indent");
|
editor.execCommand("indent");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,10 @@ var SnippetManager = function() {
|
||||||
}, next: "start"},
|
}, next: "start"},
|
||||||
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
|
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
|
||||||
onMatch: function(val, state, stack) {
|
onMatch: function(val, state, stack) {
|
||||||
val = this.splitRegex.exec(val);
|
|
||||||
var ts = stack[0];
|
var ts = stack[0];
|
||||||
|
ts.fmtString = val;
|
||||||
|
|
||||||
|
val = this.splitRegex.exec(val);
|
||||||
ts.guard = val[1];
|
ts.guard = val[1];
|
||||||
ts.fmt = val[2];
|
ts.fmt = val[2];
|
||||||
ts.flag = val[3];
|
ts.flag = val[3];
|
||||||
|
|
@ -230,7 +232,7 @@ var SnippetManager = function() {
|
||||||
continue;
|
continue;
|
||||||
} else if (ch.text) {
|
} else if (ch.text) {
|
||||||
var value = this.getVariableValue(editor, ch.text);
|
var value = this.getVariableValue(editor, ch.text);
|
||||||
if (value && ch.fmt)
|
if (value && ch.fmtString)
|
||||||
value = this.tmStrFormat(value, ch);
|
value = this.tmStrFormat(value, ch);
|
||||||
ch.processed = i;
|
ch.processed = i;
|
||||||
if (ch.expectIf == null) {
|
if (ch.expectIf == null) {
|
||||||
|
|
@ -482,6 +484,7 @@ var SnippetManager = function() {
|
||||||
snippets.forEach(removeSnippet);
|
snippets.forEach(removeSnippet);
|
||||||
};
|
};
|
||||||
this.parseSnippetFile = function(str) {
|
this.parseSnippetFile = function(str) {
|
||||||
|
str = str.replace(/\r/, "");
|
||||||
var list = [], snippet = {};
|
var list = [], snippet = {};
|
||||||
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
|
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
|
||||||
var m;
|
var m;
|
||||||
|
|
@ -498,13 +501,13 @@ var SnippetManager = function() {
|
||||||
} else {
|
} else {
|
||||||
var key = m[2], val = m[3];
|
var key = m[2], val = m[3];
|
||||||
if (key == "regex") {
|
if (key == "regex") {
|
||||||
val = val.split(/\/((?:[^\/\\]|\\.)*)\/?/);
|
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
|
||||||
snippet.guard = val[1];
|
snippet.guard = guardRe.exec(val)[1];
|
||||||
snippet.trigger = val[2];
|
snippet.trigger = guardRe.exec(val)[1];
|
||||||
snippet.endTrigger = val[3];
|
snippet.endTrigger = guardRe.exec(val)[1];
|
||||||
snippet.endGuard = val[4];
|
snippet.endGuard = guardRe.exec(val)[1];
|
||||||
} else if (key == "snippet") {
|
} else if (key == "snippet") {
|
||||||
snippet.tabTrigger = val.split(/^(\S*)(?:\s(.*))?$/)[1];
|
snippet.tabTrigger = val.match(/^\S*/)[0];
|
||||||
if (!snippet.name)
|
if (!snippet.name)
|
||||||
snippet.name = val;
|
snippet.name = val;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -629,7 +632,7 @@ var TabstopManager = function(editor) {
|
||||||
var range = ts[i];
|
var range = ts[i];
|
||||||
if (!range.linked)
|
if (!range.linked)
|
||||||
continue;
|
continue;
|
||||||
var fmt = exports.SnippetManager.tmStrFormat(text, range.original)
|
var fmt = exports.snippetManager.tmStrFormat(text, range.original)
|
||||||
session.replace(range, fmt);
|
session.replace(range, fmt);
|
||||||
}
|
}
|
||||||
this.$inChange = false;
|
this.$inChange = false;
|
||||||
|
|
@ -708,7 +711,7 @@ var TabstopManager = function(editor) {
|
||||||
range.tabstop = ts;
|
range.tabstop = ts;
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
ts[i] = range;
|
ts[i] = range;
|
||||||
if (p.fmt) {
|
if (p.fmtString) {
|
||||||
range.linked = true;
|
range.linked = true;
|
||||||
ts.hasLinkedRanges = true;
|
ts.hasLinkedRanges = true;
|
||||||
} else if (!ts.firstNonLinked)
|
} else if (!ts.firstNonLinked)
|
||||||
|
|
@ -757,7 +760,8 @@ var TabstopManager = function(editor) {
|
||||||
"Esc": function(ed) {
|
"Esc": function(ed) {
|
||||||
ed.tabstopManager.detach();
|
ed.tabstopManager.detach();
|
||||||
},
|
},
|
||||||
"Return": function(ed) {
|
// todo multiselectExec doesn't handle command return values
|
||||||
|
"!Return": function(ed) {
|
||||||
//ed.tabstopManager.tabNext(1);
|
//ed.tabstopManager.tabNext(1);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
@ -787,7 +791,7 @@ require("./lib/dom").importCssString("\
|
||||||
position: absolute;\
|
position: absolute;\
|
||||||
}");
|
}");
|
||||||
|
|
||||||
exports.SnippetManager = new SnippetManager();
|
exports.snippetManager = new SnippetManager();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,9 @@ regex /([,{[])|^\s*/:f/
|
||||||
${0}
|
${0}
|
||||||
}${3:,}
|
}${3:,}
|
||||||
# setTimeout function
|
# setTimeout function
|
||||||
snippet timeout
|
snippet setTimeout
|
||||||
setTimeout(function() {${3}}${2}, ${1:10});
|
regex /\b/st|timeout|setTimeo?u?t?/
|
||||||
|
setTimeout(function() {${3:$TM_SELECTED_TEXT}}, ${1:10});
|
||||||
# Get Elements
|
# Get Elements
|
||||||
snippet gett
|
snippet gett
|
||||||
getElementsBy${1:TagName}('${2}')${3}
|
getElementsBy${1:TagName}('${2}')${3}
|
||||||
|
|
@ -166,12 +167,12 @@ snippet for-
|
||||||
}
|
}
|
||||||
# for (...) {...}
|
# for (...) {...}
|
||||||
snippet for
|
snippet for
|
||||||
for (var ${1:i} = 0; $1 < ${2:Things}.length; $1$++) {
|
for (var ${1:i} = 0; $1 < ${2:Things}.length; $1++) {
|
||||||
${3:$2[$1]}$0
|
${3:$2[$1]}$0
|
||||||
}
|
}
|
||||||
# for (...) {...} (Improved Native For-Loop)
|
# for (...) {...} (Improved Native For-Loop)
|
||||||
snippet forr
|
snippet forr
|
||||||
for (var ${1:i} = ${2:Things}.length - 1; $1 >= 0; $1$--) {
|
for (var ${1:i} = ${2:Things}.length - 1; $1 >= 0; $1--) {
|
||||||
${3:$2[$1]}$0
|
${3:$2[$1]}$0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,13 @@ if (typeof process !== "undefined") {
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var SnippetManager = require("./snippets").SnippetManager;
|
var snippetManager = require("./snippets").snippetManager;
|
||||||
var assert = require("./test/assertions");
|
var assert = require("./test/assertions");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"test: textmate style format strings" : function() {
|
"test: textmate style format strings" : function() {
|
||||||
var fmt = SnippetManager.tmStrFormat;
|
var fmt = snippetManager.tmStrFormat;
|
||||||
SnippetManager.tmStrFormat("hello", {
|
snippetManager.tmStrFormat("hello", {
|
||||||
guard: "(..)(.)(.)",
|
guard: "(..)(.)(.)",
|
||||||
flag:"g",
|
flag:"g",
|
||||||
fmt: "a\\UO\\l$1\\E$2"
|
fmt: "a\\UO\\l$1\\E$2"
|
||||||
|
|
@ -63,7 +63,7 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var parsed = SnippetManager.parseSnippetFile(
|
var parsed = snippetManager.parseSnippetFile(
|
||||||
"name a\nregex /(?:(=)|(:))?\s*)/\\(?f/\\)/\n\t{$0}" +
|
"name a\nregex /(?:(=)|(:))?\s*)/\\(?f/\\)/\n\t{$0}" +
|
||||||
"\n\t\n\n#function\nsnippet f function\n\tfunction"
|
"\n\t\n\n#function\nsnippet f function\n\tfunction"
|
||||||
);
|
);
|
||||||
|
|
@ -72,13 +72,13 @@ module.exports = {
|
||||||
},
|
},
|
||||||
"test: parse snippet": function() {
|
"test: parse snippet": function() {
|
||||||
var content = "-\\$$2a${1:x${$2:y$3\\}\\n\\}$TM_SELECTION}";
|
var content = "-\\$$2a${1:x${$2:y$3\\}\\n\\}$TM_SELECTION}";
|
||||||
var tokens = SnippetManager.tokenizeTmSnippet(content);
|
var tokens = snippetManager.tokenizeTmSnippet(content);
|
||||||
assert.equal(tokens.length, 15);
|
assert.equal(tokens.length, 15);
|
||||||
assert.equal(tokens[4], tokens[14]);
|
assert.equal(tokens[4], tokens[14]);
|
||||||
assert.equal(tokens[2].tabstopId, 2);
|
assert.equal(tokens[2].tabstopId, 2);
|
||||||
|
|
||||||
var content = "\\}${var/as\\/d/\\ul\\//g:s}"
|
var content = "\\}${var/as\\/d/\\ul\\//g:s}"
|
||||||
var tokens = SnippetManager.tokenizeTmSnippet(content);
|
var tokens = snippetManager.tokenizeTmSnippet(content);
|
||||||
assert.equal(tokens.length, 4);
|
assert.equal(tokens.length, 4);
|
||||||
assert.equal(tokens[1], tokens[3]);
|
assert.equal(tokens[1], tokens[3]);
|
||||||
assert.equal(tokens[2], "s");
|
assert.equal(tokens[2], "s");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue