Permalink
Browse files

Fixed working of normal mode because 'this' is dumb.

  • Loading branch information...
1 parent d6e8468 commit f207e8843382cb5e3f5a9c39d1d496abaea8e430 @luqui committed Jun 21, 2011
Showing with 6 additions and 20 deletions.
  1. +6 −5 StructuralEditor.js
  2. +0 −15 StructuralFramework.js
View
@@ -57,9 +57,10 @@ var NormalMode = object({
},
keydown: function(e) {
var head = typeof(this.zipper.expr) === 'string' ? new SF.SynClass({}) : this.zipper.expr.head;
+ var self = this;
var navigate = function(dir) {
- this.update(head[dir].call(head, this.zipper));
+ self.update(head[dir].call(head, self.zipper));
};
if (37 == e.which) { // left
@@ -103,13 +104,13 @@ var InsertMode = object({
mode_container.text('Insert');
},
keydown: function(e) {
- if (39 == e.which) { // right
- this.update(this.cursor.forward_token());
- }
- else if (8 == e.which) { // backspace
+ if (8 == e.which) { // backspace
this.input_buffer = this.input_buffer.slice(0, this.input_buffer.length-1);
this.render();
}
+ else if (27 == e.which) { // escape
+ mode = new NormalMode(this.cursor.zipper);
+ }
},
keypress: function(e) {
if (!(32 <= e.which && e.which <= 127)) return; // non-printable
View
@@ -256,21 +256,6 @@ $$.Cursor = object({
after: function() {
return this.zipper.expr.args[this.pos];
},
- forward_token: function() {
- var zipper = this.zipper;
- var pos = this.pos;
- while (typeof(this.after()) === 'object') {
- if (zipper.expr.args.length == 0) {
- pos = zipper.position()+1;
- zipper = zipper.up();
- }
- else {
- zipper = zipper.down(0);
- pos = 0;
- }
- }
- return new $$.Cursor(zipper, pos+1);
- },
parse_insert: function(text) {
var expr = this.zipper.expr;
if (expr.args.length == 0) {

0 comments on commit f207e88

Please sign in to comment.