diff editor.js @ 131:8285784f5ff5

Implement previous and next buttons
author Mike Pavone <pavone@retrodev.com>
date Wed, 07 Aug 2013 10:01:28 -0700
parents 2b25d0ce2946
children a503a329acfa
line wrap: on
line diff
--- a/editor.js	Tue Aug 06 00:53:03 2013 -0700
+++ b/editor.js	Wed Aug 07 10:01:28 2013 -0700
@@ -16,6 +16,24 @@
 	}
 };
 
+object.prototype.getNext = function(curNode) {
+	for (var i = 0; i < this.messages.length-1; i++) {
+		if (this.messages[i] == curNode) {
+			return this.messages[i+1];
+		}
+	}
+	return this.up.getNext(this);
+};
+
+object.prototype.getPrev = function(curNode) {
+	for (var i = 1; i < this.messages.length; i++) {
+		if (this.messages[i] == curNode) {
+			return this.messages[i - 1];
+		}
+	}
+	return this.up.getPrev(this);
+};
+
 lambda.prototype.toHTML = function(node, up) {
 	this.up = up
 	var astNode = this;
@@ -43,6 +61,50 @@
 	node.appendChild(el);
 };
 
+lambda.prototype.getNext = function(curNode) {
+	for (var i = 0; i < this.args.length; i++) {
+		if (this.args[i] == curNode) {
+			if ((i + 1) < this.args.length) {
+				return this.args[i+1];
+			} else if(this.expressions.length) {
+				return this.expressions[0];
+			} else {
+				break;
+			}
+		}
+	}
+	for (var i = 0; i < this.expressions.length-1; i++) {
+		if (this.expressions[i] == curNode) {
+			return this.expressions[i+1];
+		}
+	}
+	return this.up.getNext(this);
+};
+
+lambda.prototype.getPrev = function(curNode) {
+	for (var i = 0; i < this.args.length; i++) {
+		if (this.args[i] == curNode) {
+			if (i > 0) {
+				return this.args[i-1];
+			} else {
+				return this.up.getPrev(this);
+			}
+		}
+	}
+	for (var i = 0; i < this.expressions.length; i++) {
+		if (this.expressions[i] == curNode) {
+			if (i > 0) {
+				return this.expressions[i-1];
+			} else if(this.args.length) {
+				return this.args[this.args.length-1];
+			} else {
+				break;
+			}
+		}
+	}
+	return this.up.getPrev(this);
+};
+
 assignment.prototype.toHTML = function(node, up) {
 	this.up = up;
 	var astNode = this;
@@ -62,6 +124,14 @@
 	this.expression.toHTML(base, this);
 };
 
+assignment.prototype.getNext = function(curNode) {
+	return this.up.getNext(this);
+};
+
+assignment.prototype.getPrev = function(curNode) {
+	return this;
+};
+
 op.prototype.toHTML = function(node, up) {
 	this.up = up;
 	var astNode = this;
@@ -85,6 +155,20 @@
 	node.appendChild(base);
 };
 
+op.prototype.getNext = function(curNode) {
+	if (this.left == curNode) {
+		return this.right;
+	}
+	return this.up.getNext(this);
+};
+
+op.prototype.getPrev = function(curNode) {
+	if (this.right == curNode) {
+		return this.left;
+	}
+	return this.up.getPrev(this);
+};
+
 intlit.prototype.toHTML = function(node, up) {
 	this.up = up;
 	var astNode = this;
@@ -136,6 +220,32 @@
 	node.appendChild(this.domNode);
 };
 
+listlit.prototype.getNext = arraylit.prototype.getNext = function(curNode) {
+	for (var i = 0; i < this.val.length; i++) {
+		if (this.val[i] == curNode) {
+			if ((i + 1) < this.val.length) {
+				return this.val[i+1];
+			} else {
+				break;
+			}
+		}
+	}
+	return this.up.getNext(this);
+};
+
+listlit.prototype.getPrev = arraylit.prototype.getPrev = function(curNode) {
+	for (var i = 0; i < this.val.length; i++) {
+		if (this.val[i] == curNode) {
+			if (i > 0) {
+				return this.val[i-1];
+			} else {
+				break;
+			}
+		}
+	}
+	return this.up.getPrev(this);
+};
+
 arraylit.prototype.toHTML = function(node, up) {
 	this.up = up;
 	this.domNode = newEl('span', {
@@ -178,6 +288,33 @@
 	node.appendChild(base);
 };
 
+funcall.prototype.getNext = function(curNode) {
+	if (this.receiver == curNode && this.args.length) {
+		return this.args[0];
+	}
+	for (var i = 0; i < this.args.length-1; i++) {
+		if (this.args[i] == curNode) {
+			return this.args[i+1];
+		}
+	}
+	return this.up.getNext(this);
+};
+
+funcall.prototype.getPrev = function(curNode) {
+	for (var i = 0; i < this.args.length; i++) {
+		if (this.args[i] == curNode) {
+			if (i > 0) {
+				return this.args[i-1];
+			} else if (this.receiver) {
+				return this.receiver;
+			} else {
+				break;
+			}
+		}
+	}
+	return this.up.getPrev(this);
+};
+
 symbol.prototype.toHTML = function(node, up) {
 	this.up = up;
 	var astNode = this;