add snippet editor to the demo

This commit is contained in:
nightwing 2013-03-19 18:27:09 +04:00
commit 19ea0fe979
9 changed files with 274 additions and 142 deletions

View file

@ -1,132 +1,209 @@
[[
"start",
["doc,comment","$$------------------------------------"]
["comment","# Function"]
],[
"start"
],[
"start",
["text","tabTrigger: t"]
["constant.language.escape","snippet"],
["text"," fun"]
],[
"start"
],[
"start",
["text","name: Heading 3"]
],[
"start"
],[
"start",
["text","scope: language"]
],[
"start"
],[
"start",
["text","content: -----------------------------"]
],[
"start"
],[
"start",
["text","\\begin{"],
"sn-start",
["text","\tfunction "],
["markup.list","${"],
["constant.numeric","1"],
["punctuation.operator",":"],
["text","documnet"],
["text","?:function_name"],
["markup.list","}"],
["text","}"]
],[
"start"
],[
"start",
["text"," "],
["text","("],
["markup.list","${"],
["constant.numeric","2"],
["punctuation.operator",":"],
["keyword","$TM_SELECTED_TEXT"],
["text",":some latex"],
["markup.list","}"]
["text","argument"],
["markup.list","}"],
["text",") {"]
],[
"start"
],[
"start",
["text"," "],
"sn-start",
["text","\t\t"],
["markup.list","${"],
["constant.numeric","3"],
["punctuation.operator",":"],
["text","// body..."],
["markup.list","}"]
],[
"start"
],[
"sn-start",
["text","\t}"]
],[
"start"
],[
"start",
["comment","# Anonymous Function"]
],[
"start"
],[
"start",
["constant.language.escape","regex "],
["keyword","/"],
["text","((=)\\s*|(:)\\s*|(\\()|\\b)"],
["keyword","/"],
["text","f"],
["keyword","/"],
["text","(\\))?"],
["keyword","/"]
],[
"start"
],[
"start",
["constant.language.escape","name"],
["text"," f"]
],[
"start"
],[
"sn-start",
["text","\tfunction"],
["markup.list","${"],
["variable","M1"],
["text","?: "],
["markup.list","${"],
["constant.numeric","1"],
["punctuation.operator",":"],
["text","functionName"],
["markup.list","}}"],
["text","("],
["variable","$2"],
["text",") {"]
],[
"start"
],[
"sn-start",
["text","\t\t"],
["markup.list","${"],
["constant.numeric","0"],
["punctuation.operator",":"],
["keyword","$TM_SELECTED_TEXT"],
["text","/a/b/c"],
["markup.list","}"]
],[
"start"
],[
"sn-start",
["text","\t}"],
["markup.list","${"],
["variable","M2"],
["text","?;"],
["markup.list","}${"],
["variable","M3"],
["text","?,"],
["markup.list","}${"],
["variable","M4"],
["text","?)"],
["markup.list","}"]
],[
"start"
],[
"start",
["text"," "],
["comment","# Immediate function"]
],[
"start"
],[
"start",
["constant.language.escape","trigger"],
["text"," \\(?f\\("]
],[
"start"
],[
"start",
["constant.language.escape","endTrigger"],
["text"," \\)?"]
],[
"start"
],[
"start",
["constant.language.escape","snippet"],
["text"," f("]
],[
"start"
],[
"sn-start",
["text","\t(function("],
["markup.list","${"],
["constant.numeric","4"],
["constant.numeric","1"],
["markup.list","}"],
["text",") {"]
],[
"start"
],[
"sn-start",
["text","\t\t"],
["markup.list","${"],
["constant.numeric","0"],
["punctuation.operator",":"],
["markup.list","${"],
["keyword","TM_SELECTED_TEXT"],
["string.regex","/(.)/"],
["string","\\"],
["keyword","\\u"],
["variable","$1"],
["string.regex","/g:"],
["text","7"],
["punctuation.operator",":"],
["text","/* code */"],
["markup.list","}}"]
],[
"start"
],[
"start",
["text","\\end{"],
["variable","$1"],
["text","}"]
],[
"start"
],[
"start",
["variable","$0"],
["constant.language.escape","\\\\"],
["text","$$"]
],[
"start"
],[
"start",
["doc,comment","$$------------------------------------"]
],[
"start"
],[
"start",
["text","tabTrigger: ^3"]
],[
"start"
],[
"start",
["text","name: Heading 3"]
],[
"start"
],[
"start",
["text","scope: language"]
],[
"start"
],[
"start",
["text","content: -----------------------------"]
],[
"start"
],[
"start"
],[
"start"
],[
"start",
"sn-start",
["text","\t}("],
["markup.list","${"],
["keyword","TM_CURRENT_LINE"],
["string.regex","/./"],
["string","^"],
["string.regex","/g"],
["constant.numeric","1"],
["markup.list","}"],
["text","));"]
],[
"start"
],[
"start",
["comment","# if"]
],[
"start"
],[
"start",
["constant.language.escape","snippet"],
["text"," if"]
],[
"start"
],[
"sn-start",
["text","\tif ("],
["markup.list","${"],
["constant.numeric","1"],
["punctuation.operator",":"],
["text","true"],
["markup.list","}"],
["text",") {"]
],[
"start"
],[
"sn-start",
["text","\t\t"],
["markup.list","${"],
["constant.numeric","0"],
["markup.list","}"]
],[
"start"
],[
"start",
["doc,comment","$$------------------------------------"]
"sn-start",
["text","\t}"]
],[
"start"
],[
"sn-start",
["text","\t"]
],[
"start"
],[
"sn-start",
["text","\t"]
],[
"start"
],[
"sn-start",
["text","\t"]
]]

