Permalink
Browse files

Insert text *after* cursor.

  • Loading branch information...
1 parent 21cdead commit a5973fe5d00eb1cf2e6e46b485416fff7f9f96bd @luqui committed Jun 21, 2011
Showing with 6 additions and 5 deletions.
  1. +1 −1 StructuralFramework.js
  2. +3 −2 StructuralGrammar.js
  3. +2 −2 demo/structural.html
@@ -350,7 +350,7 @@ $$.render_cursor = function(cursor, ins) {
if (typeof(ins) === 'undefined') { ins = $([]) }
var args = cursor.zipper.expr.args.map(function(a,i) {
var r = render_expr_tree(a);
- return i == cursor.pos ? elt('span', {'class': 'cursor_selected'}, ins, r) : r;
+ return i == cursor.pos ? $(ins).add(elt('span', {'class': 'cursor_selected'}, r)) : r;
});
if (args.length > 0 && cursor.pos == cursor.zipper.expr.length) {
args[args.length-1] = elt('span', {'class': 'cursor_selected_right'}, args[args.length-1], ins);
@@ -224,11 +224,12 @@ $$.literal = function(str) {
};
};
-$$.token = function(rx) {
+$$.token = function(rx, canon) {
return function(grammar) {
var toks = {};
toks[rx.source] = function(m) {
- return cursor($$.literal(m[0])(grammar).make([m[0]]), 1);
+ var tok = typeof(canon) === 'undefined' ? m[0] : canon;
+ return cursor($$.literal(m[0])(grammar).make([tok]), 1);
};
var c = new SF.SynClass({
open: function() { return box_synclass(c).make([]) },
@@ -60,12 +60,12 @@
var text_node = function(text) { return document.createTextNode(text) };
// End CodeCatalog Snippet
-var space = SG.literal(' ');
+var space = SG.token(/\s*/, ' ');
var top_class = SG.grammar('stmts', {
'stmts': SG.choice(
SG.empty,
- SG.seq(SG.sym('stmt'), SG.literal(';\n'), SG.sym('stmts'))),
+ SG.seq(SG.sym('stmt'), SG.token(/;/, ';\n'), SG.sym('stmts'))),
'stmt': SG.choice(
SG.sym('var_decl'),
SG.sym('funcall')),

0 comments on commit a5973fe

Please sign in to comment.