diff src/editor.tp @ 110:d715fb3c39ab

Implemented clicking on symbols inside inscope box to replace function name in funcall.
author Mike Pavone <pavone@retrodev.com>
date Sat, 13 Apr 2013 23:37:54 -0700
parents a647cdad620b
children b2a3f202d485
line wrap: on
line diff
--- a/src/editor.tp	Sat Apr 13 17:33:14 2013 -0700
+++ b/src/editor.tp	Sat Apr 13 23:37:54 2013 -0700
@@ -5,7 +5,10 @@
 each <- foreign: :iterable fun {}
 addClass <- foreign: :node className {}
 removeClass <- foreign: :node className {}
+hasClass <- foreign: :node className {}
 get <- foreign: :url onSuccess onFail onOther {}
+getEl <- foreign: :from idx {}
+setEl <- foreign: :to idx val {}
 newEl <- foreign: :tagname props {}
 
 //TP Parser
@@ -101,7 +104,51 @@
 	syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym {
 		isLambda: ((symtable find: sym) def)
 	}
-	popInscope: syms onClick: {}
+	popInscope: syms onClick: :key {
+		astnode name!: key
+		parts <- key split: ":"
+		parent <- domnode parentNode
+		nodes <- []
+		each: (parent children) :idx val{
+			nodes push: val
+		}
+		partIdx <- 0
+		nodeIdx <- 0
+		lastWasNamePart <- true
+		while: { partIdx < (parts length) || nodeIdx < (nodes length) } do: {
+			if: nodeIdx < (nodes length) {
+				node <-getEl: nodes nodeIdx
+				nodeIdx <- nodeIdx + 1
+				if: (hasClass: node "funpart") {
+					if: partIdx < (parts length) {
+						postfix <- if: partIdx = 0 && nodeIdx = 2 && (parts length) = 1 && (nodes length) = 2 { "" } else: { ":" }
+						t <- (getEl: parts partIdx)
+						node textContent!: (getEl: parts partIdx) . postfix
+						partIdx <- partIdx + 1
+					} else: {
+						parent removeChild: node
+					}
+					lastWasNamePart <- true
+				} else: {
+					if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 {
+						parent insertBefore: (newEl: "span" #{
+							className <- "funpart selected"
+							textContent <- (getEl: parts partIdx) . ":"
+						}) node
+						partIdx <- partIdx + 1
+					}
+					lastWasNamePart <- false
+				}
+			} else: {
+				console log: "part: " . (getEl: parts partIdx)
+				parent appendChild: (newEl: "span" #{
+					className <- "funpart selected"
+					textContent <- (getEl: parts partIdx) . ":"
+				})
+				partIdx <- partIdx + 1
+			}
+		}
+	}
 	event stopPropagation: (foreign: undefined)
 }