View file

@ -20,7 +20,7 @@ var SnippetHighlightRules = function() {
if (stack[1])
stack[1]++;
else
stack.unshift("start", 1);
stack.unshift(state, 1);
return this.tokenName;
}, tokenName: "markup.list", regex: "\\${", next: "varDecl"},
{onMatch: function(value, state, stack) {
@ -31,7 +31,7 @@ var SnippetHighlightRules = function() {
stack.splice(0,2);
return this.tokenName;
}, tokenName: "markup.list", regex: "}"},
{token: "doc,comment", regex:/^\${2}-{5,}$/}
{token: "doc.comment", regex:/^\${2}-{5,}$/}
],
"varDecl" : [
{regex: /\d+\b/, token: "constant.numeric"},
@ -62,15 +62,44 @@ var SnippetHighlightRules = function() {
]
};
};
oop.inherits(SnippetHighlightRules, TextHighlightRules);
exports.SnippetHighlightRules = SnippetHighlightRules;
var SnippetGroupHighlightRules = function() {
this.$rules = {
"start" : [
{token: "text", regex: "^\\t", next: "sn-start"},
{token:"invalid", regex: /^ \s*/},
{token:"comment", regex: /^#.*/},
{token:"constant.language.escape", regex: "^regex ", next: "regex"},
{token:"constant.language.escape", regex: "^(trigger|endTrigger|name|snippet|guard|endGuard|tabTrigger|key)\\b"}
],
"regex" : [
{token:"text", regex: "\\."},
{token:"keyword", regex: "/"},
{token:"empty", regex: "$", next: "start"}
]
};
this.embedRules(SnippetHighlightRules, "sn-", [
{token: "text", regex: "^\\t", next: "sn-start"},
{onMatch: function(value, state, stack) {
stack.splice(stack.length);
return this.tokenName;
}, tokenName: "text", regex: "^(?!\t)", next: "start"},
])
};
oop.inherits(SnippetGroupHighlightRules, TextHighlightRules);
exports.SnippetGroupHighlightRules = SnippetGroupHighlightRules;
var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
var highlighter = new SnippetHighlightRules();
var highlighter = new SnippetGroupHighlightRules();
this.foldingRules = new FoldMode();
this.$tokenizer = new Tokenizer(highlighter.getRules());
};
oop.inherits(Mode, TextMode);

View file

@ -619,6 +619,8 @@ var TabstopManager = function(editor) {
var anchor = this.editor.selection.anchor;
var isEmpty = this.editor.selection.isEmpty();
for (var i = this.ranges.length; i--;) {
if (this.ranges[i].linked)
continue;
var containsLead = this.ranges[i].contains(lead.row, lead.column);
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
if (containsLead && containsAnchor)

View file

@ -1,6 +1,6 @@
# Prototype
snippet proto
${1:class_name}.prototype.${2:method_name} = function(${3irst_argument}) {
${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) {
${4:// body...}
};
# Function