comparison 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
comparison
equal deleted inserted replaced
112:c0cf9444cf88 113:c0bfff39abe3
38 } 38 }
39 output 39 output
40 } 40 }
41 41
42 //editor code 42 //editor code
43 selection <- #{
44 valid? <- false
45 }
46
43 editFile <- :path { 47 editFile <- :path {
44 get: path :request { 48 get: path :request {
45 addClass: (q: "body") "editorMode" 49 addClass: (q: "body") "editorMode"
46 src <- request responseText 50 src <- request responseText
47 ast <- parser parse: src 51 ast <- parser parse: src
72 76
73 selectParent <- :node { 77 selectParent <- :node {
74 each: (qall: ".selectParent") :idx el { 78 each: (qall: ".selectParent") :idx el {
75 removeClass: el "selectParent" 79 removeClass: el "selectParent"
76 } 80 }
77 addClass: (node parentNode) "selectParent" 81 addClass: node "selectParent"
78 } 82 }
79 83
80 popInscope:onClick <- :syms :handler { 84 popInscope:onClick <- :syms :handler {
81 inscope <- q: "#inscope" 85 inscope <- q: "#inscope"
82 inscope innerHTML!: "" 86 inscope innerHTML!: ""
97 event stopPropagation: (foreign: undefined) 101 event stopPropagation: (foreign: undefined)
98 } 102 }
99 103
100 funClick <- :domnode astnode event { 104 funClick <- :domnode astnode event {
101 selectParent: domnode 105 selectParent: domnode
102 selectQuery: ".selectParent > .funpart" in: (domnode parentNode) 106 selectQuery: ".selectParent > .funpart" in: domnode
103 symtable <- astnode symbols 107 symtable <- astnode symbols
104 syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym { 108 syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym {
105 isLambda: ((symtable find: sym) def) 109 isLambda: ((symtable find: sym) def)
106 } 110 }
111 self selection!: #{
112 valid? <- true
113 in <- {
114 fakeEvent <- #{
115 stopPropagation <- :Blah {
116 }
117 }
118 if: (astnode receiver) != (foreign: null) {
119 ((astnode receiver) domNode) onclick: fakeEvent
120 } else: {
121 if: ((astnode args) length) > 0 {
122 (((astnode args) getEl: 0) domNode) onclick: fakeEvent
123 }
124 }
125 }
126 out <- {
127 fakeEvent <- #{
128 stopPropagation <- :Blah {
129 }
130 }
131 ((astnode up) domNode) onclick: fakeEvent
132 }
133 }
107 popInscope: syms onClick: :key { 134 popInscope: syms onClick: :key {
108 astnode name!: key 135 astnode name!: key
109 parts <- key split: ":" 136 parts <- key split: ":"
110 parent <- domnode parentNode
111 nodes <- [] 137 nodes <- []
112 each: (parent children) :idx val{ 138 each: (domnode children) :idx val{
113 nodes push: val 139 nodes push: val
114 } 140 }
115 partIdx <- 0 141 partIdx <- 0
116 nodeIdx <- 0 142 nodeIdx <- 0
117 lastWasNamePart <- true 143 lastWasNamePart <- true
124 postfix <- if: partIdx = 0 && nodeIdx = 2 && (parts length) = 1 && (nodes length) = 2 { "" } else: { ":" } 150 postfix <- if: partIdx = 0 && nodeIdx = 2 && (parts length) = 1 && (nodes length) = 2 { "" } else: { ":" }
125 t <- (getEl: parts partIdx) 151 t <- (getEl: parts partIdx)
126 node textContent!: (getEl: parts partIdx) . postfix 152 node textContent!: (getEl: parts partIdx) . postfix
127 partIdx <- partIdx + 1 153 partIdx <- partIdx + 1
128 } else: { 154 } else: {
129 parent removeChild: node 155 domnode removeChild: node
130 } 156 }
131 lastWasNamePart <- true 157 lastWasNamePart <- true
132 } else: { 158 } else: {
133 if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 { 159 if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 {
134 parent insertBefore: (newEl: "span" #{ 160 domnode insertBefore: (newEl: "span" #{
135 className <- "funpart selected" 161 className <- "funpart selected"
136 textContent <- (getEl: parts partIdx) . ":" 162 textContent <- (getEl: parts partIdx) . ":"
137 }) node 163 }) node
138 partIdx <- partIdx + 1 164 partIdx <- partIdx + 1
139 } 165 }
140 lastWasNamePart <- false 166 lastWasNamePart <- false
141 } 167 }
142 } else: { 168 } else: {
143 console log: "part: " . (getEl: parts partIdx) 169 console log: "part: " . (getEl: parts partIdx)
144 parent appendChild: (newEl: "span" #{ 170 domnode appendChild: (newEl: "span" #{
145 className <- "funpart selected" 171 className <- "funpart selected"
146 textContent <- (getEl: parts partIdx) . ":" 172 textContent <- (getEl: parts partIdx) . ":"
147 }) 173 })
148 partIdx <- partIdx + 1 174 partIdx <- partIdx + 1
149 } 175 }
202 addClass: el "showlit" 228 addClass: el "showlit"
203 } 229 }
204 visible <- "showlit" 230 visible <- "showlit"
205 } 231 }
206 232
233 (q: "#in") onclick!: :event {
234 console log: "inwards"
235 if: (selection valid?) {
236 selection in
237 }
238 }
239
240 (q: "#out") onclick!: :event {
241 console log: "outwards"
242 if: (selection valid?) {
243 selection out
244 }
245 }
246
207 path <- (window location) pathname 247 path <- (window location) pathname
208 if: (path indexOf: "/edit/") = 0 { 248 if: (path indexOf: "/edit/") = 0 {
209 editFile: (path substr: 5) 249 editFile: (path substr: 5)
210 } else: {} 250 }
211 } 251 }
212 252
213 } 253 }