From ef6116cbaf9368e490bfdec1c6404396ac161026 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 13 May 2017 12:50:07 -0700 Subject: 3855 --- html/edit/006-sandbox-copy.mu.html | 302 +++++++++++++++++++------------------ 1 file changed, 152 insertions(+), 150 deletions(-) (limited to 'html/edit/006-sandbox-copy.mu.html') diff --git a/html/edit/006-sandbox-copy.mu.html b/html/edit/006-sandbox-copy.mu.html index d7d3192a..82d58cb3 100644 --- a/html/edit/006-sandbox-copy.mu.html +++ b/html/edit/006-sandbox-copy.mu.html @@ -183,160 +183,162 @@ if ('onhashchange' in window) { 121 ] 122 ] 123 -124 after <global-touch> [ +124 after <global-touch> [ 125 # support 'copy' button 126 { -127 ¦ copy?:bool <- should-attempt-copy? click-row, click-column, env +127 ¦ copy?:bool <- should-attempt-copy? click-row, click-column, env 128 ¦ break-unless copy? -129 ¦ copy?, env <- try-copy-sandbox click-row, env +129 ¦ copy?, env <- try-copy-sandbox click-row, env 130 ¦ break-unless copy? -131 ¦ screen <- render-sandbox-side screen, env, render -132 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -133 ¦ loop +next-event -134 } -135 ] -136 -137 # some preconditions for attempting to copy a sandbox -138 def should-attempt-copy? click-row:num, click-column:num, env:&:environment -> result:bool [ -139 local-scope -140 load-ingredients -141 # are we below the sandbox editor? -142 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env -143 return-unless click-sandbox-area?, 0/false -144 # narrower, is the click in the columns spanning the 'copy' button? -145 first-sandbox:&:editor <- get *env, current-sandbox:offset -146 assert first-sandbox, [!!] -147 sandbox-left-margin:num <- get *first-sandbox, left:offset -148 sandbox-right-margin:num <- get *first-sandbox, right:offset -149 _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin -150 copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right -151 return-unless copy-button-vertical-area?, 0/false -152 # finally, is sandbox editor empty? -153 current-sandbox:&:editor <- get *env, current-sandbox:offset -154 result <- empty-editor? current-sandbox -155 ] -156 -157 def try-copy-sandbox click-row:num, env:&:environment -> clicked-on-copy-button?:bool, env:&:environment [ -158 local-scope -159 load-ingredients -160 # identify the sandbox to copy, if the click was actually on the 'copy' button -161 sandbox:&:sandbox <- find-sandbox env, click-row -162 return-unless sandbox, 0/false -163 clicked-on-copy-button? <- copy 1/true -164 text:text <- get *sandbox, data:offset -165 current-sandbox:&:editor <- get *env, current-sandbox:offset -166 current-sandbox <- insert-text current-sandbox, text -167 # reset scroll -168 *env <- put *env, render-from:offset, -1 -169 # position cursor in sandbox editor -170 *env <- put *env, sandbox-in-focus?:offset, 1/true -171 ] -172 -173 def find-sandbox env:&:environment, click-row:num -> result:&:sandbox [ -174 local-scope -175 load-ingredients -176 curr-sandbox:&:sandbox <- get *env, sandbox:offset -177 { -178 ¦ break-unless curr-sandbox -179 ¦ start:num <- get *curr-sandbox, starting-row-on-screen:offset -180 ¦ found?:bool <- equal click-row, start -181 ¦ return-if found?, curr-sandbox -182 ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset -183 ¦ loop -184 } -185 return 0/not-found -186 ] -187 -188 def click-on-sandbox-area? click-row:num, click-column:num, env:&:environment -> result:bool [ -189 local-scope -190 load-ingredients -191 current-sandbox:&:editor <- get *env, current-sandbox:offset -192 sandbox-left-margin:num <- get *current-sandbox, left:offset -193 on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin -194 return-unless on-sandbox-side?, 0/false -195 first-sandbox:&:sandbox <- get *env, sandbox:offset -196 return-unless first-sandbox, 0/false -197 first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset -198 result <- greater-or-equal click-row, first-sandbox-begins -199 ] -200 -201 def empty-editor? editor:&:editor -> result:bool [ -202 local-scope -203 load-ingredients -204 head:&:duplex-list:char <- get *editor, data:offset -205 first:&:duplex-list:char <- next head -206 result <- not first -207 ] -208 -209 def within-range? x:num, low:num, high:num -> result:bool [ -210 local-scope -211 load-ingredients -212 not-too-far-left?:bool <- greater-or-equal x, low -213 not-too-far-right?:bool <- lesser-or-equal x, high -214 result <- and not-too-far-left? not-too-far-right? -215 ] -216 -217 scenario copy-fails-if-sandbox-editor-not-empty [ -218 local-scope -219 trace-until 100/app # trace too long -220 assume-screen 100/width, 10/height -221 # empty recipes -222 assume-resources [ -223 ] -224 env:&:environment <- new-programming-environment resources, screen, [add 1, 1] # contents of sandbox editor -225 # run it -226 assume-console [ -227 ¦ press F4 -228 ] -229 event-loop screen, console, env, resources -230 screen-should-contain [ -231 ¦ . run (F4) . -232 ¦ . ╎ . -233 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -234 ¦ . ╎0 edit copy delete . -235 ¦ . ╎add 1, 1 . -236 ¦ . ╎2 . -237 ¦ . ╎─────────────────────────────────────────────────. -238 ¦ . ╎ . -239 ] -240 # type something into the sandbox editor, then click on the 'copy' button -241 assume-console [ -242 ¦ left-click 2, 70 # put cursor in sandbox editor -243 ¦ type [0] # type something -244 ¦ left-click 3, 70 # click 'copy' button -245 ] -246 run [ -247 ¦ event-loop screen, console, env, resources -248 ] -249 # copy doesn't happen -250 screen-should-contain [ -251 ¦ . run (F4) . -252 ¦ . ╎0 . -253 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -254 ¦ . ╎0 edit copy delete . -255 ¦ . ╎add 1, 1 . -256 ¦ . ╎2 . -257 ¦ . ╎─────────────────────────────────────────────────. -258 ¦ . ╎ . -259 ] -260 # cursor should be in the right place -261 assume-console [ -262 ¦ type [1] -263 ] -264 run [ -265 ¦ event-loop screen, console, env, resources -266 ] -267 screen-should-contain [ -268 ¦ . run (F4) . -269 ¦ . ╎01 . -270 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -271 ¦ . ╎0 edit copy delete . -272 ¦ . ╎add 1, 1 . -273 ¦ . ╎2 . -274 ¦ . ╎─────────────────────────────────────────────────. -275 ¦ . ╎ . -276 ] -277 ] +131 ¦ hide-screen screen +132 ¦ screen <- render-sandbox-side screen, env, render +133 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +134 ¦ show-screen screen +135 ¦ loop +next-event +136 } +137 ] +138 +139 # some preconditions for attempting to copy a sandbox +140 def should-attempt-copy? click-row:num, click-column:num, env:&:environment -> result:bool [ +141 local-scope +142 load-ingredients +143 # are we below the sandbox editor? +144 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env +145 return-unless click-sandbox-area?, 0/false +146 # narrower, is the click in the columns spanning the 'copy' button? +147 first-sandbox:&:editor <- get *env, current-sandbox:offset +148 assert first-sandbox, [!!] +149 sandbox-left-margin:num <- get *first-sandbox, left:offset +150 sandbox-right-margin:num <- get *first-sandbox, right:offset +151 _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin +152 copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right +153 return-unless copy-button-vertical-area?, 0/false +154 # finally, is sandbox editor empty? +155 current-sandbox:&:editor <- get *env, current-sandbox:offset +156 result <- empty-editor? current-sandbox +157 ] +158 +159 def try-copy-sandbox click-row:num, env:&:environment -> clicked-on-copy-button?:bool, env:&:environment [ +160 local-scope +161 load-ingredients +162 # identify the sandbox to copy, if the click was actually on the 'copy' button +163 sandbox:&:sandbox <- find-sandbox env, click-row +164 return-unless sandbox, 0/false +165 clicked-on-copy-button? <- copy 1/true +166 text:text <- get *sandbox, data:offset +167 current-sandbox:&:editor <- get *env, current-sandbox:offset +168 current-sandbox <- insert-text current-sandbox, text +169 # reset scroll +170 *env <- put *env, render-from:offset, -1 +171 # position cursor in sandbox editor +172 *env <- put *env, sandbox-in-focus?:offset, 1/true +173 ] +174 +175 def find-sandbox env:&:environment, click-row:num -> result:&:sandbox [ +176 local-scope +177 load-ingredients +178 curr-sandbox:&:sandbox <- get *env, sandbox:offset +179 { +180 ¦ break-unless curr-sandbox +181 ¦ start:num <- get *curr-sandbox, starting-row-on-screen:offset +182 ¦ found?:bool <- equal click-row, start +183 ¦ return-if found?, curr-sandbox +184 ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset +185 ¦ loop +186 } +187 return 0/not-found +188 ] +189 +190 def click-on-sandbox-area? click-row:num, click-column:num, env:&:environment -> result:bool [ +191 local-scope +192 load-ingredients +193 current-sandbox:&:editor <- get *env, current-sandbox:offset +194 sandbox-left-margin:num <- get *current-sandbox, left:offset +195 on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin +196 return-unless on-sandbox-side?, 0/false +197 first-sandbox:&:sandbox <- get *env, sandbox:offset +198 return-unless first-sandbox, 0/false +199 first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset +200 result <- greater-or-equal click-row, first-sandbox-begins +201 ] +202 +203 def empty-editor? editor:&:editor -> result:bool [ +204 local-scope +205 load-ingredients +206 head:&:duplex-list:char <- get *editor, data:offset +207 first:&:duplex-list:char <- next head +208 result <- not first +209 ] +210 +211 def within-range? x:num, low:num, high:num -> result:bool [ +212 local-scope +213 load-ingredients +214 not-too-far-left?:bool <- greater-or-equal x, low +215 not-too-far-right?:bool <- lesser-or-equal x, high +216 result <- and not-too-far-left? not-too-far-right? +217 ] +218 +219 scenario copy-fails-if-sandbox-editor-not-empty [ +220 local-scope +221 trace-until 100/app # trace too long +222 assume-screen 100/width, 10/height +223 # empty recipes +224 assume-resources [ +225 ] +226 env:&:environment <- new-programming-environment resources, screen, [add 1, 1] # contents of sandbox editor +227 # run it +228 assume-console [ +229 ¦ press F4 +230 ] +231 event-loop screen, console, env, resources +232 screen-should-contain [ +233 ¦ . run (F4) . +234 ¦ . ╎ . +235 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +236 ¦ . ╎0 edit copy delete . +237 ¦ . ╎add 1, 1 . +238 ¦ . ╎2 . +239 ¦ . ╎─────────────────────────────────────────────────. +240 ¦ . ╎ . +241 ] +242 # type something into the sandbox editor, then click on the 'copy' button +243 assume-console [ +244 ¦ left-click 2, 70 # put cursor in sandbox editor +245 ¦ type [0] # type something +246 ¦ left-click 3, 70 # click 'copy' button +247 ] +248 run [ +249 ¦ event-loop screen, console, env, resources +250 ] +251 # copy doesn't happen +252 screen-should-contain [ +253 ¦ . run (F4) . +254 ¦ . ╎0 . +255 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +256 ¦ . ╎0 edit copy delete . +257 ¦ . ╎add 1, 1 . +258 ¦ . ╎2 . +259 ¦ . ╎─────────────────────────────────────────────────. +260 ¦ . ╎ . +261 ] +262 # cursor should be in the right place +263 assume-console [ +264 ¦ type [1] +265 ] +266 run [ +267 ¦ event-loop screen, console, env, resources +268 ] +269 screen-should-contain [ +270 ¦ . run (F4) . +271 ¦ . ╎01 . +272 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +273 ¦ . ╎0 edit copy delete . +274 ¦ . ╎add 1, 1 . +275 ¦ . ╎2 . +276 ¦ . ╎─────────────────────────────────────────────────. +277 ¦ . ╎ . +278 ] +279 ] -- cgit 1.4.1-2-gfad0