Permalink
Browse files

Vim-like editing commands.

  • Loading branch information...
1 parent f61f6ef commit ae095c5538983ba4d8a8249b80d9c78e2cd2ff9e @luqui committed Jun 7, 2011
Showing with 21 additions and 12 deletions.
  1. +12 −11 demo/structural.html
  2. +9 −1 structural.js
View
@@ -33,15 +33,7 @@
})
};
-var zipper =
-/*
- new Zipper([],
- Exp_E.make(
- Exp_eplus.make(
- Exp_eatom.make(),
- Exp_eatom.make())));
-*/
- new Zipper([], Exp_unassembled(parser).make());
+var zipper = new Zipper([], Exp_unassembled(parser).make());
update(zipper);
@@ -69,14 +61,23 @@
update(zipper = zipper.down(0));
}
else {
- //console.log(e.which, e.charCode);
+ console.log(e.which, e.charCode);
}
});
$(document.body).keypress(function(e) {
- if (e.charCode != 0 && typeof(zipper.expr) !== 'string' && zipper.expr.head.keypress) {
+ if (typeof(zipper.expr) !== 'string' && zipper.expr.head.keypress) {
update(zipper = zipper.expr.head.keypress(String.fromCharCode(e.charCode), zipper));
}
+ else {
+ var cmd = String.fromCharCode(e.charCode);
+ if (cmd == 'a') {
+ update(zipper = new Zipper(zipper.contexts, Exp_unassembled(parser).make(zipper.expr)));
+ }
+ if (cmd == 'c') {
+ update(zipper = new Zipper(zipper.contexts, Exp_unassembled(parser).make()));
+ }
+ }
});
});
View
@@ -277,7 +277,15 @@ var Exp_unassembled = function(parser) {
args = args.slice(0, args.length-1);
}
}
- return new Zipper(zipper.contexts, new Expr(zipper.expr.head, args));
+
+ // if we have a single thing, the parse was a success
+ // (TODO not necessarily, typecheck I think)
+ if (args.length == 1) {
+ return new Zipper(zipper.contexts, args[0]);
+ }
+ else {
+ return new Zipper(zipper.contexts, new Expr(zipper.expr.head, args));
+ }
}
})
};

0 comments on commit ae095c5

Please sign in to comment.