1
2
3 scenario clicking-on-sandbox-edit-button-moves-it-to-editor [
4 local-scope
5 trace-until 100/app
6 assume-screen 100/width, 10/height
7
8 assume-resources [
9 ]
10 env:&:environment <- new-programming-environment resources, screen, [add 2, 2]
11
12 assume-console [
13 ¦ press F4
14 ]
15 event-loop screen, console, env, resources
16 screen-should-contain [
17 ¦ . run (F4) .
18 ¦ . ╎ .
19 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
20 ¦ . ╎0 edit copy to recipe delete .
21 ¦ . ╎add 2, 2 .
22 ¦ . ╎4 .
23 ¦ . ╎─────────────────────────────────────────────────.
24 ¦ . ╎ .
25 ]
26
27 assume-console [
28 ¦ left-click 3, 55
29 ]
30 run [
31 ¦ event-loop screen, console, env, resources
32 ]
33
34 screen-should-contain [
35 ¦ . run (F4) .
36 ¦ . ╎add 2, 2 .
37 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
38 ¦ . ╎ .
39 ]
40
41 assume-console [
42 ¦ type [0]
43 ]
44 run [
45 ¦ event-loop screen, console, env, resources
46 ]
47 screen-should-contain [
48 ¦ . run (F4) .
49 ¦ . ╎0add 2, 2 .
50 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
51 ¦ . ╎ .
52 ]
53 ]
54
55 scenario clicking-on-sandbox-edit-button-moves-it-to-editor-2 [
56 local-scope
57 trace-until 100/app
58 assume-screen 100/width, 10/height
59
60 assume-resources [
61 ]
62 env:&:environment <- new-programming-environment resources, screen, [add 2, 2]
63
64 assume-console [
65 ¦ press F4
66 ]
67 event-loop screen, console, env, resources
68 screen-should-contain [
69 ¦ . run (F4) .
70 ¦ . ╎ .
71 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
72 ¦ . ╎0 edit copy to recipe delete .
73 ¦ . ╎add 2, 2 .
74 ¦ . ╎4 .
75 ¦ . ╎─────────────────────────────────────────────────.
76 ¦ . ╎ .
77 ]
78
79 assume-console [
80 ¦ left-click 3, 65
81 ]
82 run [
83 ¦ event-loop screen, console, env, resources
84 ]
85
86 screen-should-contain [
87 ¦ . run (F4) .
88 ¦ . ╎add 2, 2 .
89 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
90 ¦ . ╎ .
91 ]
92
93 assume-console [
94 ¦ type [0]
95 ]
96 run [
97 ¦ event-loop screen, console, env, resources
98 ]
99 screen-should-contain [
100 ¦ . run (F4) .
101 ¦ . ╎0add 2, 2 .
102 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
103 ¦ . ╎ .
104 ]
105 ]
106
107 after <global-touch> [
108
109 {
110 ¦ edit?:bool <- should-attempt-edit? click-row, click-column, env
111 ¦ break-unless edit?
112 ¦ edit?, env <- try-edit-sandbox click-row, env
113 ¦ break-unless edit?
114 ¦ screen <- render-sandbox-side screen, env, render
115 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
116 ¦ loop +next-event
117 }
118 ]
119
120
121 def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> result:bool [
122 local-scope
123 load-ingredients
124
125 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env
126 return-unless click-sandbox-area?, 0/false
127
128 first-sandbox:&:editor <- get *env, current-sandbox:offset
129 assert first-sandbox, [!!]
130 sandbox-left-margin:num <- get *first-sandbox, left:offset
131 sandbox-right-margin:num <- get *first-sandbox, right:offset
132 edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin
133 edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right
134 return-unless edit-button-vertical-area?, 0/false
135
136 current-sandbox:&:editor <- get *env, current-sandbox:offset
137 result <- empty-editor? current-sandbox
138 ]
139
140 def try-edit-sandbox click-row:num, env:&:environment -> clicked-on-edit-button?:bool, env:&:environment [
141 local-scope
142 load-ingredients
143
144 sandbox:&:sandbox <- find-sandbox env, click-row
145 return-unless sandbox, 0/false
146 clicked-on-edit-button? <- copy 1/true
147
148 text:text <- get *sandbox, data:offset
149 current-sandbox:&:editor <- get *env, current-sandbox:offset
150 current-sandbox <- insert-text current-sandbox, text
151 env <- delete-sandbox env, sandbox
152
153 *env <- put *env, render-from:offset, -1
154
155 *env <- put *env, sandbox-in-focus?:offset, 1/true
156 ]
157
158 scenario sandbox-with-print-can-be-edited [
159 local-scope
160 trace-until 100/app
161 assume-screen 100/width, 20/height
162
163 assume-resources [
164 ]
165
166 env:&:environment <- new-programming-environment resources, screen, [print screen, 4]
167
168 assume-console [
169 ¦ press F4
170 ]
171 event-loop screen, console, env, resources
172 screen-should-contain [
173 ¦ . run (F4) .
174 ¦ . ╎ .
175 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
176 ¦ . ╎0 edit copy to recipe delete .
177 ¦ . ╎print screen, 4 .
178 ¦ . ╎screen: .
179 ¦ . ╎ .4 . .
180 ¦ . ╎ . . .
181 ¦ . ╎ . . .
182 ¦ . ╎ . . .
183 ¦ . ╎ . . .
184 ¦ . ╎─────────────────────────────────────────────────.
185 ¦ . ╎ .
186 ]
187
188 assume-console [
189 ¦ left-click 3, 65
190 ]
191 run [
192 ¦ event-loop screen, console, env, resources
193 ]
194 screen-should-contain [
195 ¦ . run (F4) .
196 ¦ . ╎print screen, 4 .
197 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
198 ¦ . ╎ .
199 ¦ . ╎ .
200 ]
201 ]
202
203 scenario editing-sandbox-after-scrolling-resets-scroll [
204 local-scope
205 trace-until 100/app
206 assume-screen 100/width, 10/height
207
208 assume-resources [
209 ]
210 env:&:environment <- new-programming-environment resources, screen, []
211 render-all screen, env, render
212
213 assume-console [
214 ¦ press ctrl-n
215 ¦ type [add 2, 2]
216 ¦ press F4
217 ¦ type [add 1, 1]
218 ¦ press F4
219 ¦ press page-down
220 ¦ press page-down
221 ]
222 event-loop screen, console, env, resources
223 screen-should-contain [
224 ¦ . run (F4) .
225 ¦ . ╎─────────────────────────────────────────────────.
226 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy to recipe delete .
227 ¦ . ╎add 2, 2 .
228 ¦ . ╎4 .
229 ¦ . ╎─────────────────────────────────────────────────.
230 ¦ . ╎ .
231 ]
232
233 assume-console [
234 ¦ left-click 2, 55
235 ]
236 run [
237 ¦ event-loop screen, console, env, resources
238 ]
239
240 screen-should-contain [
241 ¦ . run (F4) .
242 ¦ . ╎add 2, 2 .
243 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
244 ¦ . ╎0 edit copy to recipe delete .
245 ¦ . ╎add 1, 1 .
246 ¦ . ╎2 .
247 ¦ . ╎─────────────────────────────────────────────────.
248 ¦ . ╎ .
249 ]
250 ]
251
252 scenario editing-sandbox-updates-sandbox-count [
253 local-scope
254 trace-until 100/app
255 assume-screen 100/width, 10/height
256
257 assume-resources [
258 ]
259 env:&:environment <- new-programming-environment resources, screen, []
260 render-all screen, env, render
261
262 assume-console [
263 ¦ press ctrl-n
264 ¦ type [add 2, 2]
265 ¦ press F4
266 ¦ type [add 1, 1]
267 ¦ press F4
268 ]
269 event-loop screen, console, env, resources
270 screen-should-contain [
271 ¦ . run (F4) .
272 ¦ . ╎ .
273 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
274 ¦ . ╎0 edit copy to recipe delete .
275 ¦ . ╎add 1, 1 .
276 ¦ . ╎2 .
277 ¦ . ╎─────────────────────────────────────────────────.
278 ¦ . ╎1 edit copy to recipe delete .
279 ¦ . ╎add 2, 2 .
280 ¦ . ╎4 .
281 ]
282
283 assume-console [
284 ¦ left-click 3, 60
285 ¦ press F4
286 ]
287 run [
288 ¦ event-loop screen, console, env, resources
289 ]
290
291 screen-should-contain [
292 ¦ . run (F4) .
293 ¦ . ╎ .
294 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
295 ¦ . ╎0 edit copy to recipe delete .
296 ¦ . ╎add 1, 1 .
297 ¦ . ╎2 .
298 ¦ . ╎─────────────────────────────────────────────────.
299 ¦ . ╎1 edit copy to recipe delete .
300 ¦ . ╎add 2, 2 .
301 ¦ . ╎4 .
302 ]
303
304 assume-console [
305 ¦ press page-down
306 ¦ press page-down
307 ¦ press page-down
308 ]
309 run [
310 ¦ event-loop screen, console, env, resources
311 ]
312
313 screen-should-contain [
314 ¦ . run (F4) .
315 ¦ . ╎─────────────────────────────────────────────────.
316 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy to recipe delete .
317 ¦ . ╎add 2, 2 .
318 ¦ . ╎4 .
319 ¦ . ╎─────────────────────────────────────────────────.
320 ¦ . ╎ .
321 ]
322 ]