diff src/editor.tp @ 113:c0bfff39abe3

Basic in and out navigation support added to funcall expressions. Added toHTML methods to listlit and arraylit.
author Mike Pavone <pavone@retrodev.com>
date Sun, 14 Apr 2013 23:09:46 -0700
parents b2a3f202d485
children 9cf3e0b18ecc
line wrap: on
line diff
--- a/src/editor.tp	Sun Apr 14 18:16:03 2013 -0700
+++ b/src/editor.tp	Sun Apr 14 23:09:46 2013 -0700
@@ -40,6 +40,10 @@
 }
 
 //editor code
+selection <- #{
+	valid? <- false
+}
+
 editFile <- :path {
 	get: path :request {
 		addClass: (q: "body") "editorMode"
@@ -74,7 +78,7 @@
 	each: (qall: ".selectParent") :idx el {
 		removeClass: el "selectParent"
 	}
-	addClass: (node parentNode) "selectParent"
+	addClass: node "selectParent"
 }
 
 popInscope:onClick <- :syms :handler {
@@ -99,17 +103,39 @@
 
 funClick <- :domnode astnode event {
 	selectParent: domnode
-	selectQuery: ".selectParent > .funpart" in: (domnode parentNode)
+	selectQuery: ".selectParent > .funpart" in: domnode
 	symtable <- astnode symbols
 	syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym {
 		isLambda: ((symtable find: sym) def)
 	}
+	self selection!: #{
+		valid? <- true
+		in <- {
+			fakeEvent <- #{
+				stopPropagation <- :Blah {
+				}
+			}
+			if: (astnode receiver) != (foreign: null) {
+				((astnode receiver) domNode) onclick: fakeEvent
+			} else: {
+				if: ((astnode args) length) > 0 {
+					(((astnode args) getEl: 0) domNode) onclick: fakeEvent
+				}
+			}
+		}
+		out <- {
+			fakeEvent <- #{
+				stopPropagation <- :Blah {
+				}
+			}
+			((astnode up) domNode) onclick: fakeEvent
+		}
+	}
 	popInscope: syms onClick: :key {
 		astnode name!: key
 		parts <- key split: ":"
-		parent <- domnode parentNode
 		nodes <- []
-		each: (parent children) :idx val{
+		each: (domnode children) :idx val{
 			nodes push: val
 		}
 		partIdx <- 0
@@ -126,12 +152,12 @@
 						node textContent!: (getEl: parts partIdx) . postfix
 						partIdx <- partIdx + 1
 					} else: {
-						parent removeChild: node
+						domnode removeChild: node
 					}
 					lastWasNamePart <- true
 				} else: {
 					if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 {
-						parent insertBefore: (newEl: "span" #{
+						domnode insertBefore: (newEl: "span" #{
 							className <- "funpart selected"
 							textContent <- (getEl: parts partIdx) . ":"
 						}) node
@@ -141,7 +167,7 @@
 				}
 			} else: {
 				console log: "part: " . (getEl: parts partIdx)
-				parent appendChild: (newEl: "span" #{
+				domnode appendChild: (newEl: "span" #{
 					className <- "funpart selected"
 					textContent <- (getEl: parts partIdx) . ":"
 				})
@@ -204,10 +230,24 @@
 		visible <- "showlit"
 	}
 	
+	(q: "#in") onclick!: :event {
+		console log: "inwards"
+		if: (selection valid?) {
+			selection in
+		}
+	}
+	
+	(q: "#out") onclick!: :event {
+		console log: "outwards"
+		if: (selection valid?) {
+			selection out
+		}
+	}
+	
 	path <- (window location) pathname
 	if: (path indexOf: "/edit/") = 0 {
 		editFile: (path substr: 5)
-	} else: {}
+	}
 }
 
 }