adding forward and backward movement

This commit is contained in:
Danny Yoo 2011-09-12 11:43:06 -04:00
parent 4bd8d877af
commit 21c73b77c3
3 changed files with 121 additions and 0 deletions

View File

@ -48,6 +48,11 @@
view-down?
view-down
view-forward?
view-forward
view-backward?
view-backward
view-text
update-view-text

View File

@ -324,6 +324,60 @@
view.focus = view.focus.children(':first');
});
};
MockView.prototype.forward = function() {
return this.act(
function(cursor) {
return cursor.succ();
},
function(eventHandlers) {
return eventHandlers;
},
function(view) {
if (view.focus.children().length > 0) {
view.focus = view.focus.children(':first');
} else if (view.focus.next().length > 0) {
view.focus = view.focus.next();
} else {
while (true) {
view.focus = view.focus.parent();
if (view.focus.next().length > 0) {
view.focus = view.focus.next();
return;
}
}
}
});
};
MockView.prototype.backward = function() {
return this.act(
function(cursor) {
return cursor.pred();
},
function(eventHandlers) {
return eventHandlers;
},
function(view) {
if (view.focus.prev().length > 0) {
view.focus = view.focus.prev();
while (view.focus.children().length > 0) {
view.focus = view.focus.children(':last');
}
} else {
view.focus = view.focus.parent();
}
});
};
var mockViewIdGensym = 0;
@ -489,6 +543,13 @@
return this.cursor.canRight();
};
MockView.prototype.isForwardMovementOk = function() {
return this.cursor.canSucc();
};
MockView.prototype.isBackwardMovementOk = function() {
return this.cursor.canPred();
};
//////////////////////////////////////////////////////////////////////
@ -1620,6 +1681,21 @@
return view.down();
});
EXPORTS['view-forward'] = makePrimitiveProcedure(
'view-forward',
1,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-forward', 0);
return view.forward();
});
EXPORTS['view-backward'] = makePrimitiveProcedure(
'view-backward',
1,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-backward', 0);
return view.backward();
});
EXPORTS['view-left?'] = makePrimitiveProcedure(
@ -1655,6 +1731,24 @@
});
EXPORTS['view-forward?'] = makePrimitiveProcedure(
'view-down?',
1,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-forward?', 0);
return view.isForwardMovementOk();
});
EXPORTS['view-backward?'] = makePrimitiveProcedure(
'view-backward?',
1,
function(MACHINE) {
var view = checkMockView(MACHINE, 'view-backward?', 0);
return view.isBackwardMovementOk();
});

View File

@ -9,6 +9,12 @@
view-focus? view-focus
view-left view-right view-up view-down
view-left? view-right? view-up? view-down?
view-forward?
view-forward
view-backward?
view-backward
view-text update-view-text
view-attr update-view-attr
view-css update-view-css
@ -25,6 +31,9 @@
view-insert-right
view-insert-left
view-remove
open-output-element
@ -111,6 +120,19 @@
(define (view-down? v)
(error 'view-down? "Please run in JavaScript context"))
(define (view-forward? v)
(error 'view-forward? "Please run in JavaScript context"))
(define (view-backward? v)
(error 'view-backward? "Please run in JavaScript context"))
(define (view-forward v)
(error 'view-forward "Please run in JavaScript context"))
(define (view-backward v)
(error 'view-backward "Please run in JavaScript context"))