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/001-editor.mu.html | 912 ++++++++++++------------- html/edit/002-typing.mu.html | 90 +-- html/edit/003-shortcuts.mu.html | 176 ++--- html/edit/004-programming-environment.mu.html | 942 +++++++++++++------------- html/edit/005-sandbox.mu.html | 726 ++++++++++---------- html/edit/006-sandbox-copy.mu.html | 302 +++++---- html/edit/007-sandbox-delete.mu.html | 534 +++++++-------- html/edit/008-sandbox-edit.mu.html | 416 ++++++------ html/edit/009-sandbox-test.mu.html | 152 +++-- html/edit/010-sandbox-trace.mu.html | 102 +-- html/edit/011-errors.mu.html | 10 +- html/edit/012-editor-undo.mu.html | 58 +- 12 files changed, 2231 insertions(+), 2189 deletions(-) (limited to 'html/edit') diff --git a/html/edit/001-editor.mu.html b/html/edit/001-editor.mu.html index 14307ec2..b17df3bd 100644 --- a/html/edit/001-editor.mu.html +++ b/html/edit/001-editor.mu.html @@ -69,472 +69,474 @@ if ('onhashchange' in window) { 6 local-scope 7 load-ingredients 8 open-console - 9 e:&:editor <- new-editor text, 0/left, 5/right - 10 render 0/screen, e - 11 wait-for-event 0/console - 12 close-console - 13 ] - 14 - 15 scenario editor-renders-text-to-screen [ - 16 local-scope - 17 assume-screen 10/width, 5/height - 18 e:&:editor <- new-editor [abc], 0/left, 10/right - 19 run [ - 20 ¦ render screen, e - 21 ] - 22 screen-should-contain [ - 23 ¦ # top line of screen reserved for menu - 24 ¦ . . - 25 ¦ .abc . + 9 hide-screen 0/screen + 10 e:&:editor <- new-editor text, 0/left, 5/right + 11 render 0/screen, e + 12 show-screen 0/screen + 13 wait-for-event 0/console + 14 close-console + 15 ] + 16 + 17 scenario editor-renders-text-to-screen [ + 18 local-scope + 19 assume-screen 10/width, 5/height + 20 e:&:editor <- new-editor [abc], 0/left, 10/right + 21 run [ + 22 ¦ render screen, e + 23 ] + 24 screen-should-contain [ + 25 ¦ # top line of screen reserved for menu 26 ¦ . . - 27 ] - 28 ] - 29 - 30 container editor [ - 31 # editable text: doubly linked list of characters (head contains a special sentinel) - 32 data:&:duplex-list:char - 33 top-of-screen:&:duplex-list:char - 34 bottom-of-screen:&:duplex-list:char - 35 # location before cursor inside data - 36 before-cursor:&:duplex-list:char - 37 - 38 # raw bounds of display area on screen - 39 # always displays from row 1 (leaving row 0 for a menu) and at most until bottom of screen - 40 left:num - 41 right:num - 42 bottom:num - 43 # raw screen coordinates of cursor - 44 cursor-row:num - 45 cursor-column:num - 46 ] - 47 - 48 # creates a new editor widget - 49 # right is exclusive - 50 def new-editor s:text, left:num, right:num -> result:&:editor [ - 51 local-scope - 52 load-ingredients - 53 # no clipping of bounds - 54 right <- subtract right, 1 - 55 result <- new editor:type - 56 # initialize screen-related fields - 57 *result <- put *result, left:offset, left - 58 *result <- put *result, right:offset, right - 59 # initialize cursor coordinates - 60 *result <- put *result, cursor-row:offset, 1/top - 61 *result <- put *result, cursor-column:offset, left - 62 # initialize empty contents - 63 init:&:duplex-list:char <- push 167/§, 0/tail - 64 *result <- put *result, data:offset, init - 65 *result <- put *result, top-of-screen:offset, init - 66 *result <- put *result, before-cursor:offset, init - 67 result <- insert-text result, s - 68 <editor-initialization> - 69 ] - 70 - 71 def insert-text editor:&:editor, text:text -> editor:&:editor [ - 72 local-scope - 73 load-ingredients - 74 # early exit if text is empty - 75 return-unless text - 76 len:num <- length *text - 77 return-unless len - 78 idx:num <- copy 0 - 79 # now we can start appending the rest, character by character - 80 curr:&:duplex-list:char <- get *editor, data:offset - 81 { - 82 ¦ done?:bool <- greater-or-equal idx, len - 83 ¦ break-if done? - 84 ¦ c:char <- index *text, idx - 85 ¦ insert c, curr - 86 ¦ # next iter - 87 ¦ curr <- next curr - 88 ¦ idx <- add idx, 1 - 89 ¦ loop - 90 } - 91 ] - 92 - 93 scenario editor-initializes-without-data [ - 94 local-scope - 95 assume-screen 5/width, 3/height - 96 run [ - 97 ¦ e:&:editor <- new-editor 0/data, 2/left, 5/right - 98 ¦ 2:editor/raw <- copy *e - 99 ] -100 memory-should-contain [ -101 ¦ # 2 (data) <- just the § sentinel -102 ¦ # 3 (top of screen) <- the § sentinel -103 ¦ 4 <- 0 # bottom-of-screen; null since text fits on screen -104 ¦ # 5 (before cursor) <- the § sentinel -105 ¦ 6 <- 2 # left -106 ¦ 7 <- 4 # right (inclusive) -107 ¦ 8 <- 0 # bottom (not set until render) -108 ¦ 9 <- 1 # cursor row -109 ¦ 10 <- 2 # cursor column -110 ] -111 screen-should-contain [ -112 ¦ . . -113 ¦ . . + 27 ¦ .abc . + 28 ¦ . . + 29 ] + 30 ] + 31 + 32 container editor [ + 33 # editable text: doubly linked list of characters (head contains a special sentinel) + 34 data:&:duplex-list:char + 35 top-of-screen:&:duplex-list:char + 36 bottom-of-screen:&:duplex-list:char + 37 # location before cursor inside data + 38 before-cursor:&:duplex-list:char + 39 + 40 # raw bounds of display area on screen + 41 # always displays from row 1 (leaving row 0 for a menu) and at most until bottom of screen + 42 left:num + 43 right:num + 44 bottom:num + 45 # raw screen coordinates of cursor + 46 cursor-row:num + 47 cursor-column:num + 48 ] + 49 + 50 # creates a new editor widget + 51 # right is exclusive + 52 def new-editor s:text, left:num, right:num -> result:&:editor [ + 53 local-scope + 54 load-ingredients + 55 # no clipping of bounds + 56 right <- subtract right, 1 + 57 result <- new editor:type + 58 # initialize screen-related fields + 59 *result <- put *result, left:offset, left + 60 *result <- put *result, right:offset, right + 61 # initialize cursor coordinates + 62 *result <- put *result, cursor-row:offset, 1/top + 63 *result <- put *result, cursor-column:offset, left + 64 # initialize empty contents + 65 init:&:duplex-list:char <- push 167/§, 0/tail + 66 *result <- put *result, data:offset, init + 67 *result <- put *result, top-of-screen:offset, init + 68 *result <- put *result, before-cursor:offset, init + 69 result <- insert-text result, s + 70 <editor-initialization> + 71 ] + 72 + 73 def insert-text editor:&:editor, text:text -> editor:&:editor [ + 74 local-scope + 75 load-ingredients + 76 # early exit if text is empty + 77 return-unless text + 78 len:num <- length *text + 79 return-unless len + 80 idx:num <- copy 0 + 81 # now we can start appending the rest, character by character + 82 curr:&:duplex-list:char <- get *editor, data:offset + 83 { + 84 ¦ done?:bool <- greater-or-equal idx, len + 85 ¦ break-if done? + 86 ¦ c:char <- index *text, idx + 87 ¦ insert c, curr + 88 ¦ # next iter + 89 ¦ curr <- next curr + 90 ¦ idx <- add idx, 1 + 91 ¦ loop + 92 } + 93 ] + 94 + 95 scenario editor-initializes-without-data [ + 96 local-scope + 97 assume-screen 5/width, 3/height + 98 run [ + 99 ¦ e:&:editor <- new-editor 0/data, 2/left, 5/right +100 ¦ 2:editor/raw <- copy *e +101 ] +102 memory-should-contain [ +103 ¦ # 2 (data) <- just the § sentinel +104 ¦ # 3 (top of screen) <- the § sentinel +105 ¦ 4 <- 0 # bottom-of-screen; null since text fits on screen +106 ¦ # 5 (before cursor) <- the § sentinel +107 ¦ 6 <- 2 # left +108 ¦ 7 <- 4 # right (inclusive) +109 ¦ 8 <- 0 # bottom (not set until render) +110 ¦ 9 <- 1 # cursor row +111 ¦ 10 <- 2 # cursor column +112 ] +113 screen-should-contain [ 114 ¦ . . -115 ] -116 ] -117 -118 # Assumes cursor should be at coordinates (cursor-row, cursor-column) and -119 # updates before-cursor to match. Might also move coordinates if they're -120 # outside text. -121 def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ -122 local-scope -123 load-ingredients -124 return-unless editor, 1/top, 0/left -125 left:num <- get *editor, left:offset -126 screen-height:num <- screen-height screen -127 right:num <- get *editor, right:offset -128 # traversing editor -129 curr:&:duplex-list:char <- get *editor, top-of-screen:offset -130 prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev -131 curr <- next curr -132 # traversing screen -133 color:num <- copy 7/white -134 row:num <- copy 1/top -135 column:num <- copy left -136 cursor-row:num <- get *editor, cursor-row:offset -137 cursor-column:num <- get *editor, cursor-column:offset -138 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset -139 screen <- move-cursor screen, row, column -140 { -141 ¦ +next-character -142 ¦ break-unless curr -143 ¦ off-screen?:bool <- greater-or-equal row, screen-height -144 ¦ break-if off-screen? -145 ¦ # update editor.before-cursor -146 ¦ # Doing so at the start of each iteration ensures it stays one step behind -147 ¦ # the current character. -148 ¦ { -149 ¦ ¦ at-cursor-row?:bool <- equal row, cursor-row -150 ¦ ¦ break-unless at-cursor-row? -151 ¦ ¦ at-cursor?:bool <- equal column, cursor-column -152 ¦ ¦ break-unless at-cursor? -153 ¦ ¦ before-cursor <- copy prev -154 ¦ } -155 ¦ c:char <- get *curr, value:offset -156 ¦ <character-c-received> -157 ¦ { -158 ¦ ¦ # newline? move to left rather than 0 -159 ¦ ¦ newline?:bool <- equal c, 10/newline -160 ¦ ¦ break-unless newline? -161 ¦ ¦ # adjust cursor if necessary -162 ¦ ¦ { -163 ¦ ¦ ¦ at-cursor-row?:bool <- equal row, cursor-row -164 ¦ ¦ ¦ break-unless at-cursor-row? -165 ¦ ¦ ¦ left-of-cursor?:bool <- lesser-than column, cursor-column -166 ¦ ¦ ¦ break-unless left-of-cursor? -167 ¦ ¦ ¦ cursor-column <- copy column -168 ¦ ¦ ¦ before-cursor <- prev curr -169 ¦ ¦ } -170 ¦ ¦ # clear rest of line in this window -171 ¦ ¦ clear-line-until screen, right -172 ¦ ¦ # skip to next line -173 ¦ ¦ row <- add row, 1 -174 ¦ ¦ column <- copy left -175 ¦ ¦ screen <- move-cursor screen, row, column -176 ¦ ¦ curr <- next curr -177 ¦ ¦ prev <- next prev -178 ¦ ¦ loop +next-character -179 ¦ } -180 ¦ { -181 ¦ ¦ # at right? wrap. even if there's only one more letter left; we need -182 ¦ ¦ # room for clicking on the cursor after it. -183 ¦ ¦ at-right?:bool <- equal column, right -184 ¦ ¦ break-unless at-right? -185 ¦ ¦ # print wrap icon -186 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left -187 ¦ ¦ print screen, wrap-icon, 245/grey -188 ¦ ¦ column <- copy left -189 ¦ ¦ row <- add row, 1 -190 ¦ ¦ screen <- move-cursor screen, row, column -191 ¦ ¦ # don't increment curr -192 ¦ ¦ loop +next-character -193 ¦ } -194 ¦ print screen, c, color -195 ¦ curr <- next curr -196 ¦ prev <- next prev -197 ¦ column <- add column, 1 -198 ¦ loop -199 } -200 # save first character off-screen -201 *editor <- put *editor, bottom-of-screen:offset, curr -202 # is cursor to the right of the last line? move to end -203 { -204 ¦ at-cursor-row?:bool <- equal row, cursor-row -205 ¦ cursor-outside-line?:bool <- lesser-or-equal column, cursor-column -206 ¦ before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? -207 ¦ above-cursor-row?:bool <- lesser-than row, cursor-row -208 ¦ before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? -209 ¦ break-unless before-cursor? -210 ¦ cursor-row <- copy row -211 ¦ cursor-column <- copy column -212 ¦ before-cursor <- copy prev -213 } -214 *editor <- put *editor, bottom:offset, row -215 *editor <- put *editor, cursor-row:offset, cursor-row -216 *editor <- put *editor, cursor-column:offset, cursor-column -217 *editor <- put *editor, before-cursor:offset, before-cursor -218 return row, column -219 ] -220 -221 def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [ -222 local-scope -223 load-ingredients -224 # if it's the real screen, use the optimized primitive -225 { -226 ¦ break-if screen -227 ¦ clear-display-from row, column, left, right -228 ¦ return -229 } -230 # if not, go the slower route -231 screen <- move-cursor screen, row, column -232 clear-line-until screen, right -233 clear-rest-of-screen screen, row, left, right -234 ] -235 -236 def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ -237 local-scope -238 load-ingredients -239 row <- add row, 1 -240 # if it's the real screen, use the optimized primitive -241 { -242 ¦ break-if screen -243 ¦ clear-display-from row, left, left, right -244 ¦ return -245 } -246 screen <- move-cursor screen, row, left -247 screen-height:num <- screen-height screen -248 { -249 ¦ at-bottom-of-screen?:bool <- greater-or-equal row, screen-height -250 ¦ break-if at-bottom-of-screen? -251 ¦ screen <- move-cursor screen, row, left -252 ¦ clear-line-until screen, right -253 ¦ row <- add row, 1 -254 ¦ loop -255 } -256 ] -257 -258 scenario editor-prints-multiple-lines [ -259 local-scope -260 assume-screen 5/width, 5/height -261 s:text <- new [abc -262 def] -263 e:&:editor <- new-editor s, 0/left, 5/right -264 run [ -265 ¦ render screen, e -266 ] -267 screen-should-contain [ -268 ¦ . . -269 ¦ .abc . -270 ¦ .def . -271 ¦ . . -272 ] -273 ] -274 -275 scenario editor-handles-offsets [ -276 local-scope -277 assume-screen 5/width, 5/height -278 e:&:editor <- new-editor [abc], 1/left, 5/right -279 run [ -280 ¦ render screen, e -281 ] -282 screen-should-contain [ -283 ¦ . . -284 ¦ . abc . +115 ¦ . . +116 ¦ . . +117 ] +118 ] +119 +120 # Assumes cursor should be at coordinates (cursor-row, cursor-column) and +121 # updates before-cursor to match. Might also move coordinates if they're +122 # outside text. +123 def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ +124 local-scope +125 load-ingredients +126 return-unless editor, 1/top, 0/left +127 left:num <- get *editor, left:offset +128 screen-height:num <- screen-height screen +129 right:num <- get *editor, right:offset +130 # traversing editor +131 curr:&:duplex-list:char <- get *editor, top-of-screen:offset +132 prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev +133 curr <- next curr +134 # traversing screen +135 color:num <- copy 7/white +136 row:num <- copy 1/top +137 column:num <- copy left +138 cursor-row:num <- get *editor, cursor-row:offset +139 cursor-column:num <- get *editor, cursor-column:offset +140 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset +141 screen <- move-cursor screen, row, column +142 { +143 ¦ +next-character +144 ¦ break-unless curr +145 ¦ off-screen?:bool <- greater-or-equal row, screen-height +146 ¦ break-if off-screen? +147 ¦ # update editor.before-cursor +148 ¦ # Doing so at the start of each iteration ensures it stays one step behind +149 ¦ # the current character. +150 ¦ { +151 ¦ ¦ at-cursor-row?:bool <- equal row, cursor-row +152 ¦ ¦ break-unless at-cursor-row? +153 ¦ ¦ at-cursor?:bool <- equal column, cursor-column +154 ¦ ¦ break-unless at-cursor? +155 ¦ ¦ before-cursor <- copy prev +156 ¦ } +157 ¦ c:char <- get *curr, value:offset +158 ¦ <character-c-received> +159 ¦ { +160 ¦ ¦ # newline? move to left rather than 0 +161 ¦ ¦ newline?:bool <- equal c, 10/newline +162 ¦ ¦ break-unless newline? +163 ¦ ¦ # adjust cursor if necessary +164 ¦ ¦ { +165 ¦ ¦ ¦ at-cursor-row?:bool <- equal row, cursor-row +166 ¦ ¦ ¦ break-unless at-cursor-row? +167 ¦ ¦ ¦ left-of-cursor?:bool <- lesser-than column, cursor-column +168 ¦ ¦ ¦ break-unless left-of-cursor? +169 ¦ ¦ ¦ cursor-column <- copy column +170 ¦ ¦ ¦ before-cursor <- prev curr +171 ¦ ¦ } +172 ¦ ¦ # clear rest of line in this window +173 ¦ ¦ clear-line-until screen, right +174 ¦ ¦ # skip to next line +175 ¦ ¦ row <- add row, 1 +176 ¦ ¦ column <- copy left +177 ¦ ¦ screen <- move-cursor screen, row, column +178 ¦ ¦ curr <- next curr +179 ¦ ¦ prev <- next prev +180 ¦ ¦ loop +next-character +181 ¦ } +182 ¦ { +183 ¦ ¦ # at right? wrap. even if there's only one more letter left; we need +184 ¦ ¦ # room for clicking on the cursor after it. +185 ¦ ¦ at-right?:bool <- equal column, right +186 ¦ ¦ break-unless at-right? +187 ¦ ¦ # print wrap icon +188 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left +189 ¦ ¦ print screen, wrap-icon, 245/grey +190 ¦ ¦ column <- copy left +191 ¦ ¦ row <- add row, 1 +192 ¦ ¦ screen <- move-cursor screen, row, column +193 ¦ ¦ # don't increment curr +194 ¦ ¦ loop +next-character +195 ¦ } +196 ¦ print screen, c, color +197 ¦ curr <- next curr +198 ¦ prev <- next prev +199 ¦ column <- add column, 1 +200 ¦ loop +201 } +202 # save first character off-screen +203 *editor <- put *editor, bottom-of-screen:offset, curr +204 # is cursor to the right of the last line? move to end +205 { +206 ¦ at-cursor-row?:bool <- equal row, cursor-row +207 ¦ cursor-outside-line?:bool <- lesser-or-equal column, cursor-column +208 ¦ before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? +209 ¦ above-cursor-row?:bool <- lesser-than row, cursor-row +210 ¦ before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? +211 ¦ break-unless before-cursor? +212 ¦ cursor-row <- copy row +213 ¦ cursor-column <- copy column +214 ¦ before-cursor <- copy prev +215 } +216 *editor <- put *editor, bottom:offset, row +217 *editor <- put *editor, cursor-row:offset, cursor-row +218 *editor <- put *editor, cursor-column:offset, cursor-column +219 *editor <- put *editor, before-cursor:offset, before-cursor +220 return row, column +221 ] +222 +223 def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [ +224 local-scope +225 load-ingredients +226 # if it's the real screen, use the optimized primitive +227 { +228 ¦ break-if screen +229 ¦ clear-display-from row, column, left, right +230 ¦ return +231 } +232 # if not, go the slower route +233 screen <- move-cursor screen, row, column +234 clear-line-until screen, right +235 clear-rest-of-screen screen, row, left, right +236 ] +237 +238 def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ +239 local-scope +240 load-ingredients +241 row <- add row, 1 +242 # if it's the real screen, use the optimized primitive +243 { +244 ¦ break-if screen +245 ¦ clear-display-from row, left, left, right +246 ¦ return +247 } +248 screen <- move-cursor screen, row, left +249 screen-height:num <- screen-height screen +250 { +251 ¦ at-bottom-of-screen?:bool <- greater-or-equal row, screen-height +252 ¦ break-if at-bottom-of-screen? +253 ¦ screen <- move-cursor screen, row, left +254 ¦ clear-line-until screen, right +255 ¦ row <- add row, 1 +256 ¦ loop +257 } +258 ] +259 +260 scenario editor-prints-multiple-lines [ +261 local-scope +262 assume-screen 5/width, 5/height +263 s:text <- new [abc +264 def] +265 e:&:editor <- new-editor s, 0/left, 5/right +266 run [ +267 ¦ render screen, e +268 ] +269 screen-should-contain [ +270 ¦ . . +271 ¦ .abc . +272 ¦ .def . +273 ¦ . . +274 ] +275 ] +276 +277 scenario editor-handles-offsets [ +278 local-scope +279 assume-screen 5/width, 5/height +280 e:&:editor <- new-editor [abc], 1/left, 5/right +281 run [ +282 ¦ render screen, e +283 ] +284 screen-should-contain [ 285 ¦ . . -286 ] -287 ] -288 -289 scenario editor-prints-multiple-lines-at-offset [ -290 local-scope -291 assume-screen 5/width, 5/height -292 s:text <- new [abc -293 def] -294 e:&:editor <- new-editor s, 1/left, 5/right -295 run [ -296 ¦ render screen, e -297 ] -298 screen-should-contain [ -299 ¦ . . -300 ¦ . abc . -301 ¦ . def . -302 ¦ . . -303 ] -304 ] -305 -306 scenario editor-wraps-long-lines [ -307 local-scope -308 assume-screen 5/width, 5/height -309 e:&:editor <- new-editor [abc def], 0/left, 5/right -310 run [ -311 ¦ render screen, e -312 ] -313 screen-should-contain [ -314 ¦ . . -315 ¦ .abc ↩. -316 ¦ .def . -317 ¦ . . -318 ] -319 screen-should-contain-in-color 245/grey [ -320 ¦ . . -321 ¦ . ↩. +286 ¦ . abc . +287 ¦ . . +288 ] +289 ] +290 +291 scenario editor-prints-multiple-lines-at-offset [ +292 local-scope +293 assume-screen 5/width, 5/height +294 s:text <- new [abc +295 def] +296 e:&:editor <- new-editor s, 1/left, 5/right +297 run [ +298 ¦ render screen, e +299 ] +300 screen-should-contain [ +301 ¦ . . +302 ¦ . abc . +303 ¦ . def . +304 ¦ . . +305 ] +306 ] +307 +308 scenario editor-wraps-long-lines [ +309 local-scope +310 assume-screen 5/width, 5/height +311 e:&:editor <- new-editor [abc def], 0/left, 5/right +312 run [ +313 ¦ render screen, e +314 ] +315 screen-should-contain [ +316 ¦ . . +317 ¦ .abc ↩. +318 ¦ .def . +319 ¦ . . +320 ] +321 screen-should-contain-in-color 245/grey [ 322 ¦ . . -323 ¦ . . -324 ] -325 ] -326 -327 scenario editor-wraps-barely-long-lines [ -328 local-scope -329 assume-screen 5/width, 5/height -330 e:&:editor <- new-editor [abcde], 0/left, 5/right -331 run [ -332 ¦ render screen, e -333 ] -334 # still wrap, even though the line would fit. We need room to click on the -335 # end of the line -336 screen-should-contain [ -337 ¦ . . -338 ¦ .abcd↩. -339 ¦ .e . -340 ¦ . . -341 ] -342 screen-should-contain-in-color 245/grey [ -343 ¦ . . -344 ¦ . ↩. +323 ¦ . ↩. +324 ¦ . . +325 ¦ . . +326 ] +327 ] +328 +329 scenario editor-wraps-barely-long-lines [ +330 local-scope +331 assume-screen 5/width, 5/height +332 e:&:editor <- new-editor [abcde], 0/left, 5/right +333 run [ +334 ¦ render screen, e +335 ] +336 # still wrap, even though the line would fit. We need room to click on the +337 # end of the line +338 screen-should-contain [ +339 ¦ . . +340 ¦ .abcd↩. +341 ¦ .e . +342 ¦ . . +343 ] +344 screen-should-contain-in-color 245/grey [ 345 ¦ . . -346 ¦ . . -347 ] -348 ] -349 -350 scenario editor-with-empty-text [ -351 local-scope -352 assume-screen 5/width, 5/height -353 e:&:editor <- new-editor [], 0/left, 5/right -354 run [ -355 ¦ render screen, e -356 ¦ 3:num/raw <- get *e, cursor-row:offset -357 ¦ 4:num/raw <- get *e, cursor-column:offset -358 ] -359 screen-should-contain [ -360 ¦ . . -361 ¦ . . +346 ¦ . ↩. +347 ¦ . . +348 ¦ . . +349 ] +350 ] +351 +352 scenario editor-with-empty-text [ +353 local-scope +354 assume-screen 5/width, 5/height +355 e:&:editor <- new-editor [], 0/left, 5/right +356 run [ +357 ¦ render screen, e +358 ¦ 3:num/raw <- get *e, cursor-row:offset +359 ¦ 4:num/raw <- get *e, cursor-column:offset +360 ] +361 screen-should-contain [ 362 ¦ . . -363 ] -364 memory-should-contain [ -365 ¦ 3 <- 1 # cursor row -366 ¦ 4 <- 0 # cursor column -367 ] -368 ] -369 -370 # just a little color for Mu code +363 ¦ . . +364 ¦ . . +365 ] +366 memory-should-contain [ +367 ¦ 3 <- 1 # cursor row +368 ¦ 4 <- 0 # cursor column +369 ] +370 ] 371 -372 scenario render-colors-comments [ -373 local-scope -374 assume-screen 5/width, 5/height -375 s:text <- new [abc -376 # de -377 f] -378 e:&:editor <- new-editor s, 0/left, 5/right -379 run [ -380 ¦ render screen, e -381 ] -382 screen-should-contain [ -383 ¦ . . -384 ¦ .abc . -385 ¦ .# de . -386 ¦ .f . -387 ¦ . . -388 ] -389 screen-should-contain-in-color 12/lightblue, [ -390 ¦ . . -391 ¦ . . -392 ¦ .# de . +372 # just a little color for Mu code +373 +374 scenario render-colors-comments [ +375 local-scope +376 assume-screen 5/width, 5/height +377 s:text <- new [abc +378 # de +379 f] +380 e:&:editor <- new-editor s, 0/left, 5/right +381 run [ +382 ¦ render screen, e +383 ] +384 screen-should-contain [ +385 ¦ . . +386 ¦ .abc . +387 ¦ .# de . +388 ¦ .f . +389 ¦ . . +390 ] +391 screen-should-contain-in-color 12/lightblue, [ +392 ¦ . . 393 ¦ . . -394 ¦ . . -395 ] -396 screen-should-contain-in-color 7/white, [ -397 ¦ . . -398 ¦ .abc . +394 ¦ .# de . +395 ¦ . . +396 ¦ . . +397 ] +398 screen-should-contain-in-color 7/white, [ 399 ¦ . . -400 ¦ .f . +400 ¦ .abc . 401 ¦ . . -402 ] -403 ] -404 -405 after <character-c-received> [ -406 color <- get-color color, c -407 ] -408 -409 # so far the previous color is all the information we need; that may change -410 def get-color color:num, c:char -> color:num [ -411 local-scope -412 load-ingredients -413 color-is-white?:bool <- equal color, 7/white -414 # if color is white and next character is '#', switch color to blue -415 { -416 ¦ break-unless color-is-white? -417 ¦ starting-comment?:bool <- equal c, 35/# -418 ¦ break-unless starting-comment? -419 ¦ trace 90, [app], [switch color back to blue] -420 ¦ return 12/lightblue -421 } -422 # if color is blue and next character is newline, switch color to white -423 { -424 ¦ color-is-blue?:bool <- equal color, 12/lightblue -425 ¦ break-unless color-is-blue? -426 ¦ ending-comment?:bool <- equal c, 10/newline -427 ¦ break-unless ending-comment? -428 ¦ trace 90, [app], [switch color back to white] -429 ¦ return 7/white -430 } -431 # if color is white (no comments) and next character is '<', switch color to red -432 { -433 ¦ break-unless color-is-white? -434 ¦ starting-assignment?:bool <- equal c, 60/< -435 ¦ break-unless starting-assignment? -436 ¦ return 1/red -437 } -438 # if color is red and next character is space, switch color to white -439 { -440 ¦ color-is-red?:bool <- equal color, 1/red -441 ¦ break-unless color-is-red? -442 ¦ ending-assignment?:bool <- equal c, 32/space -443 ¦ break-unless ending-assignment? -444 ¦ return 7/white -445 } -446 # otherwise no change -447 return color -448 ] -449 -450 scenario render-colors-assignment [ -451 local-scope -452 assume-screen 8/width, 5/height -453 s:text <- new [abc -454 d <- e -455 f] -456 e:&:editor <- new-editor s, 0/left, 8/right -457 run [ -458 ¦ render screen, e -459 ] -460 screen-should-contain [ -461 ¦ . . -462 ¦ .abc . -463 ¦ .d <- e . -464 ¦ .f . -465 ¦ . . -466 ] -467 screen-should-contain-in-color 1/red, [ -468 ¦ . . -469 ¦ . . -470 ¦ . <- . +402 ¦ .f . +403 ¦ . . +404 ] +405 ] +406 +407 after <character-c-received> [ +408 color <- get-color color, c +409 ] +410 +411 # so far the previous color is all the information we need; that may change +412 def get-color color:num, c:char -> color:num [ +413 local-scope +414 load-ingredients +415 color-is-white?:bool <- equal color, 7/white +416 # if color is white and next character is '#', switch color to blue +417 { +418 ¦ break-unless color-is-white? +419 ¦ starting-comment?:bool <- equal c, 35/# +420 ¦ break-unless starting-comment? +421 ¦ trace 90, [app], [switch color back to blue] +422 ¦ return 12/lightblue +423 } +424 # if color is blue and next character is newline, switch color to white +425 { +426 ¦ color-is-blue?:bool <- equal color, 12/lightblue +427 ¦ break-unless color-is-blue? +428 ¦ ending-comment?:bool <- equal c, 10/newline +429 ¦ break-unless ending-comment? +430 ¦ trace 90, [app], [switch color back to white] +431 ¦ return 7/white +432 } +433 # if color is white (no comments) and next character is '<', switch color to red +434 { +435 ¦ break-unless color-is-white? +436 ¦ starting-assignment?:bool <- equal c, 60/< +437 ¦ break-unless starting-assignment? +438 ¦ return 1/red +439 } +440 # if color is red and next character is space, switch color to white +441 { +442 ¦ color-is-red?:bool <- equal color, 1/red +443 ¦ break-unless color-is-red? +444 ¦ ending-assignment?:bool <- equal c, 32/space +445 ¦ break-unless ending-assignment? +446 ¦ return 7/white +447 } +448 # otherwise no change +449 return color +450 ] +451 +452 scenario render-colors-assignment [ +453 local-scope +454 assume-screen 8/width, 5/height +455 s:text <- new [abc +456 d <- e +457 f] +458 e:&:editor <- new-editor s, 0/left, 8/right +459 run [ +460 ¦ render screen, e +461 ] +462 screen-should-contain [ +463 ¦ . . +464 ¦ .abc . +465 ¦ .d <- e . +466 ¦ .f . +467 ¦ . . +468 ] +469 screen-should-contain-in-color 1/red, [ +470 ¦ . . 471 ¦ . . -472 ¦ . . -473 ] -474 ] +472 ¦ . <- . +473 ¦ . . +474 ¦ . . +475 ] +476 ] diff --git a/html/edit/002-typing.mu.html b/html/edit/002-typing.mu.html index ad249e5c..29c0a77e 100644 --- a/html/edit/002-typing.mu.html +++ b/html/edit/002-typing.mu.html @@ -69,7 +69,7 @@ if ('onhashchange' in window) { 6 local-scope 7 load-ingredients 8 open-console - 9 editor:&:editor <- new-editor text, 5/left, 45/right + 9 editor:&:editor <- new-editor text, 5/left, 45/right 10 editor-event-loop 0/screen, 0/console, editor 11 close-console 12 ] @@ -82,7 +82,7 @@ if ('onhashchange' in window) { 19 ¦ +next-event 20 ¦ cursor-row:num <- get *editor, cursor-row:offset 21 ¦ cursor-column:num <- get *editor, cursor-column:offset - 22 ¦ screen <- move-cursor screen, cursor-row, cursor-column + 22 ¦ screen <- move-cursor screen, cursor-row, cursor-column 23 ¦ e:event, found?:bool, quit?:bool, console <- read-event console 24 ¦ loop-unless found? 25 ¦ break-if quit? # only in tests @@ -139,7 +139,7 @@ if ('onhashchange' in window) { 76 return-unless editor 77 left:num <- get *editor, left:offset 78 right:num <- get *editor, right:offset - 79 screen-height:num <- screen-height screen + 79 screen-height:num <- screen-height screen 80 # count newlines until screen row 81 curr:&:duplex-list:char <- get *editor, top-of-screen:offset 82 prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev @@ -154,7 +154,7 @@ if ('onhashchange' in window) { 91 { 92 ¦ +next-character 93 ¦ break-unless curr - 94 ¦ off-screen?:bool <- greater-or-equal row, screen-height + 94 ¦ off-screen?:bool <- greater-or-equal row, screen-height 95 ¦ break-if off-screen? 96 ¦ # update editor.before-cursor 97 ¦ # Doing so at the start of each iteration ensures it stays one step behind @@ -228,8 +228,8 @@ if ('onhashchange' in window) { 165 local-scope 166 load-ingredients 167 return-unless editor, 0/don't-render - 168 screen-width:num <- screen-width screen - 169 screen-height:num <- screen-height screen + 168 screen-width:num <- screen-width screen + 169 screen-height:num <- screen-height screen 170 left:num <- get *editor, left:offset 171 right:num <- get *editor, right:offset 172 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset @@ -274,8 +274,8 @@ if ('onhashchange' in window) { 211 right:num <- get *editor, right:offset 212 save-row:num <- copy cursor-row 213 save-column:num <- copy cursor-column - 214 screen-width:num <- screen-width screen - 215 screen-height:num <- screen-height screen + 214 screen-width:num <- screen-width screen + 215 screen-height:num <- screen-height screen 216 # occasionally we'll need to mess with the cursor 217 <insert-character-special-case> 218 # but mostly we'll just move the cursor right @@ -286,22 +286,22 @@ if ('onhashchange' in window) { 223 ¦ # at end of all text? no need to scroll? just print the character and leave 224 ¦ at-end?:bool <- equal next, 0/null 225 ¦ break-unless at-end? - 226 ¦ bottom:num <- subtract screen-height, 1 + 226 ¦ bottom:num <- subtract screen-height, 1 227 ¦ at-bottom?:bool <- equal save-row, bottom 228 ¦ at-right?:bool <- equal save-column, right 229 ¦ overflow?:bool <- and at-bottom?, at-right? 230 ¦ break-if overflow? - 231 ¦ move-cursor screen, save-row, save-column + 231 ¦ move-cursor screen, save-row, save-column 232 ¦ print screen, c 233 ¦ return 0/don't-render 234 } 235 { 236 ¦ # not at right margin? print the character and rest of line 237 ¦ break-unless next - 238 ¦ at-right?:bool <- greater-or-equal cursor-column, screen-width + 238 ¦ at-right?:bool <- greater-or-equal cursor-column, screen-width 239 ¦ break-if at-right? 240 ¦ curr:&:duplex-list:char <- copy before-cursor - 241 ¦ move-cursor screen, save-row, save-column + 241 ¦ move-cursor screen, save-row, save-column 242 ¦ curr-column:num <- copy save-column 243 ¦ { 244 ¦ ¦ # hit right margin? give up and let caller render @@ -328,18 +328,18 @@ if ('onhashchange' in window) { 265 load-ingredients 266 left:num <- get *editor, left:offset 267 right:num <- get *editor, right:offset - 268 row:num, column:num <- render screen, editor - 269 clear-line-until screen, right + 268 row:num, column:num <- render screen, editor + 269 clear-line-until screen, right 270 row <- add row, 1 271 draw-horizontal screen, row, left, right, 9480/horizontal-dotted 272 row <- add row, 1 - 273 clear-screen-from screen, row, left, left, right + 273 clear-screen-from screen, row, left, left, right 274 ] 275 276 scenario editor-handles-empty-event-queue [ 277 local-scope 278 assume-screen 10/width, 5/height - 279 e:&:editor <- new-editor [abc], 0/left, 10/right + 279 e:&:editor <- new-editor [abc], 0/left, 10/right 280 editor-render screen, e 281 assume-console [] 282 run [ @@ -356,7 +356,7 @@ if ('onhashchange' in window) { 293 scenario editor-handles-mouse-clicks [ 294 local-scope 295 assume-screen 10/width, 5/height - 296 e:&:editor <- new-editor [abc], 0/left, 10/right + 296 e:&:editor <- new-editor [abc], 0/left, 10/right 297 editor-render screen, e 298 $clear-trace 299 assume-console [ @@ -383,7 +383,7 @@ if ('onhashchange' in window) { 320 scenario editor-handles-mouse-clicks-outside-text [ 321 local-scope 322 assume-screen 10/width, 5/height - 323 e:&:editor <- new-editor [abc], 0/left, 10/right + 323 e:&:editor <- new-editor [abc], 0/left, 10/right 324 $clear-trace 325 assume-console [ 326 ¦ left-click 1, 7 # last line, to the right of text @@ -405,7 +405,7 @@ if ('onhashchange' in window) { 342 assume-screen 10/width, 5/height 343 s:text <- new [abc 344 def] - 345 e:&:editor <- new-editor s, 0/left, 10/right + 345 e:&:editor <- new-editor s, 0/left, 10/right 346 $clear-trace 347 assume-console [ 348 ¦ left-click 1, 7 # interior line, to the right of text @@ -427,7 +427,7 @@ if ('onhashchange' in window) { 364 assume-screen 10/width, 5/height 365 s:text <- new [abc 366 def] - 367 e:&:editor <- new-editor s, 0/left, 10/right + 367 e:&:editor <- new-editor s, 0/left, 10/right 368 $clear-trace 369 assume-console [ 370 ¦ left-click 3, 7 # below text @@ -448,7 +448,7 @@ if ('onhashchange' in window) { 385 local-scope 386 assume-screen 10/width, 5/height 387 # editor occupies only left half of screen - 388 e:&:editor <- new-editor [abc], 0/left, 5/right + 388 e:&:editor <- new-editor [abc], 0/left, 5/right 389 editor-render screen, e 390 $clear-trace 391 assume-console [ @@ -476,7 +476,7 @@ if ('onhashchange' in window) { 413 scenario editor-handles-mouse-clicks-in-menu-area [ 414 local-scope 415 assume-screen 10/width, 5/height - 416 e:&:editor <- new-editor [abc], 0/left, 5/right + 416 e:&:editor <- new-editor [abc], 0/left, 5/right 417 editor-render screen, e 418 $clear-trace 419 assume-console [ @@ -498,7 +498,7 @@ if ('onhashchange' in window) { 435 scenario editor-inserts-characters-into-empty-editor [ 436 local-scope 437 assume-screen 10/width, 5/height - 438 e:&:editor <- new-editor [], 0/left, 5/right + 438 e:&:editor <- new-editor [], 0/left, 5/right 439 editor-render screen, e 440 $clear-trace 441 assume-console [ @@ -519,7 +519,7 @@ if ('onhashchange' in window) { 456 scenario editor-inserts-characters-at-cursor [ 457 local-scope 458 assume-screen 10/width, 5/height - 459 e:&:editor <- new-editor [abc], 0/left, 10/right + 459 e:&:editor <- new-editor [abc], 0/left, 10/right 460 editor-render screen, e 461 $clear-trace 462 # type two letters at different places @@ -543,7 +543,7 @@ if ('onhashchange' in window) { 480 scenario editor-inserts-characters-at-cursor-2 [ 481 local-scope 482 assume-screen 10/width, 5/height - 483 e:&:editor <- new-editor [abc], 0/left, 10/right + 483 e:&:editor <- new-editor [abc], 0/left, 10/right 484 editor-render screen, e 485 $clear-trace 486 assume-console [ @@ -567,7 +567,7 @@ if ('onhashchange' in window) { 504 assume-screen 10/width, 5/height 505 s:text <- new [abc 506 d] - 507 e:&:editor <- new-editor s, 0/left, 10/right + 507 e:&:editor <- new-editor s, 0/left, 10/right 508 editor-render screen, e 509 $clear-trace 510 assume-console [ @@ -590,7 +590,7 @@ if ('onhashchange' in window) { 527 scenario editor-inserts-characters-at-cursor-3 [ 528 local-scope 529 assume-screen 10/width, 5/height - 530 e:&:editor <- new-editor [abc], 0/left, 10/right + 530 e:&:editor <- new-editor [abc], 0/left, 10/right 531 editor-render screen, e 532 $clear-trace 533 assume-console [ @@ -614,7 +614,7 @@ if ('onhashchange' in window) { 551 assume-screen 10/width, 5/height 552 s:text <- new [abc 553 d] - 554 e:&:editor <- new-editor s, 0/left, 10/right + 554 e:&:editor <- new-editor s, 0/left, 10/right 555 editor-render screen, e 556 $clear-trace 557 assume-console [ @@ -639,7 +639,7 @@ if ('onhashchange' in window) { 576 assume-screen 10/width, 5/height 577 s:text <- new [abc 578 d] - 579 e:&:editor <- new-editor s, 0/left, 10/right + 579 e:&:editor <- new-editor s, 0/left, 10/right 580 editor-render screen, e 581 $clear-trace 582 assume-console [ @@ -662,7 +662,7 @@ if ('onhashchange' in window) { 599 scenario editor-moves-cursor-after-inserting-characters [ 600 local-scope 601 assume-screen 10/width, 5/height - 602 e:&:editor <- new-editor [ab], 0/left, 5/right + 602 e:&:editor <- new-editor [ab], 0/left, 5/right 603 editor-render screen, e 604 assume-console [ 605 ¦ type [01] @@ -683,7 +683,7 @@ if ('onhashchange' in window) { 620 scenario editor-wraps-line-on-insert [ 621 local-scope 622 assume-screen 5/width, 5/height - 623 e:&:editor <- new-editor [abc], 0/left, 5/right + 623 e:&:editor <- new-editor [abc], 0/left, 5/right 624 editor-render screen, e 625 # type a letter 626 assume-console [ @@ -723,7 +723,7 @@ if ('onhashchange' in window) { 660 assume-screen 10/width, 5/height 661 s:text <- new [abcdefg 662 defg] - 663 e:&:editor <- new-editor s, 0/left, 5/right + 663 e:&:editor <- new-editor s, 0/left, 5/right 664 editor-render screen, e 665 # type more text at the start 666 assume-console [ @@ -792,7 +792,7 @@ if ('onhashchange' in window) { 729 ¦ *editor <- put *editor, cursor-row:offset, cursor-row 730 ¦ # if we're out of the screen, scroll down 731 ¦ { - 732 ¦ ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height + 732 ¦ ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height 733 ¦ ¦ break-unless below-screen? 734 ¦ ¦ <scroll-down> 735 ¦ } @@ -803,7 +803,7 @@ if ('onhashchange' in window) { 740 scenario editor-wraps-cursor-after-inserting-characters-in-middle-of-line [ 741 local-scope 742 assume-screen 10/width, 5/height - 743 e:&:editor <- new-editor [abcde], 0/left, 5/right + 743 e:&:editor <- new-editor [abcde], 0/left, 5/right 744 assume-console [ 745 ¦ left-click 1, 3 # right before the wrap icon 746 ¦ type [f] @@ -832,7 +832,7 @@ if ('onhashchange' in window) { 769 # create an editor containing two lines 770 s:text <- new [abc 771 xyz] - 772 e:&:editor <- new-editor s, 0/left, 5/right + 772 e:&:editor <- new-editor s, 0/left, 5/right 773 editor-render screen, e 774 screen-should-contain [ 775 ¦ . . @@ -860,7 +860,7 @@ if ('onhashchange' in window) { 797 scenario editor-wraps-cursor-to-left-margin [ 798 local-scope 799 assume-screen 10/width, 5/height - 800 e:&:editor <- new-editor [abcde], 2/left, 7/right + 800 e:&:editor <- new-editor [abcde], 2/left, 7/right 801 assume-console [ 802 ¦ left-click 1, 5 # line is full; no wrap icon yet 803 ¦ type [01] @@ -889,14 +889,14 @@ if ('onhashchange' in window) { 826 indent?:bool 827 ] 828 - 829 after <editor-initialization> [ + 829 after <editor-initialization> [ 830 *result <- put *result, indent?:offset, 1/true 831 ] 832 833 scenario editor-moves-cursor-down-after-inserting-newline [ 834 local-scope 835 assume-screen 10/width, 5/height - 836 e:&:editor <- new-editor [abc], 0/left, 10/right + 836 e:&:editor <- new-editor [abc], 0/left, 10/right 837 assume-console [ 838 ¦ type [0 839 1] @@ -932,7 +932,7 @@ if ('onhashchange' in window) { 869 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset 870 left:num <- get *editor, left:offset 871 right:num <- get *editor, right:offset - 872 screen-height:num <- screen-height screen + 872 screen-height:num <- screen-height screen 873 # insert newline 874 insert 10/newline, before-cursor 875 before-cursor <- next before-cursor @@ -943,7 +943,7 @@ if ('onhashchange' in window) { 880 *editor <- put *editor, cursor-column:offset, cursor-column 881 # maybe scroll 882 { - 883 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater + 883 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater 884 ¦ break-unless below-screen? 885 ¦ <scroll-down> 886 ¦ cursor-row <- subtract cursor-row, 1 # bring back into screen range @@ -1000,7 +1000,7 @@ if ('onhashchange' in window) { 937 scenario editor-moves-cursor-down-after-inserting-newline-2 [ 938 local-scope 939 assume-screen 10/width, 5/height - 940 e:&:editor <- new-editor [abc], 1/left, 10/right + 940 e:&:editor <- new-editor [abc], 1/left, 10/right 941 assume-console [ 942 ¦ type [0 943 1] @@ -1020,7 +1020,7 @@ if ('onhashchange' in window) { 957 scenario editor-clears-previous-line-completely-after-inserting-newline [ 958 local-scope 959 assume-screen 10/width, 5/height - 960 e:&:editor <- new-editor [abcde], 0/left, 5/right + 960 e:&:editor <- new-editor [abcde], 0/left, 5/right 961 editor-render screen, e 962 screen-should-contain [ 963 ¦ . . @@ -1051,7 +1051,7 @@ if ('onhashchange' in window) { 988 s:text <- new [ab 989 cd 990 ef] - 991 e:&:editor <- new-editor s, 0/left, 10/right + 991 e:&:editor <- new-editor s, 0/left, 10/right 992 # position cursor after 'cd' and hit 'newline' 993 assume-console [ 994 ¦ left-click 2, 8 @@ -1076,7 +1076,7 @@ if ('onhashchange' in window) { 1013 s:text <- new [ab 1014 cd 1015 ef] -1016 e:&:editor <- new-editor s, 0/left, 10/right +1016 e:&:editor <- new-editor s, 0/left, 10/right 1017 # position cursor after 'cd' and hit 'newline' surrounded by paste markers 1018 assume-console [ 1019 ¦ left-click 2, 8 @@ -1135,7 +1135,7 @@ if ('onhashchange' in window) { 1072 ¦ break-if bg-color-found? 1073 ¦ bg-color <- copy 0/black 1074 } -1075 screen <- move-cursor screen, row, x +1075 screen <- move-cursor screen, row, x 1076 { 1077 ¦ continue?:bool <- lesser-or-equal x, right # right is inclusive, to match editor semantics 1078 ¦ break-unless continue? diff --git a/html/edit/003-shortcuts.mu.html b/html/edit/003-shortcuts.mu.html index 83871010..8e3bc675 100644 --- a/html/edit/003-shortcuts.mu.html +++ b/html/edit/003-shortcuts.mu.html @@ -72,7 +72,7 @@ if ('onhashchange' in window) { 10 # just one character in final line 11 s:text <- new [ab 12 cd] - 13 e:&:editor <- new-editor s, 0/left, 5/right + 13 e:&:editor <- new-editor s, 0/left, 5/right 14 assume-console [ 15 ¦ press tab 16 ] @@ -103,7 +103,7 @@ if ('onhashchange' in window) { 41 scenario editor-handles-backspace-key [ 42 local-scope 43 assume-screen 10/width, 5/height - 44 e:&:editor <- new-editor [abc], 0/left, 10/right + 44 e:&:editor <- new-editor [abc], 0/left, 10/right 45 editor-render screen, e 46 $clear-trace 47 assume-console [ @@ -158,7 +158,7 @@ if ('onhashchange' in window) { 96 before-cursor <- copy prev 97 *editor <- put *editor, before-cursor:offset, before-cursor 98 return-if scroll?, 1/go-render - 99 screen-width:num <- screen-width screen + 99 screen-width:num <- screen-width screen 100 cursor-row:num <- get *editor, cursor-row:offset 101 cursor-column:num <- get *editor, cursor-column:offset 102 # did we just backspace over a newline? @@ -167,7 +167,7 @@ if ('onhashchange' in window) { 105 left:num <- get *editor, left:offset 106 right:num <- get *editor, right:offset 107 curr:&:duplex-list:char <- next before-cursor - 108 screen <- move-cursor screen, cursor-row, cursor-column + 108 screen <- move-cursor screen, cursor-row, cursor-column 109 curr-column:num <- copy cursor-column 110 { 111 ¦ # hit right margin? give up and let caller render @@ -278,7 +278,7 @@ if ('onhashchange' in window) { 216 # just one character in final line 217 s:text <- new [ab 218 cd] - 219 e:&:editor <- new-editor s, 0/left, 10/right + 219 e:&:editor <- new-editor s, 0/left, 10/right 220 assume-console [ 221 ¦ left-click 2, 0 # cursor at only character in final line 222 ¦ press backspace @@ -306,7 +306,7 @@ if ('onhashchange' in window) { 244 # initialize editor with two long-ish but non-wrapping lines 245 s:text <- new [abc def 246 ghi jkl] - 247 e:&:editor <- new-editor s, 0/left, 10/right + 247 e:&:editor <- new-editor s, 0/left, 10/right 248 editor-render screen, e 249 $clear-trace 250 # position the cursor at the start of the second and hit backspace @@ -331,7 +331,7 @@ if ('onhashchange' in window) { 269 local-scope 270 assume-screen 10/width, 5/height 271 # initialize editor in part of the screen with a long line - 272 e:&:editor <- new-editor [abc def ghij], 0/left, 8/right + 272 e:&:editor <- new-editor [abc def ghij], 0/left, 8/right 273 editor-render screen, e 274 # confirm that it wraps 275 screen-should-contain [ @@ -364,7 +364,7 @@ if ('onhashchange' in window) { 302 scenario editor-handles-delete-key [ 303 local-scope 304 assume-screen 10/width, 5/height - 305 e:&:editor <- new-editor [abc], 0/left, 10/right + 305 e:&:editor <- new-editor [abc], 0/left, 10/right 306 editor-render screen, e 307 $clear-trace 308 assume-console [ @@ -422,12 +422,12 @@ if ('onhashchange' in window) { 360 curr:&:duplex-list:char <- next before-cursor # refresh after remove above 361 cursor-row:num <- get *editor, cursor-row:offset 362 cursor-column:num <- get *editor, cursor-column:offset - 363 screen <- move-cursor screen, cursor-row, cursor-column + 363 screen <- move-cursor screen, cursor-row, cursor-column 364 curr-column:num <- copy cursor-column - 365 screen-width:num <- screen-width screen + 365 screen-width:num <- screen-width screen 366 { 367 ¦ # hit right margin? give up and let caller render - 368 ¦ at-right?:bool <- greater-or-equal curr-column, screen-width + 368 ¦ at-right?:bool <- greater-or-equal curr-column, screen-width 369 ¦ return-if at-right?, 1/go-render 370 ¦ break-unless curr 371 ¦ # newline? done. @@ -450,7 +450,7 @@ if ('onhashchange' in window) { 388 scenario editor-moves-cursor-right-with-key [ 389 local-scope 390 assume-screen 10/width, 5/height - 391 e:&:editor <- new-editor [abc], 0/left, 10/right + 391 e:&:editor <- new-editor [abc], 0/left, 10/right 392 editor-render screen, e 393 $clear-trace 394 assume-console [ @@ -480,15 +480,15 @@ if ('onhashchange' in window) { 418 ¦ <move-cursor-begin> 419 ¦ before-cursor <- copy next-cursor 420 ¦ *editor <- put *editor, before-cursor:offset, before-cursor - 421 ¦ go-render?:bool <- move-cursor-coordinates-right editor, screen-height - 422 ¦ screen <- move-cursor screen, cursor-row, cursor-column + 421 ¦ go-render?:bool <- move-cursor-coordinates-right editor, screen-height + 422 ¦ screen <- move-cursor screen, cursor-row, cursor-column 423 ¦ undo-coalesce-tag:num <- copy 2/right-arrow 424 ¦ <move-cursor-end> 425 ¦ return 426 } 427 ] 428 - 429 def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ + 429 def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ 430 local-scope 431 load-ingredients 432 before-cursor:&:duplex-list:char <- get *editor before-cursor:offset @@ -505,7 +505,7 @@ if ('onhashchange' in window) { 443 ¦ *editor <- put *editor, cursor-row:offset, cursor-row 444 ¦ cursor-column <- copy left 445 ¦ *editor <- put *editor, cursor-column:offset, cursor-column - 446 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal + 446 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal 447 ¦ return-unless below-screen?, 0/don't-render 448 ¦ <scroll-down> 449 ¦ cursor-row <- subtract cursor-row, 1 # bring back into screen range @@ -528,7 +528,7 @@ if ('onhashchange' in window) { 466 ¦ *editor <- put *editor, cursor-row:offset, cursor-row 467 ¦ cursor-column <- copy left 468 ¦ *editor <- put *editor, cursor-column:offset, cursor-column - 469 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal + 469 ¦ below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal 470 ¦ return-unless below-screen?, 0/no-more-render 471 ¦ <scroll-down> 472 ¦ cursor-row <- subtract cursor-row, 1 # bring back into screen range @@ -546,7 +546,7 @@ if ('onhashchange' in window) { 484 assume-screen 10/width, 5/height 485 s:text <- new [abc 486 d] - 487 e:&:editor <- new-editor s, 0/left, 10/right + 487 e:&:editor <- new-editor s, 0/left, 10/right 488 editor-render screen, e 489 $clear-trace 490 # type right-arrow a few times to get to start of second line @@ -582,7 +582,7 @@ if ('onhashchange' in window) { 520 assume-screen 10/width, 5/height 521 s:text <- new [abc 522 d] - 523 e:&:editor <- new-editor s, 1/left, 10/right + 523 e:&:editor <- new-editor s, 1/left, 10/right 524 editor-render screen, e 525 assume-console [ 526 ¦ press right-arrow @@ -606,7 +606,7 @@ if ('onhashchange' in window) { 544 scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ 545 local-scope 546 assume-screen 10/width, 5/height - 547 e:&:editor <- new-editor [abcdef], 0/left, 5/right + 547 e:&:editor <- new-editor [abcdef], 0/left, 5/right 548 editor-render screen, e 549 $clear-trace 550 assume-console [ @@ -636,7 +636,7 @@ if ('onhashchange' in window) { 574 local-scope 575 assume-screen 10/width, 5/height 576 # line just barely wrapping - 577 e:&:editor <- new-editor [abcde], 0/left, 5/right + 577 e:&:editor <- new-editor [abcde], 0/left, 5/right 578 editor-render screen, e 579 $clear-trace 580 # position cursor at last character before wrap and hit right-arrow @@ -672,7 +672,7 @@ if ('onhashchange' in window) { 610 scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ 611 local-scope 612 assume-screen 10/width, 5/height - 613 e:&:editor <- new-editor [abcdef], 1/left, 6/right + 613 e:&:editor <- new-editor [abcdef], 1/left, 6/right 614 editor-render screen, e 615 $clear-trace 616 assume-console [ @@ -703,7 +703,7 @@ if ('onhashchange' in window) { 641 assume-screen 10/width, 5/height 642 s:text <- new [abc 643 d] - 644 e:&:editor <- new-editor s, 0/left, 10/right + 644 e:&:editor <- new-editor s, 0/left, 10/right 645 editor-render screen, e 646 $clear-trace 647 # move to end of line, press right-arrow, type a character @@ -733,7 +733,7 @@ if ('onhashchange' in window) { 671 scenario editor-moves-cursor-left-with-key [ 672 local-scope 673 assume-screen 10/width, 5/height - 674 e:&:editor <- new-editor [abc], 0/left, 10/right + 674 e:&:editor <- new-editor [abc], 0/left, 10/right 675 editor-render screen, e 676 $clear-trace 677 assume-console [ @@ -777,7 +777,7 @@ if ('onhashchange' in window) { 715 # initialize editor with two lines 716 s:text <- new [abc 717 d] - 718 e:&:editor <- new-editor s, 0/left, 10/right + 718 e:&:editor <- new-editor s, 0/left, 10/right 719 editor-render screen, e 720 $clear-trace 721 # position cursor at start of second line (so there's no previous newline) @@ -804,7 +804,7 @@ if ('onhashchange' in window) { 742 s:text <- new [abc 743 def 744 g] - 745 e:&:editor <- new-editor s:text, 0/left, 10/right + 745 e:&:editor <- new-editor s:text, 0/left, 10/right 746 editor-render screen, e 747 $clear-trace 748 # position cursor further down (so there's a newline before the character at @@ -833,7 +833,7 @@ if ('onhashchange' in window) { 771 s:text <- new [abc 772 def 773 g] - 774 e:&:editor <- new-editor s, 0/left, 10/right + 774 e:&:editor <- new-editor s, 0/left, 10/right 775 editor-render screen, e 776 $clear-trace 777 # position cursor at start of text, press left-arrow, then type a character @@ -863,7 +863,7 @@ if ('onhashchange' in window) { 801 s:text <- new [abc 802 803 d] - 804 e:&:editor <- new-editor s, 0/left, 10/right + 804 e:&:editor <- new-editor s, 0/left, 10/right 805 editor-render screen, e:&:editor 806 $clear-trace 807 # position cursor right after empty line @@ -889,7 +889,7 @@ if ('onhashchange' in window) { 827 local-scope 828 assume-screen 10/width, 5/height 829 # initialize editor with a wrapping line - 830 e:&:editor <- new-editor [abcdef], 0/left, 5/right + 830 e:&:editor <- new-editor [abcdef], 0/left, 5/right 831 editor-render screen, e 832 $clear-trace 833 screen-should-contain [ @@ -922,7 +922,7 @@ if ('onhashchange' in window) { 860 # initialize editor with a wrapping line followed by a second line 861 s:text <- new [abcdef 862 g] - 863 e:&:editor <- new-editor s, 0/left, 5/right + 863 e:&:editor <- new-editor s, 0/left, 5/right 864 editor-render screen, e 865 $clear-trace 866 screen-should-contain [ @@ -955,7 +955,7 @@ if ('onhashchange' in window) { 893 # initialize editor with a line on the verge of wrapping, followed by a second line 894 s:text <- new [abcd 895 e] - 896 e:&:editor <- new-editor s, 0/left, 5/right + 896 e:&:editor <- new-editor s, 0/left, 5/right 897 editor-render screen, e 898 $clear-trace 899 screen-should-contain [ @@ -991,7 +991,7 @@ if ('onhashchange' in window) { 929 assume-screen 10/width, 5/height 930 s:text <- new [abc 931 def] - 932 e:&:editor <- new-editor s, 0/left, 10/right + 932 e:&:editor <- new-editor s, 0/left, 10/right 933 editor-render screen, e 934 $clear-trace 935 assume-console [ @@ -1105,7 +1105,7 @@ if ('onhashchange' in window) { 1043 assume-screen 10/width, 5/height 1044 s:text <- new [ab 1045 def] -1046 e:&:editor <- new-editor s, 0/left, 10/right +1046 e:&:editor <- new-editor s, 0/left, 10/right 1047 editor-render screen, e 1048 $clear-trace 1049 assume-console [ @@ -1142,7 +1142,7 @@ if ('onhashchange' in window) { 1080 assume-screen 10/width, 5/height 1081 s:text <- new [ 1082 def] -1083 e:&:editor <- new-editor s, 0/left, 10/right +1083 e:&:editor <- new-editor s, 0/left, 10/right 1084 editor-render screen, e 1085 $clear-trace 1086 assume-console [ @@ -1181,7 +1181,7 @@ if ('onhashchange' in window) { 1119 s:text <- new [abc 1120 def 1121 ghi] -1122 e:&:editor <- new-editor s, 0/left, 10/right +1122 e:&:editor <- new-editor s, 0/left, 10/right 1123 editor-render screen, e 1124 $clear-trace 1125 # click on the third line and hit up-arrow, so you end up just after a newline @@ -1221,7 +1221,7 @@ if ('onhashchange' in window) { 1159 assume-screen 10/width, 5/height 1160 s:text <- new [abc 1161 def] -1162 e:&:editor <- new-editor s, 0/left, 10/right +1162 e:&:editor <- new-editor s, 0/left, 10/right 1163 editor-render screen, e 1164 $clear-trace 1165 # cursor starts out at (1, 0) @@ -1259,14 +1259,14 @@ if ('onhashchange' in window) { 1197 ¦ move-to-next-line?:bool <- equal k, 65516/down-arrow 1198 ¦ break-unless move-to-next-line? 1199 ¦ <move-cursor-begin> -1200 ¦ go-render? <- move-to-next-line editor, screen-height +1200 ¦ go-render? <- move-to-next-line editor, screen-height 1201 ¦ undo-coalesce-tag:num <- copy 4/down-arrow 1202 ¦ <move-cursor-end> 1203 ¦ return 1204 } 1205 ] 1206 -1207 def move-to-next-line editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ +1207 def move-to-next-line editor:&:editor, screen-height:num -> go-render?:bool, editor:&:editor [ 1208 local-scope 1209 load-ingredients 1210 cursor-row:num <- get *editor, cursor-row:offset @@ -1274,7 +1274,7 @@ if ('onhashchange' in window) { 1212 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset 1213 left:num <- get *editor, left:offset 1214 right:num <- get *editor, right:offset -1215 last-line:num <- subtract screen-height, 1 +1215 last-line:num <- subtract screen-height, 1 1216 already-at-bottom?:bool <- greater-or-equal cursor-row, last-line 1217 { 1218 ¦ # if cursor not at bottom, move it @@ -1325,7 +1325,7 @@ if ('onhashchange' in window) { 1263 assume-screen 10/width, 5/height 1264 s:text <- new [abc 1265 de] -1266 e:&:editor <- new-editor s, 0/left, 10/right +1266 e:&:editor <- new-editor s, 0/left, 10/right 1267 editor-render screen, e 1268 $clear-trace 1269 assume-console [ @@ -1364,7 +1364,7 @@ if ('onhashchange' in window) { 1302 assume-screen 10/width, 5/height 1303 s:text <- new [123 1304 456] -1305 e:&:editor <- new-editor s, 0/left, 10/right +1305 e:&:editor <- new-editor s, 0/left, 10/right 1306 editor-render screen, e 1307 $clear-trace 1308 # start on second line, press ctrl-a @@ -1438,7 +1438,7 @@ if ('onhashchange' in window) { 1376 assume-screen 10/width, 5/height 1377 s:text <- new [123 1378 456] -1379 e:&:editor <- new-editor s, 0/left, 10/right +1379 e:&:editor <- new-editor s, 0/left, 10/right 1380 editor-render screen, e 1381 $clear-trace 1382 # start on first line (no newline before), press ctrl-a @@ -1464,7 +1464,7 @@ if ('onhashchange' in window) { 1402 assume-screen 10/width, 5/height 1403 s:text <- new [123 1404 456] -1405 e:&:editor <- new-editor s, 0/left, 10/right +1405 e:&:editor <- new-editor s, 0/left, 10/right 1406 $clear-trace 1407 # start on second line, press 'home' 1408 assume-console [ @@ -1489,7 +1489,7 @@ if ('onhashchange' in window) { 1427 assume-screen 10/width, 5/height 1428 s:text <- new [123 1429 456] -1430 e:&:editor <- new-editor s, 0/left, 10/right +1430 e:&:editor <- new-editor s, 0/left, 10/right 1431 editor-render screen, e 1432 $clear-trace 1433 # start on first line (no newline before), press 'home' @@ -1517,7 +1517,7 @@ if ('onhashchange' in window) { 1455 assume-screen 10/width, 5/height 1456 s:text <- new [123 1457 456] -1458 e:&:editor <- new-editor s, 0/left, 10/right +1458 e:&:editor <- new-editor s, 0/left, 10/right 1459 editor-render screen, e 1460 $clear-trace 1461 # start on first line, press ctrl-e @@ -1608,7 +1608,7 @@ if ('onhashchange' in window) { 1546 assume-screen 10/width, 5/height 1547 s:text <- new [123 1548 456] -1549 e:&:editor <- new-editor s, 0/left, 10/right +1549 e:&:editor <- new-editor s, 0/left, 10/right 1550 editor-render screen, e 1551 $clear-trace 1552 # start on second line (no newline after), press ctrl-e @@ -1634,7 +1634,7 @@ if ('onhashchange' in window) { 1572 assume-screen 10/width, 5/height 1573 s:text <- new [123 1574 456] -1575 e:&:editor <- new-editor s, 0/left, 10/right +1575 e:&:editor <- new-editor s, 0/left, 10/right 1576 editor-render screen, e 1577 $clear-trace 1578 # start on first line, press 'end' @@ -1660,7 +1660,7 @@ if ('onhashchange' in window) { 1598 assume-screen 10/width, 5/height 1599 s:text <- new [123 1600 456] -1601 e:&:editor <- new-editor s, 0/left, 10/right +1601 e:&:editor <- new-editor s, 0/left, 10/right 1602 editor-render screen, e 1603 $clear-trace 1604 # start on second line (no newline after), press 'end' @@ -1688,7 +1688,7 @@ if ('onhashchange' in window) { 1626 assume-screen 10/width, 5/height 1627 s:text <- new [123 1628 456] -1629 e:&:editor <- new-editor s, 0/left, 10/right +1629 e:&:editor <- new-editor s, 0/left, 10/right 1630 # start on second line, press ctrl-u 1631 assume-console [ 1632 ¦ left-click 2, 2 @@ -1751,7 +1751,7 @@ if ('onhashchange' in window) { 1689 assume-screen 10/width, 5/height 1690 s:text <- new [123 1691 456] -1692 e:&:editor <- new-editor s, 0/left, 10/right +1692 e:&:editor <- new-editor s, 0/left, 10/right 1693 # start on first line (no newline before), press ctrl-u 1694 assume-console [ 1695 ¦ left-click 1, 2 @@ -1775,7 +1775,7 @@ if ('onhashchange' in window) { 1713 assume-screen 10/width, 5/height 1714 s:text <- new [123 1715 456] -1716 e:&:editor <- new-editor s, 0/left, 10/right +1716 e:&:editor <- new-editor s, 0/left, 10/right 1717 # start past end of line, press ctrl-u 1718 assume-console [ 1719 ¦ left-click 1, 3 @@ -1799,7 +1799,7 @@ if ('onhashchange' in window) { 1737 assume-screen 10/width, 5/height 1738 s:text <- new [123 1739 456] -1740 e:&:editor <- new-editor s, 0/left, 10/right +1740 e:&:editor <- new-editor s, 0/left, 10/right 1741 # start past end of final line, press ctrl-u 1742 assume-console [ 1743 ¦ left-click 2, 3 @@ -1825,7 +1825,7 @@ if ('onhashchange' in window) { 1763 assume-screen 10/width, 5/height 1764 s:text <- new [123 1765 456] -1766 e:&:editor <- new-editor s, 0/left, 10/right +1766 e:&:editor <- new-editor s, 0/left, 10/right 1767 # start on first line, press ctrl-k 1768 assume-console [ 1769 ¦ left-click 1, 1 @@ -1880,7 +1880,7 @@ if ('onhashchange' in window) { 1818 assume-screen 10/width, 5/height 1819 s:text <- new [123 1820 456] -1821 e:&:editor <- new-editor s, 0/left, 10/right +1821 e:&:editor <- new-editor s, 0/left, 10/right 1822 # start on second line (no newline after), press ctrl-k 1823 assume-console [ 1824 ¦ left-click 2, 1 @@ -1904,7 +1904,7 @@ if ('onhashchange' in window) { 1842 assume-screen 10/width, 5/height 1843 s:text <- new [123 1844 456] -1845 e:&:editor <- new-editor s, 0/left, 10/right +1845 e:&:editor <- new-editor s, 0/left, 10/right 1846 # start at end of line 1847 assume-console [ 1848 ¦ left-click 1, 2 @@ -1928,7 +1928,7 @@ if ('onhashchange' in window) { 1866 assume-screen 10/width, 5/height 1867 s:text <- new [123 1868 456] -1869 e:&:editor <- new-editor s, 0/left, 10/right +1869 e:&:editor <- new-editor s, 0/left, 10/right 1870 # start past end of line 1871 assume-console [ 1872 ¦ left-click 1, 3 @@ -1952,7 +1952,7 @@ if ('onhashchange' in window) { 1890 assume-screen 10/width, 5/height 1891 s:text <- new [123 1892 456] -1893 e:&:editor <- new-editor s, 0/left, 10/right +1893 e:&:editor <- new-editor s, 0/left, 10/right 1894 # start at end of text 1895 assume-console [ 1896 ¦ left-click 2, 2 @@ -1976,7 +1976,7 @@ if ('onhashchange' in window) { 1914 assume-screen 10/width, 5/height 1915 s:text <- new [123 1916 456] -1917 e:&:editor <- new-editor s, 0/left, 10/right +1917 e:&:editor <- new-editor s, 0/left, 10/right 1918 # start past end of text 1919 assume-console [ 1920 ¦ left-click 2, 3 @@ -2006,7 +2006,7 @@ if ('onhashchange' in window) { 1944 b 1945 c 1946 d] -1947 e:&:editor <- new-editor s, 0/left, 10/right +1947 e:&:editor <- new-editor s, 0/left, 10/right 1948 editor-render screen, e 1949 screen-should-contain [ 1950 ¦ . . @@ -2085,7 +2085,7 @@ if ('onhashchange' in window) { 2023 g 2024 h 2025 i] -2026 e:&:editor <- new-editor s, 0/left, 5/right +2026 e:&:editor <- new-editor s, 0/left, 5/right 2027 editor-render screen, e 2028 screen-should-contain [ 2029 ¦ . . @@ -2119,7 +2119,7 @@ if ('onhashchange' in window) { 2057 k 2058 l 2059 m] -2060 e:&:editor <- new-editor s, 0/left, 5/right +2060 e:&:editor <- new-editor s, 0/left, 5/right 2061 # position cursor at last line, then try to move further down 2062 assume-console [ 2063 ¦ left-click 3, 0 @@ -2159,7 +2159,7 @@ if ('onhashchange' in window) { 2097 s:text <- new [a 2098 b 2099 cdef] -2100 e:&:editor <- new-editor s, 0/left, 5/right +2100 e:&:editor <- new-editor s, 0/left, 5/right 2101 # position cursor at end, type a character 2102 assume-console [ 2103 ¦ left-click 3, 4 @@ -2190,7 +2190,7 @@ if ('onhashchange' in window) { 2128 s:text <- new [a 2129 b 2130 c] -2131 e:&:editor <- new-editor s, 0/left, 5/right +2131 e:&:editor <- new-editor s, 0/left, 5/right 2132 assume-console [ 2133 ¦ left-click 3, 4 2134 ¦ type [ @@ -2222,7 +2222,7 @@ if ('onhashchange' in window) { 2160 s:text <- new [a 2161 b 2162 cdefgh] -2163 e:&:editor <- new-editor s, 0/left, 5/right +2163 e:&:editor <- new-editor s, 0/left, 5/right 2164 # position cursor at end of screen and try to move right 2165 assume-console [ 2166 ¦ left-click 3, 3 @@ -2255,7 +2255,7 @@ if ('onhashchange' in window) { 2193 b 2194 c 2195 d] -2196 e:&:editor <- new-editor s, 0/left, 5/right +2196 e:&:editor <- new-editor s, 0/left, 5/right 2197 # position cursor at end of screen and try to move right 2198 assume-console [ 2199 ¦ left-click 3, 3 @@ -2284,7 +2284,7 @@ if ('onhashchange' in window) { 2222 assume-screen 10/width, 5/height 2223 s:text <- new [abc 2224 de] -2225 e:&:editor <- new-editor s, 0/left, 10/right +2225 e:&:editor <- new-editor s, 0/left, 10/right 2226 editor-render screen, e 2227 $clear-trace 2228 # try to move down past end of text @@ -2357,7 +2357,7 @@ if ('onhashchange' in window) { 2295 e 2296 f 2297 g] -2298 e:&:editor <- new-editor s, 0/left, 5/right +2298 e:&:editor <- new-editor s, 0/left, 5/right 2299 editor-render screen, e 2300 # scroll down one page and one line 2301 assume-console [ @@ -2388,7 +2388,7 @@ if ('onhashchange' in window) { 2326 b 2327 c 2328 d] -2329 e:&:editor <- new-editor s, 0/left, 10/right +2329 e:&:editor <- new-editor s, 0/left, 10/right 2330 editor-render screen, e 2331 screen-should-contain [ 2332 ¦ . . @@ -2477,7 +2477,7 @@ if ('onhashchange' in window) { 2415 g 2416 h 2417 i] -2418 e:&:editor <- new-editor s, 0/left, 5/right +2418 e:&:editor <- new-editor s, 0/left, 5/right 2419 editor-render screen, e 2420 screen-should-contain [ 2421 ¦ . . @@ -2523,7 +2523,7 @@ if ('onhashchange' in window) { 2461 k 2462 l 2463 m] -2464 e:&:editor <- new-editor s, 0/left, 5/right +2464 e:&:editor <- new-editor s, 0/left, 5/right 2465 editor-render screen, e 2466 # position cursor at top of second page 2467 assume-console [ @@ -2598,7 +2598,7 @@ if ('onhashchange' in window) { 2536 g 2537 h 2538 i] -2539 e:&:editor <- new-editor s, 0/left, 6/right +2539 e:&:editor <- new-editor s, 0/left, 6/right 2540 editor-render screen, e 2541 screen-should-contain [ 2542 ¦ . . @@ -2646,7 +2646,7 @@ if ('onhashchange' in window) { 2584 c 2585 d 2586 e] -2587 e:&:editor <- new-editor s, 0/left, 6/right +2587 e:&:editor <- new-editor s, 0/left, 6/right 2588 editor-render screen, e 2589 assume-console [ 2590 ¦ press page-down @@ -2696,7 +2696,7 @@ if ('onhashchange' in window) { 2634 c 2635 d 2636 e] -2637 e:&:editor <- new-editor s, 0/left, 5/right +2637 e:&:editor <- new-editor s, 0/left, 5/right 2638 editor-render screen, e 2639 # position cursor at top of second page 2640 assume-console [ @@ -2742,7 +2742,7 @@ if ('onhashchange' in window) { 2680 b 2681 c 2682 d] -2683 e:&:editor <- new-editor s, 0/left, 10/right +2683 e:&:editor <- new-editor s, 0/left, 10/right 2684 editor-render screen, e 2685 screen-should-contain [ 2686 ¦ . . @@ -2792,7 +2792,7 @@ if ('onhashchange' in window) { 2730 b 2731 c 2732 d] -2733 e:&:editor <- new-editor s, 0/left, 10/right +2733 e:&:editor <- new-editor s, 0/left, 10/right 2734 editor-render screen, e 2735 screen-should-contain [ 2736 ¦ . . @@ -2877,7 +2877,7 @@ if ('onhashchange' in window) { 2815 assume-screen 10/width, 4/height 2816 s:text <- new [a 2817 b] -2818 e:&:editor <- new-editor s, 0/left, 10/right +2818 e:&:editor <- new-editor s, 0/left, 10/right 2819 editor-render screen, e 2820 screen-should-contain [ 2821 ¦ . . @@ -2910,7 +2910,7 @@ if ('onhashchange' in window) { 2848 b 2849 cdefgh] 2850 # editor screen triggers wrap of last line -2851 e:&:editor <- new-editor s, 0/left, 4/right +2851 e:&:editor <- new-editor s, 0/left, 4/right 2852 editor-render screen, e 2853 # some part of last line is not displayed 2854 screen-should-contain [ @@ -2943,7 +2943,7 @@ if ('onhashchange' in window) { 2881 # and still has something left over 2882 s:text <- new [a 2883 bcdefgh] -2884 e:&:editor <- new-editor s, 0/left, 4/right +2884 e:&:editor <- new-editor s, 0/left, 4/right 2885 editor-render screen, e 2886 # some part of last line is not displayed 2887 screen-should-contain [ @@ -2977,7 +2977,7 @@ if ('onhashchange' in window) { 2915 b 2916 c 2917 d] -2918 e:&:editor <- new-editor s, 0/left, 10/right +2918 e:&:editor <- new-editor s, 0/left, 10/right 2919 editor-render screen, e 2920 screen-should-contain [ 2921 ¦ . . @@ -3021,7 +3021,7 @@ if ('onhashchange' in window) { 2959 ¦ break-unless page-up? 2960 ¦ old-top:&:duplex-list:char <- get *editor, top-of-screen:offset 2961 ¦ <move-cursor-begin> -2962 ¦ editor <- page-up editor, screen-height +2962 ¦ editor <- page-up editor, screen-height 2963 ¦ undo-coalesce-tag:num <- copy 0/never 2964 ¦ <move-cursor-end> 2965 ¦ top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset @@ -3036,7 +3036,7 @@ if ('onhashchange' in window) { 2974 ¦ break-unless page-up? 2975 ¦ old-top:&:duplex-list:char <- get *editor, top-of-screen:offset 2976 ¦ <move-cursor-begin> -2977 ¦ editor <- page-up editor, screen-height +2977 ¦ editor <- page-up editor, screen-height 2978 ¦ undo-coalesce-tag:num <- copy 0/never 2979 ¦ <move-cursor-end> 2980 ¦ top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset @@ -3046,10 +3046,10 @@ if ('onhashchange' in window) { 2984 } 2985 ] 2986 -2987 def page-up editor:&:editor, screen-height:num -> editor:&:editor [ +2987 def page-up editor:&:editor, screen-height:num -> editor:&:editor [ 2988 local-scope 2989 load-ingredients -2990 max:num <- subtract screen-height, 1/menu-bar, 1/overlapping-line +2990 max:num <- subtract screen-height, 1/menu-bar, 1/overlapping-line 2991 count:num <- copy 0 2992 top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset 2993 { @@ -3077,7 +3077,7 @@ if ('onhashchange' in window) { 3015 f 3016 g 3017 h] -3018 e:&:editor <- new-editor s, 0/left, 10/right +3018 e:&:editor <- new-editor s, 0/left, 10/right 3019 editor-render screen, e 3020 screen-should-contain [ 3021 ¦ . . @@ -3146,7 +3146,7 @@ if ('onhashchange' in window) { 3084 n 3085 o] 3086 # editor screen triggers wrap of last line -3087 e:&:editor <- new-editor s, 0/left, 4/right +3087 e:&:editor <- new-editor s, 0/left, 4/right 3088 editor-render screen, e 3089 # some part of last line is not displayed 3090 screen-should-contain [ @@ -3201,7 +3201,7 @@ if ('onhashchange' in window) { 3139 # and still has something left over 3140 s:text <- new [a 3141 bcdefgh] -3142 e:&:editor <- new-editor s, 0/left, 4/right +3142 e:&:editor <- new-editor s, 0/left, 4/right 3143 editor-render screen, e 3144 # some part of last line is not displayed 3145 screen-should-contain [ @@ -3253,7 +3253,7 @@ if ('onhashchange' in window) { 3191 gxx 3192 hxx 3193 ] -3194 e:&:editor <- new-editor s, 0/left, 4/right +3194 e:&:editor <- new-editor s, 0/left, 4/right 3195 editor-render screen, e 3196 screen-should-contain [ 3197 ¦ . . @@ -3313,7 +3313,7 @@ if ('onhashchange' in window) { 3251 fxy 3252 gxy 3253 ] -3254 e:&:editor <- new-editor s, 0/left, 4/right +3254 e:&:editor <- new-editor s, 0/left, 4/right 3255 editor-render screen, e 3256 screen-should-contain [ 3257 ¦ . . diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index bc4394cd..87f2586b 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -70,7 +70,7 @@ if ('onhashchange' in window) { 7 local-scope 8 open-console 9 env:&:environment <- new-programming-environment 0/filesystem, 0/screen - 10 render-all 0/screen, env, render + 10 render-all 0/screen, env, render 11 event-loop 0/screen, 0/console, env, 0/filesystem 12 # never gets here 13 ] @@ -84,15 +84,15 @@ if ('onhashchange' in window) { 21 def new-programming-environment resources:&:resources, screen:&:screen, test-sandbox-editor-contents:text -> result:&:environment [ 22 local-scope 23 load-ingredients - 24 width:num <- screen-width screen + 24 width:num <- screen-width screen 25 result <- new environment:type 26 # recipe editor on the left 27 initial-recipe-contents:text <- slurp resources, [lesson/recipes.mu] # ignore errors 28 divider:num, _ <- divide-with-remainder width, 2 - 29 recipes:&:editor <- new-editor initial-recipe-contents, 0/left, divider/right + 29 recipes:&:editor <- new-editor initial-recipe-contents, 0/left, divider/right 30 # sandbox editor on the right 31 sandbox-left:num <- add divider, 1 - 32 current-sandbox:&:editor <- new-editor test-sandbox-editor-contents, sandbox-left, width/right + 32 current-sandbox:&:editor <- new-editor test-sandbox-editor-contents, sandbox-left, width/right 33 *result <- put *result, recipes:offset, recipes 34 *result <- put *result, current-sandbox:offset, current-sandbox 35 *result <- put *result, sandbox-in-focus?:offset, 0/false @@ -105,464 +105,490 @@ if ('onhashchange' in window) { 42 recipes:&:editor <- get *env, recipes:offset 43 current-sandbox:&:editor <- get *env, current-sandbox:offset 44 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset - 45 { - 46 ¦ # looping over each (keyboard or touch) event as it occurs - 47 ¦ +next-event - 48 ¦ e:event, found?:bool, quit?:bool, console <- read-event console - 49 ¦ loop-unless found? - 50 ¦ break-if quit? # only in tests - 51 ¦ trace 10, [app], [next-event] - 52 ¦ <handle-event> - 53 ¦ # check for global events that will trigger regardless of which editor has focus - 54 ¦ { - 55 ¦ ¦ k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant - 56 ¦ ¦ break-unless is-keycode? - 57 ¦ ¦ <global-keypress> - 58 ¦ } - 59 ¦ { - 60 ¦ ¦ c:char, is-unicode?:bool <- maybe-convert e:event, text:variant - 61 ¦ ¦ break-unless is-unicode? - 62 ¦ ¦ <global-type> - 63 ¦ } - 64 ¦ # 'touch' event - send to both sides, see what picks it up - 65 ¦ { - 66 ¦ ¦ t:touch-event, is-touch?:bool <- maybe-convert e:event, touch:variant - 67 ¦ ¦ break-unless is-touch? - 68 ¦ ¦ # ignore all but 'left-click' events for now - 69 ¦ ¦ # todo: test this - 70 ¦ ¦ touch-type:num <- get t, type:offset - 71 ¦ ¦ is-left-click?:bool <- equal touch-type, 65513/mouse-left - 72 ¦ ¦ loop-unless is-left-click?, +next-event - 73 ¦ ¦ click-row:num <- get t, row:offset - 74 ¦ ¦ click-column:num <- get t, column:offset - 75 ¦ ¦ # later exceptions for non-editor touches will go here - 76 ¦ ¦ <global-touch> - 77 ¦ ¦ # send to both editors - 78 ¦ ¦ _ <- move-cursor-in-editor screen, recipes, t - 79 ¦ ¦ sandbox-in-focus?:bool <- move-cursor-in-editor screen, current-sandbox, t - 80 ¦ ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? - 81 ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env - 82 ¦ ¦ loop +next-event - 83 ¦ } - 84 ¦ # 'resize' event - redraw editor - 85 ¦ # todo: test this after supporting resize in assume-console - 86 ¦ { - 87 ¦ ¦ r:resize-event, is-resize?:bool <- maybe-convert e:event, resize:variant - 88 ¦ ¦ break-unless is-resize? - 89 ¦ ¦ env, screen <- resize screen, env - 90 ¦ ¦ screen <- render-all screen, env, render-without-moving-cursor - 91 ¦ ¦ loop +next-event - 92 ¦ } - 93 ¦ # if it's not global and not a touch event, send to appropriate editor - 94 ¦ { - 95 ¦ ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset - 96 ¦ ¦ { - 97 ¦ ¦ ¦ break-if sandbox-in-focus? - 98 ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, recipes, e:event - 99 ¦ ¦ ¦ break-unless render? -100 ¦ ¦ ¦ screen <- render-all screen, env, render -101 ¦ ¦ } -102 ¦ ¦ { -103 ¦ ¦ ¦ break-unless sandbox-in-focus? -104 ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, current-sandbox, e:event -105 ¦ ¦ ¦ break-unless render? -106 ¦ ¦ ¦ screen <- render-sandbox-side screen, env, render -107 ¦ ¦ } -108 ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -109 ¦ } -110 ¦ loop -111 } -112 ] -113 -114 def resize screen:&:screen, env:&:environment -> env:&:environment, screen:&:screen [ -115 local-scope -116 load-ingredients -117 clear-screen screen # update screen dimensions -118 width:num <- screen-width screen -119 divider:num, _ <- divide-with-remainder width, 2 -120 # update recipe editor -121 recipes:&:editor <- get *env, recipes:offset -122 right:num <- subtract divider, 1 -123 *recipes <- put *recipes, right:offset, right -124 # reset cursor (later we'll try to preserve its position) -125 *recipes <- put *recipes, cursor-row:offset, 1 -126 *recipes <- put *recipes, cursor-column:offset, 0 -127 # update sandbox editor -128 current-sandbox:&:editor <- get *env, current-sandbox:offset -129 left:num <- add divider, 1 -130 *current-sandbox <- put *current-sandbox, left:offset, left -131 right:num <- subtract width, 1 -132 *current-sandbox <- put *current-sandbox, right:offset, right -133 # reset cursor (later we'll try to preserve its position) -134 *current-sandbox <- put *current-sandbox, cursor-row:offset, 1 -135 *current-sandbox <- put *current-sandbox, cursor-column:offset, left -136 ] -137 -138 # Variant of 'render' that updates cursor-row and cursor-column based on -139 # before-cursor (rather than the other way around). If before-cursor moves -140 # off-screen, it resets cursor-row and cursor-column. -141 def render-without-moving-cursor screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ -142 local-scope -143 load-ingredients -144 return-unless editor, 1/top, 0/left -145 left:num <- get *editor, left:offset -146 screen-height:num <- screen-height screen -147 right:num <- get *editor, right:offset -148 curr:&:duplex-list:char <- get *editor, top-of-screen:offset -149 prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev -150 curr <- next curr -151 color:num <- copy 7/white -152 row:num <- copy 1/top -153 column:num <- copy left -154 # save before-cursor -155 old-before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset -156 # initialze cursor-row/cursor-column/before-cursor to the top of the screen -157 # by default -158 *editor <- put *editor, cursor-row:offset, row -159 *editor <- put *editor, cursor-column:offset, column -160 top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset -161 *editor <- put *editor, before-cursor:offset, top-of-screen -162 screen <- move-cursor screen, row, column -163 { -164 ¦ +next-character -165 ¦ break-unless curr -166 ¦ off-screen?:bool <- greater-or-equal row, screen-height -167 ¦ break-if off-screen? -168 ¦ # if we find old-before-cursor still on the new resized screen, update -169 ¦ # editor.cursor-row and editor.cursor-column based on -170 ¦ # old-before-cursor -171 ¦ { -172 ¦ ¦ at-cursor?:bool <- equal old-before-cursor, prev -173 ¦ ¦ break-unless at-cursor? -174 ¦ ¦ *editor <- put *editor, cursor-row:offset, row -175 ¦ ¦ *editor <- put *editor, cursor-column:offset, column -176 ¦ ¦ *editor <- put *editor, before-cursor:offset, old-before-cursor -177 ¦ } -178 ¦ c:char <- get *curr, value:offset -179 ¦ <character-c-received> -180 ¦ { -181 ¦ ¦ # newline? move to left rather than 0 -182 ¦ ¦ newline?:bool <- equal c, 10/newline -183 ¦ ¦ break-unless newline? -184 ¦ ¦ # clear rest of line in this window -185 ¦ ¦ clear-line-until screen, right -186 ¦ ¦ # skip to next line -187 ¦ ¦ row <- add row, 1 -188 ¦ ¦ column <- copy left -189 ¦ ¦ screen <- move-cursor screen, row, column -190 ¦ ¦ curr <- next curr -191 ¦ ¦ prev <- next prev -192 ¦ ¦ loop +next-character -193 ¦ } -194 ¦ { -195 ¦ ¦ # at right? wrap. even if there's only one more letter left; we need -196 ¦ ¦ # room for clicking on the cursor after it. -197 ¦ ¦ at-right?:bool <- equal column, right -198 ¦ ¦ break-unless at-right? -199 ¦ ¦ # print wrap icon -200 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left -201 ¦ ¦ print screen, wrap-icon, 245/grey -202 ¦ ¦ column <- copy left -203 ¦ ¦ row <- add row, 1 -204 ¦ ¦ screen <- move-cursor screen, row, column -205 ¦ ¦ # don't increment curr -206 ¦ ¦ loop +next-character -207 ¦ } -208 ¦ print screen, c, color -209 ¦ curr <- next curr -210 ¦ prev <- next prev -211 ¦ column <- add column, 1 -212 ¦ loop -213 } -214 # save first character off-screen -215 *editor <- put *editor, bottom-of-screen:offset, curr -216 *editor <- put *editor, bottom:offset, row -217 return row, column -218 ] -219 -220 scenario point-at-multiple-editors [ -221 local-scope -222 trace-until 100/app # trace too long -223 assume-screen 30/width, 5/height -224 # initialize both halves of screen -225 assume-resources [ -226 ¦ [lesson/recipes.mu] <- [ -227 ¦ ¦ |abc| -228 ¦ ] -229 ] -230 env:&:environment <- new-programming-environment resources, screen, [def] # contents of sandbox editor -231 # focus on both sides -232 assume-console [ -233 ¦ left-click 1, 1 -234 ¦ left-click 1, 17 -235 ] -236 # check cursor column in each -237 run [ -238 ¦ event-loop screen, console, env, resources -239 ¦ recipes:&:editor <- get *env, recipes:offset -240 ¦ 5:num/raw <- get *recipes, cursor-column:offset -241 ¦ sandbox:&:editor <- get *env, current-sandbox:offset -242 ¦ 7:num/raw <- get *sandbox, cursor-column:offset -243 ] -244 memory-should-contain [ -245 ¦ 5 <- 1 -246 ¦ 7 <- 17 -247 ] -248 ] -249 -250 scenario edit-multiple-editors [ -251 local-scope -252 trace-until 100/app # trace too long -253 assume-screen 30/width, 5/height -254 # initialize both halves of screen -255 assume-resources [ -256 ¦ [lesson/recipes.mu] <- [ -257 ¦ ¦ |abc| -258 ¦ ] -259 ] -260 env:&:environment <- new-programming-environment resources, screen, [def] # contents of sandbox -261 render-all screen, env, render -262 # type one letter in each of them -263 assume-console [ -264 ¦ left-click 1, 1 -265 ¦ type [0] -266 ¦ left-click 1, 17 -267 ¦ type [1] -268 ] -269 run [ -270 ¦ event-loop screen, console, env, resources -271 ¦ recipes:&:editor <- get *env, recipes:offset -272 ¦ 5:num/raw <- get *recipes, cursor-column:offset -273 ¦ sandbox:&:editor <- get *env, current-sandbox:offset -274 ¦ 7:num/raw <- get *sandbox, cursor-column:offset -275 ] -276 screen-should-contain [ -277 ¦ . run (F4) . # this line has a different background, but we don't test that yet -278 ¦ .a0bc ╎d1ef . -279 ¦ . ╎──────────────. -280 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . -281 ¦ . ╎ . -282 ] -283 memory-should-contain [ -284 ¦ 5 <- 2 # cursor column of recipe editor -285 ¦ 7 <- 18 # cursor column of sandbox editor + 45 # if we fall behind we'll stop updating the screen, but then we have to + 46 # render the entire screen when we catch up. + 47 # todo: test this + 48 render-all-on-no-more-events?:bool <- copy 0/false + 49 { + 50 ¦ # looping over each (keyboard or touch) event as it occurs + 51 ¦ +next-event + 52 ¦ e:event, found?:bool, quit?:bool, console <- read-event console + 53 ¦ loop-unless found? + 54 ¦ break-if quit? # only in tests + 55 ¦ trace 10, [app], [next-event] + 56 ¦ <handle-event> + 57 ¦ # check for global events that will trigger regardless of which editor has focus + 58 ¦ { + 59 ¦ ¦ k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant + 60 ¦ ¦ break-unless is-keycode? + 61 ¦ ¦ <global-keypress> + 62 ¦ } + 63 ¦ { + 64 ¦ ¦ c:char, is-unicode?:bool <- maybe-convert e:event, text:variant + 65 ¦ ¦ break-unless is-unicode? + 66 ¦ ¦ <global-type> + 67 ¦ } + 68 ¦ # 'touch' event - send to both sides, see what picks it up + 69 ¦ { + 70 ¦ ¦ t:touch-event, is-touch?:bool <- maybe-convert e:event, touch:variant + 71 ¦ ¦ break-unless is-touch? + 72 ¦ ¦ # ignore all but 'left-click' events for now + 73 ¦ ¦ # todo: test this + 74 ¦ ¦ touch-type:num <- get t, type:offset + 75 ¦ ¦ is-left-click?:bool <- equal touch-type, 65513/mouse-left + 76 ¦ ¦ loop-unless is-left-click?, +next-event + 77 ¦ ¦ click-row:num <- get t, row:offset + 78 ¦ ¦ click-column:num <- get t, column:offset + 79 ¦ ¦ # later exceptions for non-editor touches will go here + 80 ¦ ¦ <global-touch> + 81 ¦ ¦ # send to both editors + 82 ¦ ¦ _ <- move-cursor-in-editor screen, recipes, t + 83 ¦ ¦ sandbox-in-focus?:bool <- move-cursor-in-editor screen, current-sandbox, t + 84 ¦ ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? + 85 ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + 86 ¦ ¦ loop +next-event + 87 ¦ } + 88 ¦ # 'resize' event - redraw editor + 89 ¦ # todo: test this after supporting resize in assume-console + 90 ¦ { + 91 ¦ ¦ r:resize-event, is-resize?:bool <- maybe-convert e:event, resize:variant + 92 ¦ ¦ break-unless is-resize? + 93 ¦ ¦ env, screen <- resize screen, env + 94 ¦ ¦ screen <- render-all screen, env, render-without-moving-cursor + 95 ¦ ¦ loop +next-event + 96 ¦ } + 97 ¦ # if it's not global and not a touch event, send to appropriate editor + 98 ¦ { + 99 ¦ ¦ hide-screen screen +100 ¦ ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset +101 ¦ ¦ { +102 ¦ ¦ ¦ break-if sandbox-in-focus? +103 ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, recipes, e:event +104 ¦ ¦ } +105 ¦ ¦ { +106 ¦ ¦ ¦ break-unless sandbox-in-focus? +107 ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, current-sandbox, e:event +108 ¦ ¦ } +109 ¦ ¦ # try to batch up rendering if there are more events queued up +110 ¦ ¦ # to compensate for this additional code complexity, we always render both sides when we do render +111 ¦ ¦ render-all-on-no-more-events? <- or render-all-on-no-more-events?, render? +112 ¦ ¦ more-events?:bool <- has-more-events? console +113 ¦ ¦ { +114 ¦ ¦ ¦ break-if more-events? +115 ¦ ¦ ¦ break-unless render-all-on-no-more-events? +116 ¦ ¦ ¦ screen <- render-all screen, env, render +117 ¦ ¦ } +118 ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +119 ¦ ¦ show-screen screen +120 ¦ } +121 ¦ loop +122 } +123 ] +124 +125 def resize screen:&:screen, env:&:environment -> env:&:environment, screen:&:screen [ +126 local-scope +127 load-ingredients +128 clear-screen screen # update screen dimensions +129 width:num <- screen-width screen +130 divider:num, _ <- divide-with-remainder width, 2 +131 # update recipe editor +132 recipes:&:editor <- get *env, recipes:offset +133 right:num <- subtract divider, 1 +134 *recipes <- put *recipes, right:offset, right +135 # reset cursor (later we'll try to preserve its position) +136 *recipes <- put *recipes, cursor-row:offset, 1 +137 *recipes <- put *recipes, cursor-column:offset, 0 +138 # update sandbox editor +139 current-sandbox:&:editor <- get *env, current-sandbox:offset +140 left:num <- add divider, 1 +141 *current-sandbox <- put *current-sandbox, left:offset, left +142 right:num <- subtract width, 1 +143 *current-sandbox <- put *current-sandbox, right:offset, right +144 # reset cursor (later we'll try to preserve its position) +145 *current-sandbox <- put *current-sandbox, cursor-row:offset, 1 +146 *current-sandbox <- put *current-sandbox, cursor-column:offset, left +147 ] +148 +149 # Variant of 'render' that updates cursor-row and cursor-column based on +150 # before-cursor (rather than the other way around). If before-cursor moves +151 # off-screen, it resets cursor-row and cursor-column. +152 def render-without-moving-cursor screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ +153 local-scope +154 load-ingredients +155 return-unless editor, 1/top, 0/left +156 left:num <- get *editor, left:offset +157 screen-height:num <- screen-height screen +158 right:num <- get *editor, right:offset +159 curr:&:duplex-list:char <- get *editor, top-of-screen:offset +160 prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev +161 curr <- next curr +162 color:num <- copy 7/white +163 row:num <- copy 1/top +164 column:num <- copy left +165 # save before-cursor +166 old-before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset +167 # initialze cursor-row/cursor-column/before-cursor to the top of the screen +168 # by default +169 *editor <- put *editor, cursor-row:offset, row +170 *editor <- put *editor, cursor-column:offset, column +171 top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset +172 *editor <- put *editor, before-cursor:offset, top-of-screen +173 screen <- move-cursor screen, row, column +174 { +175 ¦ +next-character +176 ¦ break-unless curr +177 ¦ off-screen?:bool <- greater-or-equal row, screen-height +178 ¦ break-if off-screen? +179 ¦ # if we find old-before-cursor still on the new resized screen, update +180 ¦ # editor.cursor-row and editor.cursor-column based on +181 ¦ # old-before-cursor +182 ¦ { +183 ¦ ¦ at-cursor?:bool <- equal old-before-cursor, prev +184 ¦ ¦ break-unless at-cursor? +185 ¦ ¦ *editor <- put *editor, cursor-row:offset, row +186 ¦ ¦ *editor <- put *editor, cursor-column:offset, column +187 ¦ ¦ *editor <- put *editor, before-cursor:offset, old-before-cursor +188 ¦ } +189 ¦ c:char <- get *curr, value:offset +190 ¦ <character-c-received> +191 ¦ { +192 ¦ ¦ # newline? move to left rather than 0 +193 ¦ ¦ newline?:bool <- equal c, 10/newline +194 ¦ ¦ break-unless newline? +195 ¦ ¦ # clear rest of line in this window +196 ¦ ¦ clear-line-until screen, right +197 ¦ ¦ # skip to next line +198 ¦ ¦ row <- add row, 1 +199 ¦ ¦ column <- copy left +200 ¦ ¦ screen <- move-cursor screen, row, column +201 ¦ ¦ curr <- next curr +202 ¦ ¦ prev <- next prev +203 ¦ ¦ loop +next-character +204 ¦ } +205 ¦ { +206 ¦ ¦ # at right? wrap. even if there's only one more letter left; we need +207 ¦ ¦ # room for clicking on the cursor after it. +208 ¦ ¦ at-right?:bool <- equal column, right +209 ¦ ¦ break-unless at-right? +210 ¦ ¦ # print wrap icon +211 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left +212 ¦ ¦ print screen, wrap-icon, 245/grey +213 ¦ ¦ column <- copy left +214 ¦ ¦ row <- add row, 1 +215 ¦ ¦ screen <- move-cursor screen, row, column +216 ¦ ¦ # don't increment curr +217 ¦ ¦ loop +next-character +218 ¦ } +219 ¦ print screen, c, color +220 ¦ curr <- next curr +221 ¦ prev <- next prev +222 ¦ column <- add column, 1 +223 ¦ loop +224 } +225 # save first character off-screen +226 *editor <- put *editor, bottom-of-screen:offset, curr +227 *editor <- put *editor, bottom:offset, row +228 return row, column +229 ] +230 +231 scenario point-at-multiple-editors [ +232 local-scope +233 trace-until 100/app # trace too long +234 assume-screen 30/width, 5/height +235 # initialize both halves of screen +236 assume-resources [ +237 ¦ [lesson/recipes.mu] <- [ +238 ¦ ¦ |abc| +239 ¦ ] +240 ] +241 env:&:environment <- new-programming-environment resources, screen, [def] # contents of sandbox editor +242 # focus on both sides +243 assume-console [ +244 ¦ left-click 1, 1 +245 ¦ left-click 1, 17 +246 ] +247 # check cursor column in each +248 run [ +249 ¦ event-loop screen, console, env, resources +250 ¦ recipes:&:editor <- get *env, recipes:offset +251 ¦ 5:num/raw <- get *recipes, cursor-column:offset +252 ¦ sandbox:&:editor <- get *env, current-sandbox:offset +253 ¦ 7:num/raw <- get *sandbox, cursor-column:offset +254 ] +255 memory-should-contain [ +256 ¦ 5 <- 1 +257 ¦ 7 <- 17 +258 ] +259 ] +260 +261 scenario edit-multiple-editors [ +262 local-scope +263 trace-until 100/app # trace too long +264 assume-screen 30/width, 5/height +265 # initialize both halves of screen +266 assume-resources [ +267 ¦ [lesson/recipes.mu] <- [ +268 ¦ ¦ |abc| +269 ¦ ] +270 ] +271 env:&:environment <- new-programming-environment resources, screen, [def] # contents of sandbox +272 render-all screen, env, render +273 # type one letter in each of them +274 assume-console [ +275 ¦ left-click 1, 1 +276 ¦ type [0] +277 ¦ left-click 1, 17 +278 ¦ type [1] +279 ] +280 run [ +281 ¦ event-loop screen, console, env, resources +282 ¦ recipes:&:editor <- get *env, recipes:offset +283 ¦ 5:num/raw <- get *recipes, cursor-column:offset +284 ¦ sandbox:&:editor <- get *env, current-sandbox:offset +285 ¦ 7:num/raw <- get *sandbox, cursor-column:offset 286 ] -287 # show the cursor at the right window -288 run [ -289 ¦ cursor:char <- copy 9251/␣ -290 ¦ print screen, cursor -291 ] -292 screen-should-contain [ -293 ¦ . run (F4) . -294 ¦ .a0bc ╎d1␣f . -295 ¦ . ╎──────────────. -296 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . -297 ¦ . ╎ . -298 ] -299 ] -300 -301 scenario editor-in-focus-keeps-cursor [ -302 local-scope -303 trace-until 100/app # trace too long -304 assume-screen 30/width, 5/height -305 assume-resources [ -306 ¦ [lesson/recipes.mu] <- [ -307 ¦ ¦ |abc| -308 ¦ ] +287 screen-should-contain [ +288 ¦ . run (F4) . # this line has a different background, but we don't test that yet +289 ¦ .a0bc ╎d1ef . +290 ¦ . ╎──────────────. +291 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . +292 ¦ . ╎ . +293 ] +294 memory-should-contain [ +295 ¦ 5 <- 2 # cursor column of recipe editor +296 ¦ 7 <- 18 # cursor column of sandbox editor +297 ] +298 # show the cursor at the right window +299 run [ +300 ¦ cursor:char <- copy 9251/␣ +301 ¦ print screen, cursor +302 ] +303 screen-should-contain [ +304 ¦ . run (F4) . +305 ¦ .a0bc ╎d1␣f . +306 ¦ . ╎──────────────. +307 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . +308 ¦ . ╎ . 309 ] -310 env:&:environment <- new-programming-environment resources, screen, [def] -311 render-all screen, env, render -312 # initialize programming environment and highlight cursor -313 assume-console [] -314 run [ -315 ¦ event-loop screen, console, env, resources -316 ¦ cursor:char <- copy 9251/␣ -317 ¦ print screen, cursor -318 ] -319 # is cursor at the right place? -320 screen-should-contain [ -321 ¦ . run (F4) . -322 ¦ .␣bc ╎def . -323 ¦ . ╎──────────────. -324 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . -325 ¦ . ╎ . -326 ] -327 # now try typing a letter -328 assume-console [ -329 ¦ type [z] -330 ] -331 run [ -332 ¦ event-loop screen, console, env, resources -333 ¦ cursor:char <- copy 9251/␣ -334 ¦ print screen, cursor -335 ] -336 # cursor should still be right -337 screen-should-contain [ -338 ¦ . run (F4) . -339 ¦ .z␣bc ╎def . -340 ¦ . ╎──────────────. -341 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . -342 ¦ . ╎ . -343 ] -344 ] -345 -346 scenario backspace-in-sandbox-editor-joins-lines [ -347 local-scope -348 trace-until 100/app # trace too long -349 assume-screen 30/width, 5/height -350 assume-resources [ -351 ] -352 # initialize sandbox side with two lines -353 test-sandbox-editor-contents:text <- new [abc -354 def] -355 env:&:environment <- new-programming-environment resources, screen, test-sandbox-editor-contents -356 render-all screen, env, render -357 screen-should-contain [ -358 ¦ . run (F4) . -359 ¦ . ╎abc . -360 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎def . -361 ¦ . ╎──────────────. -362 ¦ . ╎ . -363 ] -364 # position cursor at start of second line and hit backspace -365 assume-console [ -366 ¦ left-click 2, 16 -367 ¦ press backspace -368 ] -369 run [ -370 ¦ event-loop screen, console, env, resources -371 ¦ cursor:char <- copy 9251/␣ -372 ¦ print screen, cursor -373 ] -374 # cursor moves to end of old line -375 screen-should-contain [ -376 ¦ . run (F4) . -377 ¦ . ╎abc␣ef . -378 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎──────────────. -379 ¦ . ╎ . -380 ] -381 ] -382 -383 def render-all screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ -384 local-scope -385 load-ingredients -386 trace 10, [app], [render all] -387 # top menu -388 trace 11, [app], [render top menu] -389 width:num <- screen-width screen -390 draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey -391 button-start:num <- subtract width, 20 -392 button-on-screen?:bool <- greater-or-equal button-start, 0 -393 assert button-on-screen?, [screen too narrow for menu] -394 screen <- move-cursor screen, 0/row, button-start -395 print screen, [ run (F4) ], 255/white, 161/reddish -396 # dotted line down the middle -397 trace 11, [app], [render divider] -398 divider:num, _ <- divide-with-remainder width, 2 -399 height:num <- screen-height screen -400 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted -401 # -402 screen <- render-recipes screen, env, render-editor -403 screen <- render-sandbox-side screen, env, render-editor -404 <render-components-end> -405 # -406 recipes:&:editor <- get *env, recipes:offset -407 current-sandbox:&:editor <- get *env, current-sandbox:offset -408 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset -409 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -410 ] -411 -412 def render-recipes screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ -413 local-scope -414 load-ingredients -415 trace 11, [app], [render recipes] -416 recipes:&:editor <- get *env, recipes:offset -417 # render recipes -418 left:num <- get *recipes, left:offset -419 right:num <- get *recipes, right:offset -420 row:num, column:num, screen <- call render-editor, screen, recipes -421 clear-line-until screen, right -422 row <- add row, 1 -423 <render-recipe-components-end> -424 # draw dotted line after recipes -425 draw-horizontal screen, row, left, right, 9480/horizontal-dotted -426 row <- add row, 1 -427 clear-screen-from screen, row, left, left, right -428 ] -429 -430 # replaced in a later layer -431 def render-sandbox-side screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ -432 local-scope -433 load-ingredients -434 current-sandbox:&:editor <- get *env, current-sandbox:offset -435 left:num <- get *current-sandbox, left:offset -436 right:num <- get *current-sandbox, right:offset -437 row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox -438 clear-line-until screen, right -439 row <- add row, 1 -440 # draw solid line after code (you'll see why in later layers) -441 draw-horizontal screen, row, left, right -442 row <- add row, 1 -443 clear-screen-from screen, row, left, left, right -444 ] -445 -446 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [ -447 local-scope -448 load-ingredients -449 <update-cursor-special-cases> -450 { -451 ¦ break-if sandbox-in-focus? -452 ¦ cursor-row:num <- get *recipes, cursor-row:offset -453 ¦ cursor-column:num <- get *recipes, cursor-column:offset -454 } -455 { -456 ¦ break-unless sandbox-in-focus? -457 ¦ cursor-row:num <- get *current-sandbox, cursor-row:offset -458 ¦ cursor-column:num <- get *current-sandbox, cursor-column:offset -459 } -460 screen <- move-cursor screen, cursor-row, cursor-column -461 ] -462 -463 # ctrl-n - switch focus -464 # todo: test this -465 -466 after <global-type> [ -467 { -468 ¦ switch-side?:bool <- equal c, 14/ctrl-n -469 ¦ break-unless switch-side? -470 ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset -471 ¦ sandbox-in-focus? <- not sandbox-in-focus? -472 ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? -473 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -474 ¦ loop +next-event -475 } -476 ] -477 -478 ## helpers -479 -480 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ -481 local-scope -482 load-ingredients -483 style:char, style-found?:bool <- next-ingredient -484 { -485 ¦ break-if style-found? -486 ¦ style <- copy 9474/vertical -487 } -488 color:num, color-found?:bool <- next-ingredient -489 { -490 ¦ # default color to white -491 ¦ break-if color-found? -492 ¦ color <- copy 245/grey -493 } -494 { -495 ¦ continue?:bool <- lesser-than y, bottom -496 ¦ break-unless continue? -497 ¦ screen <- move-cursor screen, y, col -498 ¦ print screen, style, color -499 ¦ y <- add y, 1 -500 ¦ loop +310 ] +311 +312 scenario editor-in-focus-keeps-cursor [ +313 local-scope +314 trace-until 100/app # trace too long +315 assume-screen 30/width, 5/height +316 assume-resources [ +317 ¦ [lesson/recipes.mu] <- [ +318 ¦ ¦ |abc| +319 ¦ ] +320 ] +321 env:&:environment <- new-programming-environment resources, screen, [def] +322 render-all screen, env, render +323 # initialize programming environment and highlight cursor +324 assume-console [] +325 run [ +326 ¦ event-loop screen, console, env, resources +327 ¦ cursor:char <- copy 9251/␣ +328 ¦ print screen, cursor +329 ] +330 # is cursor at the right place? +331 screen-should-contain [ +332 ¦ . run (F4) . +333 ¦ .␣bc ╎def . +334 ¦ . ╎──────────────. +335 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . +336 ¦ . ╎ . +337 ] +338 # now try typing a letter +339 assume-console [ +340 ¦ type [z] +341 ] +342 run [ +343 ¦ event-loop screen, console, env, resources +344 ¦ cursor:char <- copy 9251/␣ +345 ¦ print screen, cursor +346 ] +347 # cursor should still be right +348 screen-should-contain [ +349 ¦ . run (F4) . +350 ¦ .z␣bc ╎def . +351 ¦ . ╎──────────────. +352 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎ . +353 ¦ . ╎ . +354 ] +355 ] +356 +357 scenario backspace-in-sandbox-editor-joins-lines [ +358 local-scope +359 trace-until 100/app # trace too long +360 assume-screen 30/width, 5/height +361 assume-resources [ +362 ] +363 # initialize sandbox side with two lines +364 test-sandbox-editor-contents:text <- new [abc +365 def] +366 env:&:environment <- new-programming-environment resources, screen, test-sandbox-editor-contents +367 render-all screen, env, render +368 screen-should-contain [ +369 ¦ . run (F4) . +370 ¦ . ╎abc . +371 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎def . +372 ¦ . ╎──────────────. +373 ¦ . ╎ . +374 ] +375 # position cursor at start of second line and hit backspace +376 assume-console [ +377 ¦ left-click 2, 16 +378 ¦ press backspace +379 ] +380 run [ +381 ¦ event-loop screen, console, env, resources +382 ¦ cursor:char <- copy 9251/␣ +383 ¦ print screen, cursor +384 ] +385 # cursor moves to end of old line +386 screen-should-contain [ +387 ¦ . run (F4) . +388 ¦ . ╎abc␣ef . +389 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎──────────────. +390 ¦ . ╎ . +391 ] +392 ] +393 +394 def render-all screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ +395 local-scope +396 load-ingredients +397 trace 10, [app], [render all] +398 hide-screen screen +399 # top menu +400 trace 11, [app], [render top menu] +401 width:num <- screen-width screen +402 draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey +403 button-start:num <- subtract width, 20 +404 button-on-screen?:bool <- greater-or-equal button-start, 0 +405 assert button-on-screen?, [screen too narrow for menu] +406 screen <- move-cursor screen, 0/row, button-start +407 print screen, [ run (F4) ], 255/white, 161/reddish +408 # dotted line down the middle +409 trace 11, [app], [render divider] +410 divider:num, _ <- divide-with-remainder width, 2 +411 height:num <- screen-height screen +412 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted +413 # +414 screen <- render-recipes screen, env, render-editor +415 screen <- render-sandbox-side screen, env, render-editor +416 <render-components-end> +417 # +418 recipes:&:editor <- get *env, recipes:offset +419 current-sandbox:&:editor <- get *env, current-sandbox:offset +420 sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset +421 screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +422 # +423 show-screen screen +424 ] +425 +426 def render-recipes screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ +427 local-scope +428 load-ingredients +429 trace 11, [app], [render recipes] +430 recipes:&:editor <- get *env, recipes:offset +431 # render recipes +432 left:num <- get *recipes, left:offset +433 right:num <- get *recipes, right:offset +434 row:num, column:num, screen <- call render-editor, screen, recipes +435 clear-line-until screen, right +436 row <- add row, 1 +437 <render-recipe-components-end> +438 # draw dotted line after recipes +439 draw-horizontal screen, row, left, right, 9480/horizontal-dotted +440 row <- add row, 1 +441 clear-screen-from screen, row, left, left, right +442 ] +443 +444 # replaced in a later layer +445 def render-sandbox-side screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ +446 local-scope +447 load-ingredients +448 current-sandbox:&:editor <- get *env, current-sandbox:offset +449 left:num <- get *current-sandbox, left:offset +450 right:num <- get *current-sandbox, right:offset +451 row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox +452 clear-line-until screen, right +453 row <- add row, 1 +454 # draw solid line after code (you'll see why in later layers) +455 draw-horizontal screen, row, left, right +456 row <- add row, 1 +457 clear-screen-from screen, row, left, left, right +458 ] +459 +460 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [ +461 local-scope +462 load-ingredients +463 <update-cursor-special-cases> +464 { +465 ¦ break-if sandbox-in-focus? +466 ¦ cursor-row:num <- get *recipes, cursor-row:offset +467 ¦ cursor-column:num <- get *recipes, cursor-column:offset +468 } +469 { +470 ¦ break-unless sandbox-in-focus? +471 ¦ cursor-row:num <- get *current-sandbox, cursor-row:offset +472 ¦ cursor-column:num <- get *current-sandbox, cursor-column:offset +473 } +474 screen <- move-cursor screen, cursor-row, cursor-column +475 ] +476 +477 # ctrl-l - redraw screen (just in case it printed junk somehow) +478 +479 after <global-type> [ +480 { +481 ¦ redraw-screen?:bool <- equal c, 12/ctrl-l +482 ¦ break-unless redraw-screen? +483 ¦ screen <- render-all screen, env:&:environment, render +484 ¦ sync-screen screen +485 ¦ loop +next-event +486 } +487 ] +488 +489 # ctrl-n - switch focus +490 # todo: test this +491 +492 after <global-type> [ +493 { +494 ¦ switch-side?:bool <- equal c, 14/ctrl-n +495 ¦ break-unless switch-side? +496 ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset +497 ¦ sandbox-in-focus? <- not sandbox-in-focus? +498 ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? +499 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +500 ¦ loop +next-event 501 } 502 ] +503 +504 ## helpers +505 +506 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ +507 local-scope +508 load-ingredients +509 style:char, style-found?:bool <- next-ingredient +510 { +511 ¦ break-if style-found? +512 ¦ style <- copy 9474/vertical +513 } +514 color:num, color-found?:bool <- next-ingredient +515 { +516 ¦ # default color to white +517 ¦ break-if color-found? +518 ¦ color <- copy 245/grey +519 } +520 { +521 ¦ continue?:bool <- lesser-than y, bottom +522 ¦ break-unless continue? +523 ¦ screen <- move-cursor screen, y, col +524 ¦ print screen, style, color +525 ¦ y <- add y, 1 +526 ¦ loop +527 } +528 ] diff --git a/html/edit/005-sandbox.mu.html b/html/edit/005-sandbox.mu.html index cc3613d8..30ea06c6 100644 --- a/html/edit/005-sandbox.mu.html +++ b/html/edit/005-sandbox.mu.html @@ -75,7 +75,7 @@ if ('onhashchange' in window) { 12 open-console 13 env:&:environment <- new-programming-environment 0/filesystem, 0/screen 14 env <- restore-sandboxes env - 15 render-all 0/screen, env, render + 15 render-all 0/screen, env, render 16 event-loop 0/screen, 0/console, env, 0/filesystem 17 # never gets here 18 ] @@ -185,7 +185,7 @@ if ('onhashchange' in window) { 122 ] 123 ] 124 - 125 after <global-keypress> [ + 125 after <global-keypress> [ 126 # F4? load all code and run all sandboxes. 127 { 128 ¦ do-run?:bool <- equal k, 65532/F4 @@ -193,12 +193,12 @@ if ('onhashchange' in window) { 130 ¦ screen <- update-status screen, [running... ], 245/grey 131 ¦ error?:bool <- run-sandboxes env, resources, screen 132 ¦ # F4 might update warnings and results on both sides - 133 ¦ screen <- render-all screen, env, render + 133 ¦ screen <- render-all screen, env, render 134 ¦ { 135 ¦ ¦ break-if error? 136 ¦ ¦ screen <- update-status screen, [ ], 245/grey 137 ¦ } - 138 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + 138 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env 139 ¦ loop +next-event 140 } 141 ] @@ -276,7 +276,7 @@ if ('onhashchange' in window) { 213 def update-status screen:&:screen, msg:text, color:num -> screen:&:screen [ 214 local-scope 215 load-ingredients - 216 screen <- move-cursor screen, 0, 2 + 216 screen <- move-cursor screen, 0, 2 217 screen <- print screen, msg, color, 238/grey/background 218 ] 219 @@ -314,35 +314,35 @@ if ('onhashchange' in window) { 251 ¦ render-current-sandbox?:bool <- equal render-from, -1 252 ¦ break-unless render-current-sandbox? 253 ¦ row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox - 254 ¦ clear-screen-from screen, row, column, left, right + 254 ¦ clear-screen-from screen, row, column, left, right 255 ¦ row <- add row, 1 256 } 257 # render sandboxes 258 draw-horizontal screen, row, left, right 259 sandbox:&:sandbox <- get *env, sandbox:offset 260 row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from - 261 clear-rest-of-screen screen, row, left, right + 261 clear-rest-of-screen screen, row, left, right 262 ] 263 264 def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [ 265 local-scope 266 load-ingredients 267 return-unless sandbox - 268 screen-height:num <- screen-height screen - 269 at-bottom?:bool <- greater-or-equal row, screen-height + 268 screen-height:num <- screen-height screen + 269 at-bottom?:bool <- greater-or-equal row, screen-height 270 return-if at-bottom?:bool 271 hidden?:bool <- lesser-than idx, render-from 272 { 273 ¦ break-if hidden? 274 ¦ # render sandbox menu 275 ¦ row <- add row, 1 - 276 ¦ screen <- move-cursor screen, row, left + 276 ¦ screen <- move-cursor screen, row, left 277 ¦ screen <- render-sandbox-menu screen, idx, left, right 278 ¦ # save menu row so we can detect clicks to it later 279 ¦ *sandbox <- put *sandbox, starting-row-on-screen:offset, row 280 ¦ # render sandbox contents 281 ¦ row <- add row, 1 - 282 ¦ screen <- move-cursor screen, row, left + 282 ¦ screen <- move-cursor screen, row, left 283 ¦ sandbox-data:text <- get *sandbox, data:offset 284 ¦ row, screen <- render-code screen, sandbox-data, left, right, row 285 ¦ *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row @@ -351,7 +351,7 @@ if ('onhashchange' in window) { 288 ¦ <render-sandbox-results> 289 ¦ { 290 ¦ ¦ sandbox-screen:&:screen <- get *sandbox, screen:offset - 291 ¦ ¦ empty-screen?:bool <- fake-screen-is-empty? sandbox-screen + 291 ¦ ¦ empty-screen?:bool <- fake-screen-is-empty? sandbox-screen 292 ¦ ¦ break-if empty-screen? 293 ¦ ¦ row, screen <- render-screen screen, sandbox-screen, left, right, row 294 ¦ } @@ -361,7 +361,7 @@ if ('onhashchange' in window) { 298 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row 299 ¦ } 300 ¦ +render-sandbox-end - 301 ¦ at-bottom?:bool <- greater-or-equal row, screen-height + 301 ¦ at-bottom?:bool <- greater-or-equal row, screen-height 302 ¦ return-if at-bottom? 303 ¦ # draw solid line after sandbox 304 ¦ draw-horizontal screen, row, left, right @@ -382,23 +382,23 @@ if ('onhashchange' in window) { 319 def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num -> screen:&:screen [ 320 local-scope 321 load-ingredients - 322 move-cursor-to-column screen, left + 322 move-cursor-to-column screen, left 323 edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num <- sandbox-menu-columns left, right 324 print screen, sandbox-index, 232/dark-grey, 245/grey 325 start-buttons:num <- subtract edit-button-left, 1 - 326 clear-line-until screen, start-buttons, 245/grey + 326 clear-line-until screen, start-buttons, 245/grey 327 print screen, [edit], 232/black, 94/background-orange - 328 clear-line-until screen, edit-button-right, 94/background-orange - 329 _, col:num <- cursor-position screen + 328 clear-line-until screen, edit-button-right, 94/background-orange + 329 _, col:num <- cursor-position screen 330 at-start-of-copy-button?:bool <- equal col, copy-button-left 331 assert at-start-of-copy-button?, [aaa] 332 print screen, [copy], 232/black, 58/background-green - 333 clear-line-until screen, copy-button-right, 58/background-green - 334 _, col:num <- cursor-position screen + 333 clear-line-until screen, copy-button-right, 58/background-green + 334 _, col:num <- cursor-position screen 335 at-start-of-delete-button?:bool <- equal col, delete-button-left 336 assert at-start-of-delete-button?, [bbb] 337 print screen, [delete], 232/black, 52/background-red - 338 clear-line-until screen, right, 52/background-red + 338 clear-line-until screen, right, 52/background-red 339 ] 340 341 # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons @@ -426,15 +426,15 @@ if ('onhashchange' in window) { 363 load-ingredients 364 return-unless s 365 column:num <- copy left - 366 screen <- move-cursor screen, row, column - 367 screen-height:num <- screen-height screen + 366 screen <- move-cursor screen, row, column + 367 screen-height:num <- screen-height screen 368 i:num <- copy 0 369 len:num <- length *s 370 { 371 ¦ +next-character 372 ¦ done?:bool <- greater-or-equal i, len 373 ¦ break-if done? - 374 ¦ done? <- greater-or-equal row, screen-height + 374 ¦ done? <- greater-or-equal row, screen-height 375 ¦ break-if done? 376 ¦ c:char <- index *s, i 377 ¦ { @@ -452,7 +452,7 @@ if ('onhashchange' in window) { 389 ¦ ¦ } 390 ¦ ¦ row <- add row, 1 391 ¦ ¦ column <- copy left - 392 ¦ ¦ screen <- move-cursor screen, row, column + 392 ¦ ¦ screen <- move-cursor screen, row, column 393 ¦ ¦ i <- add i, 1 394 ¦ ¦ loop +next-character 395 ¦ } @@ -465,7 +465,7 @@ if ('onhashchange' in window) { 402 ¦ ¦ print screen, wrap-icon, 245/grey 403 ¦ ¦ column <- copy left 404 ¦ ¦ row <- add row, 1 - 405 ¦ ¦ screen <- move-cursor screen, row, column + 405 ¦ ¦ screen <- move-cursor screen, row, column 406 ¦ ¦ # don't increment i 407 ¦ ¦ loop +next-character 408 ¦ } @@ -475,12 +475,12 @@ if ('onhashchange' in window) { 412 ¦ loop 413 } 414 was-at-left?:bool <- equal column, left - 415 clear-line-until screen, right + 415 clear-line-until screen, right 416 { 417 ¦ break-if was-at-left? 418 ¦ row <- add row, 1 419 } - 420 move-cursor screen, row, left + 420 move-cursor screen, row, left 421 ] 422 423 scenario read-text-wraps-barely-long-lines [ @@ -505,15 +505,15 @@ if ('onhashchange' in window) { 442 return-unless s 443 color:num <- copy 7/white 444 column:num <- copy left - 445 screen <- move-cursor screen, row, column - 446 screen-height:num <- screen-height screen + 445 screen <- move-cursor screen, row, column + 446 screen-height:num <- screen-height screen 447 i:num <- copy 0 448 len:num <- length *s 449 { 450 ¦ +next-character 451 ¦ done?:bool <- greater-or-equal i, len 452 ¦ break-if done? - 453 ¦ done? <- greater-or-equal row, screen-height + 453 ¦ done? <- greater-or-equal row, screen-height 454 ¦ break-if done? 455 ¦ c:char <- index *s, i 456 ¦ <character-c-received> # only line different from 'render-text' @@ -532,7 +532,7 @@ if ('onhashchange' in window) { 469 ¦ ¦ } 470 ¦ ¦ row <- add row, 1 471 ¦ ¦ column <- copy left - 472 ¦ ¦ screen <- move-cursor screen, row, column + 472 ¦ ¦ screen <- move-cursor screen, row, column 473 ¦ ¦ i <- add i, 1 474 ¦ ¦ loop +next-character 475 ¦ } @@ -545,7 +545,7 @@ if ('onhashchange' in window) { 482 ¦ ¦ print screen, wrap-icon, 245/grey 483 ¦ ¦ column <- copy left 484 ¦ ¦ row <- add row, 1 - 485 ¦ ¦ screen <- move-cursor screen, row, column + 485 ¦ ¦ screen <- move-cursor screen, row, column 486 ¦ ¦ # don't increment i 487 ¦ ¦ loop +next-character 488 ¦ } @@ -555,12 +555,12 @@ if ('onhashchange' in window) { 492 ¦ loop 493 } 494 was-at-left?:bool <- equal column, left - 495 clear-line-until screen, right + 495 clear-line-until screen, right 496 { 497 ¦ break-if was-at-left? 498 ¦ row <- add row, 1 499 } - 500 move-cursor screen, row, left + 500 move-cursor screen, row, left 501 ] 502 503 # assumes programming environment has no sandboxes; restores them from previous session @@ -604,24 +604,24 @@ if ('onhashchange' in window) { 541 return-unless sandbox-screen 542 # print 'screen:' 543 row <- render-text screen, [screen:], left, right, 245/grey, row - 544 screen <- move-cursor screen, row, left + 544 screen <- move-cursor screen, row, left 545 # start printing sandbox-screen 546 column:num <- copy left - 547 s-width:num <- screen-width sandbox-screen - 548 s-height:num <- screen-height sandbox-screen + 547 s-width:num <- screen-width sandbox-screen + 548 s-height:num <- screen-height sandbox-screen 549 buf:&:@:screen-cell <- get *sandbox-screen, data:offset 550 stop-printing:num <- add left, s-width, 3 551 max-column:num <- min stop-printing, right 552 i:num <- copy 0 553 len:num <- length *buf - 554 screen-height:num <- screen-height screen + 554 screen-height:num <- screen-height screen 555 { 556 ¦ done?:bool <- greater-or-equal i, len 557 ¦ break-if done? - 558 ¦ done? <- greater-or-equal row, screen-height + 558 ¦ done? <- greater-or-equal row, screen-height 559 ¦ break-if done? 560 ¦ column <- copy left - 561 ¦ screen <- move-cursor screen, row, column + 561 ¦ screen <- move-cursor screen, row, column 562 ¦ # initial leader for each row: two spaces and a '.' 563 ¦ space:char <- copy 32/space 564 ¦ print screen, space, 245/grey @@ -778,7 +778,7 @@ if ('onhashchange' in window) { 715 scenario editor-provides-edited-contents [ 716 local-scope 717 assume-screen 10/width, 5/height - 718 e:&:editor <- new-editor [abc], 0/left, 10/right + 718 e:&:editor <- new-editor [abc], 0/left, 10/right 719 assume-console [ 720 ¦ left-click 1, 2 721 ¦ type [def] @@ -802,7 +802,7 @@ if ('onhashchange' in window) { 739 assume-resources [ 740 ] 741 env:&:environment <- new-programming-environment resources, screen, [] - 742 render-all screen, env, render + 742 render-all screen, env, render 743 assume-console [ 744 ¦ press enter 745 ¦ press down-arrow @@ -825,7 +825,7 @@ if ('onhashchange' in window) { 762 assume-resources [ 763 ] 764 env:&:environment <- new-programming-environment resources, screen, [] - 765 render-all screen, env, render + 765 render-all screen, env, render 766 assume-console [ 767 ¦ press enter 768 ¦ press up-arrow @@ -851,11 +851,11 @@ if ('onhashchange' in window) { 788 recipe-bottom:num 789 ] 790 - 791 after <render-recipe-components-end> [ + 791 after <render-recipe-components-end> [ 792 *env <- put *env, recipe-bottom:offset, row 793 ] 794 - 795 after <global-keypress> [ + 795 after <global-keypress> [ 796 { 797 ¦ break-if sandbox-in-focus? 798 ¦ down-arrow?:bool <- equal k, 65516/down-arrow @@ -879,7 +879,7 @@ if ('onhashchange' in window) { 816 } 817 ] 818 - 819 after <global-type> [ + 819 after <global-type> [ 820 { 821 ¦ break-if sandbox-in-focus? 822 ¦ page-down?:bool <- equal k, 6/ctrl-f @@ -894,7 +894,7 @@ if ('onhashchange' in window) { 831 local-scope 832 load-ingredients 833 recipe-bottom:num <- get *env, recipe-bottom:offset - 834 height:num <- screen-height screen + 834 height:num <- screen-height screen 835 result <- greater-or-equal recipe-bottom, height 836 ] 837 @@ -905,7 +905,7 @@ if ('onhashchange' in window) { 842 assume-resources [ 843 ] 844 env:&:environment <- new-programming-environment resources, screen, [] - 845 render-all screen, env, render + 845 render-all screen, env, render 846 assume-console [ 847 ¦ # add a line 848 ¦ press enter @@ -933,7 +933,7 @@ if ('onhashchange' in window) { 870 ] 871 env:&:environment <- new-programming-environment resources, screen, [ab 872 cd] - 873 render-all screen, env, render + 873 render-all screen, env, render 874 assume-console [ 875 ¦ # add a line 876 ¦ press enter @@ -965,7 +965,7 @@ if ('onhashchange' in window) { 902 assume-resources [ 903 ] 904 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] - 905 render-all screen, env, render + 905 render-all screen, env, render 906 assume-console [ 907 ¦ # create a sandbox 908 ¦ press F4 @@ -1017,7 +1017,7 @@ if ('onhashchange' in window) { 954 ] 955 956 # page-down on sandbox side updates render-from to scroll sandboxes - 957 after <global-keypress> [ + 957 after <global-keypress> [ 958 { 959 ¦ break-unless sandbox-in-focus? 960 ¦ page-down?:bool <- equal k, 65518/page-down @@ -1034,331 +1034,335 @@ if ('onhashchange' in window) { 971 ¦ ¦ render-from <- add render-from, 1 972 ¦ ¦ *env <- put *env, render-from:offset, render-from 973 ¦ } - 974 ¦ screen <- render-sandbox-side screen, env, render - 975 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env - 976 ¦ loop +next-event - 977 } - 978 ] - 979 - 980 # update-cursor takes render-from into account - 981 after <update-cursor-special-cases> [ - 982 { - 983 ¦ break-unless sandbox-in-focus? - 984 ¦ render-from:num <- get *env, render-from:offset - 985 ¦ scrolling?:bool <- greater-or-equal render-from, 0 - 986 ¦ break-unless scrolling? - 987 ¦ cursor-column:num <- get *current-sandbox, left:offset - 988 ¦ screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 - 989 ¦ return - 990 } - 991 ] - 992 - 993 # 'page-up' on sandbox side is like 'page-down': updates render-from when necessary - 994 after <global-keypress> [ - 995 { - 996 ¦ break-unless sandbox-in-focus? - 997 ¦ page-up?:bool <- equal k, 65519/page-up - 998 ¦ break-unless page-up? - 999 ¦ render-from:num <- get *env, render-from:offset -1000 ¦ at-beginning?:bool <- equal render-from, -1 -1001 ¦ break-if at-beginning? -1002 ¦ render-from <- subtract render-from, 1 -1003 ¦ *env <- put *env, render-from:offset, render-from -1004 ¦ screen <- render-sandbox-side screen, env, render -1005 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -1006 ¦ loop +next-event -1007 } -1008 ] -1009 -1010 # sandbox belonging to 'env' whose next-sandbox is 'in' -1011 # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox -1012 def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ -1013 local-scope -1014 load-ingredients -1015 curr:&:sandbox <- get *env, sandbox:offset -1016 return-unless curr, 0/nil -1017 next:&:sandbox <- get *curr, next-sandbox:offset -1018 { -1019 ¦ return-unless next, 0/nil -1020 ¦ found?:bool <- equal next, in -1021 ¦ break-if found? -1022 ¦ curr <- copy next -1023 ¦ next <- get *curr, next-sandbox:offset -1024 ¦ loop -1025 } -1026 return curr -1027 ] -1028 -1029 scenario scrolling-down-past-bottom-on-recipe-side [ -1030 local-scope -1031 trace-until 100/app # trace too long -1032 assume-screen 100/width, 10/height -1033 # initialize sandbox side and create a sandbox -1034 assume-resources [ -1035 ¦ [lesson/recipes.mu] <- [ -1036 ¦ ¦ || # file containing just a newline -1037 ¦ ] -1038 ] -1039 # create a sandbox -1040 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] -1041 render-all screen, env, render -1042 assume-console [ -1043 ¦ press F4 -1044 ] -1045 event-loop screen, console, env, resources -1046 # hit 'down' in recipe editor -1047 assume-console [ -1048 ¦ press page-down -1049 ] -1050 run [ -1051 ¦ event-loop screen, console, env, resources -1052 ¦ cursor:char <- copy 9251/␣ -1053 ¦ print screen, cursor -1054 ] -1055 # cursor doesn't move when the end is already on-screen -1056 screen-should-contain [ -1057 ¦ . run (F4) . -1058 ¦ .␣ ╎ . -1059 ¦ . ╎─────────────────────────────────────────────────. -1060 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1061 ¦ . ╎add 2, 2 . -1062 ] -1063 ] -1064 -1065 scenario scrolling-through-multiple-sandboxes [ -1066 local-scope -1067 trace-until 100/app # trace too long -1068 assume-screen 100/width, 10/height -1069 # initialize environment -1070 assume-resources [ -1071 ] -1072 env:&:environment <- new-programming-environment resources, screen, [] -1073 render-all screen, env, render -1074 # create 2 sandboxes -1075 assume-console [ -1076 ¦ press ctrl-n -1077 ¦ type [add 2, 2] -1078 ¦ press F4 -1079 ¦ type [add 1, 1] -1080 ¦ press F4 -1081 ] -1082 event-loop screen, console, env, resources -1083 cursor:char <- copy 9251/␣ -1084 print screen, cursor -1085 screen-should-contain [ -1086 ¦ . run (F4) . -1087 ¦ . ╎␣ . -1088 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1089 ¦ . ╎0 edit copy delete . -1090 ¦ . ╎add 1, 1 . -1091 ¦ . ╎2 . -1092 ¦ . ╎─────────────────────────────────────────────────. -1093 ¦ . ╎1 edit copy delete . -1094 ¦ . ╎add 2, 2 . -1095 ¦ . ╎4 . -1096 ] -1097 # hit 'page-down' -1098 assume-console [ -1099 ¦ press page-down + 974 ¦ hide-screen screen + 975 ¦ screen <- render-sandbox-side screen, env, render + 976 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + 977 ¦ show-screen screen + 978 ¦ loop +next-event + 979 } + 980 ] + 981 + 982 # update-cursor takes render-from into account + 983 after <update-cursor-special-cases> [ + 984 { + 985 ¦ break-unless sandbox-in-focus? + 986 ¦ render-from:num <- get *env, render-from:offset + 987 ¦ scrolling?:bool <- greater-or-equal render-from, 0 + 988 ¦ break-unless scrolling? + 989 ¦ cursor-column:num <- get *current-sandbox, left:offset + 990 ¦ screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 + 991 ¦ return + 992 } + 993 ] + 994 + 995 # 'page-up' on sandbox side is like 'page-down': updates render-from when necessary + 996 after <global-keypress> [ + 997 { + 998 ¦ break-unless sandbox-in-focus? + 999 ¦ page-up?:bool <- equal k, 65519/page-up +1000 ¦ break-unless page-up? +1001 ¦ render-from:num <- get *env, render-from:offset +1002 ¦ at-beginning?:bool <- equal render-from, -1 +1003 ¦ break-if at-beginning? +1004 ¦ render-from <- subtract render-from, 1 +1005 ¦ *env <- put *env, render-from:offset, render-from +1006 ¦ hide-screen screen +1007 ¦ screen <- render-sandbox-side screen, env, render +1008 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +1009 ¦ show-screen screen +1010 ¦ loop +next-event +1011 } +1012 ] +1013 +1014 # sandbox belonging to 'env' whose next-sandbox is 'in' +1015 # return 0 if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox +1016 def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ +1017 local-scope +1018 load-ingredients +1019 curr:&:sandbox <- get *env, sandbox:offset +1020 return-unless curr, 0/nil +1021 next:&:sandbox <- get *curr, next-sandbox:offset +1022 { +1023 ¦ return-unless next, 0/nil +1024 ¦ found?:bool <- equal next, in +1025 ¦ break-if found? +1026 ¦ curr <- copy next +1027 ¦ next <- get *curr, next-sandbox:offset +1028 ¦ loop +1029 } +1030 return curr +1031 ] +1032 +1033 scenario scrolling-down-past-bottom-on-recipe-side [ +1034 local-scope +1035 trace-until 100/app # trace too long +1036 assume-screen 100/width, 10/height +1037 # initialize sandbox side and create a sandbox +1038 assume-resources [ +1039 ¦ [lesson/recipes.mu] <- [ +1040 ¦ ¦ || # file containing just a newline +1041 ¦ ] +1042 ] +1043 # create a sandbox +1044 env:&:environment <- new-programming-environment resources, screen, [add 2, 2] +1045 render-all screen, env, render +1046 assume-console [ +1047 ¦ press F4 +1048 ] +1049 event-loop screen, console, env, resources +1050 # hit 'down' in recipe editor +1051 assume-console [ +1052 ¦ press page-down +1053 ] +1054 run [ +1055 ¦ event-loop screen, console, env, resources +1056 ¦ cursor:char <- copy 9251/␣ +1057 ¦ print screen, cursor +1058 ] +1059 # cursor doesn't move when the end is already on-screen +1060 screen-should-contain [ +1061 ¦ . run (F4) . +1062 ¦ .␣ ╎ . +1063 ¦ . ╎─────────────────────────────────────────────────. +1064 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1065 ¦ . ╎add 2, 2 . +1066 ] +1067 ] +1068 +1069 scenario scrolling-through-multiple-sandboxes [ +1070 local-scope +1071 trace-until 100/app # trace too long +1072 assume-screen 100/width, 10/height +1073 # initialize environment +1074 assume-resources [ +1075 ] +1076 env:&:environment <- new-programming-environment resources, screen, [] +1077 render-all screen, env, render +1078 # create 2 sandboxes +1079 assume-console [ +1080 ¦ press ctrl-n +1081 ¦ type [add 2, 2] +1082 ¦ press F4 +1083 ¦ type [add 1, 1] +1084 ¦ press F4 +1085 ] +1086 event-loop screen, console, env, resources +1087 cursor:char <- copy 9251/␣ +1088 print screen, cursor +1089 screen-should-contain [ +1090 ¦ . run (F4) . +1091 ¦ . ╎␣ . +1092 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1093 ¦ . ╎0 edit copy delete . +1094 ¦ . ╎add 1, 1 . +1095 ¦ . ╎2 . +1096 ¦ . ╎─────────────────────────────────────────────────. +1097 ¦ . ╎1 edit copy delete . +1098 ¦ . ╎add 2, 2 . +1099 ¦ . ╎4 . 1100 ] -1101 run [ -1102 ¦ event-loop screen, console, env, resources -1103 ¦ cursor:char <- copy 9251/␣ -1104 ¦ print screen, cursor -1105 ] -1106 # sandbox editor hidden; first sandbox displayed -1107 # cursor moves to first sandbox -1108 screen-should-contain [ -1109 ¦ . run (F4) . -1110 ¦ . ╎─────────────────────────────────────────────────. -1111 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . -1112 ¦ . ╎add 1, 1 . -1113 ¦ . ╎2 . +1101 # hit 'page-down' +1102 assume-console [ +1103 ¦ press page-down +1104 ] +1105 run [ +1106 ¦ event-loop screen, console, env, resources +1107 ¦ cursor:char <- copy 9251/␣ +1108 ¦ print screen, cursor +1109 ] +1110 # sandbox editor hidden; first sandbox displayed +1111 # cursor moves to first sandbox +1112 screen-should-contain [ +1113 ¦ . run (F4) . 1114 ¦ . ╎─────────────────────────────────────────────────. -1115 ¦ . ╎1 edit copy delete . -1116 ¦ . ╎add 2, 2 . -1117 ¦ . ╎4 . -1118 ] -1119 # hit 'page-down' again -1120 assume-console [ -1121 ¦ press page-down +1115 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎␣ edit copy delete . +1116 ¦ . ╎add 1, 1 . +1117 ¦ . ╎2 . +1118 ¦ . ╎─────────────────────────────────────────────────. +1119 ¦ . ╎1 edit copy delete . +1120 ¦ . ╎add 2, 2 . +1121 ¦ . ╎4 . 1122 ] -1123 run [ -1124 ¦ event-loop screen, console, env, resources -1125 ] -1126 # just second sandbox displayed -1127 screen-should-contain [ -1128 ¦ . run (F4) . -1129 ¦ . ╎─────────────────────────────────────────────────. -1130 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -1131 ¦ . ╎add 2, 2 . -1132 ¦ . ╎4 . +1123 # hit 'page-down' again +1124 assume-console [ +1125 ¦ press page-down +1126 ] +1127 run [ +1128 ¦ event-loop screen, console, env, resources +1129 ] +1130 # just second sandbox displayed +1131 screen-should-contain [ +1132 ¦ . run (F4) . 1133 ¦ . ╎─────────────────────────────────────────────────. -1134 ¦ . ╎ . -1135 ] -1136 # hit 'page-down' again -1137 assume-console [ -1138 ¦ press page-down +1134 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1135 ¦ . ╎add 2, 2 . +1136 ¦ . ╎4 . +1137 ¦ . ╎─────────────────────────────────────────────────. +1138 ¦ . ╎ . 1139 ] -1140 run [ -1141 ¦ event-loop screen, console, env, resources -1142 ] -1143 # no change -1144 screen-should-contain [ -1145 ¦ . run (F4) . -1146 ¦ . ╎─────────────────────────────────────────────────. -1147 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -1148 ¦ . ╎add 2, 2 . -1149 ¦ . ╎4 . +1140 # hit 'page-down' again +1141 assume-console [ +1142 ¦ press page-down +1143 ] +1144 run [ +1145 ¦ event-loop screen, console, env, resources +1146 ] +1147 # no change +1148 screen-should-contain [ +1149 ¦ . run (F4) . 1150 ¦ . ╎─────────────────────────────────────────────────. -1151 ¦ . ╎ . -1152 ] -1153 # hit 'page-up' -1154 assume-console [ -1155 ¦ press page-up +1151 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +1152 ¦ . ╎add 2, 2 . +1153 ¦ . ╎4 . +1154 ¦ . ╎─────────────────────────────────────────────────. +1155 ¦ . ╎ . 1156 ] -1157 run [ -1158 ¦ event-loop screen, console, env, resources -1159 ] -1160 # back to displaying both sandboxes without editor -1161 screen-should-contain [ -1162 ¦ . run (F4) . -1163 ¦ . ╎─────────────────────────────────────────────────. -1164 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1165 ¦ . ╎add 1, 1 . -1166 ¦ . ╎2 . +1157 # hit 'page-up' +1158 assume-console [ +1159 ¦ press page-up +1160 ] +1161 run [ +1162 ¦ event-loop screen, console, env, resources +1163 ] +1164 # back to displaying both sandboxes without editor +1165 screen-should-contain [ +1166 ¦ . run (F4) . 1167 ¦ . ╎─────────────────────────────────────────────────. -1168 ¦ . ╎1 edit copy delete . -1169 ¦ . ╎add 2, 2 . -1170 ¦ . ╎4 . -1171 ] -1172 # hit 'page-up' again -1173 assume-console [ -1174 ¦ press page-up +1168 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1169 ¦ . ╎add 1, 1 . +1170 ¦ . ╎2 . +1171 ¦ . ╎─────────────────────────────────────────────────. +1172 ¦ . ╎1 edit copy delete . +1173 ¦ . ╎add 2, 2 . +1174 ¦ . ╎4 . 1175 ] -1176 run [ -1177 ¦ event-loop screen, console, env, resources -1178 ¦ cursor:char <- copy 9251/␣ -1179 ¦ print screen, cursor -1180 ] -1181 # back to displaying both sandboxes as well as editor -1182 screen-should-contain [ -1183 ¦ . run (F4) . -1184 ¦ . ╎␣ . -1185 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1186 ¦ . ╎0 edit copy delete . -1187 ¦ . ╎add 1, 1 . -1188 ¦ . ╎2 . -1189 ¦ . ╎─────────────────────────────────────────────────. -1190 ¦ . ╎1 edit copy delete . -1191 ¦ . ╎add 2, 2 . -1192 ¦ . ╎4 . -1193 ] -1194 # hit 'page-up' again -1195 assume-console [ -1196 ¦ press page-up +1176 # hit 'page-up' again +1177 assume-console [ +1178 ¦ press page-up +1179 ] +1180 run [ +1181 ¦ event-loop screen, console, env, resources +1182 ¦ cursor:char <- copy 9251/␣ +1183 ¦ print screen, cursor +1184 ] +1185 # back to displaying both sandboxes as well as editor +1186 screen-should-contain [ +1187 ¦ . run (F4) . +1188 ¦ . ╎␣ . +1189 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1190 ¦ . ╎0 edit copy delete . +1191 ¦ . ╎add 1, 1 . +1192 ¦ . ╎2 . +1193 ¦ . ╎─────────────────────────────────────────────────. +1194 ¦ . ╎1 edit copy delete . +1195 ¦ . ╎add 2, 2 . +1196 ¦ . ╎4 . 1197 ] -1198 run [ -1199 ¦ event-loop screen, console, env, resources -1200 ¦ cursor:char <- copy 9251/␣ -1201 ¦ print screen, cursor -1202 ] -1203 # no change -1204 screen-should-contain [ -1205 ¦ . run (F4) . -1206 ¦ . ╎␣ . -1207 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1208 ¦ . ╎0 edit copy delete . -1209 ¦ . ╎add 1, 1 . -1210 ¦ . ╎2 . -1211 ¦ . ╎─────────────────────────────────────────────────. -1212 ¦ . ╎1 edit copy delete . -1213 ¦ . ╎add 2, 2 . -1214 ¦ . ╎4 . -1215 ] -1216 ] -1217 -1218 scenario scrolling-manages-sandbox-index-correctly [ -1219 local-scope -1220 trace-until 100/app # trace too long -1221 assume-screen 100/width, 10/height -1222 # initialize environment -1223 assume-resources [ -1224 ] -1225 env:&:environment <- new-programming-environment resources, screen, [] -1226 render-all screen, env, render -1227 # create a sandbox -1228 assume-console [ -1229 ¦ press ctrl-n -1230 ¦ type [add 1, 1] -1231 ¦ press F4 -1232 ] -1233 event-loop screen, console, env, resources -1234 screen-should-contain [ -1235 ¦ . run (F4) . -1236 ¦ . ╎ . -1237 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1238 ¦ . ╎0 edit copy delete . -1239 ¦ . ╎add 1, 1 . -1240 ¦ . ╎2 . -1241 ¦ . ╎─────────────────────────────────────────────────. -1242 ¦ . ╎ . -1243 ] -1244 # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable -1245 assume-console [ -1246 ¦ press page-down +1198 # hit 'page-up' again +1199 assume-console [ +1200 ¦ press page-up +1201 ] +1202 run [ +1203 ¦ event-loop screen, console, env, resources +1204 ¦ cursor:char <- copy 9251/␣ +1205 ¦ print screen, cursor +1206 ] +1207 # no change +1208 screen-should-contain [ +1209 ¦ . run (F4) . +1210 ¦ . ╎␣ . +1211 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1212 ¦ . ╎0 edit copy delete . +1213 ¦ . ╎add 1, 1 . +1214 ¦ . ╎2 . +1215 ¦ . ╎─────────────────────────────────────────────────. +1216 ¦ . ╎1 edit copy delete . +1217 ¦ . ╎add 2, 2 . +1218 ¦ . ╎4 . +1219 ] +1220 ] +1221 +1222 scenario scrolling-manages-sandbox-index-correctly [ +1223 local-scope +1224 trace-until 100/app # trace too long +1225 assume-screen 100/width, 10/height +1226 # initialize environment +1227 assume-resources [ +1228 ] +1229 env:&:environment <- new-programming-environment resources, screen, [] +1230 render-all screen, env, render +1231 # create a sandbox +1232 assume-console [ +1233 ¦ press ctrl-n +1234 ¦ type [add 1, 1] +1235 ¦ press F4 +1236 ] +1237 event-loop screen, console, env, resources +1238 screen-should-contain [ +1239 ¦ . run (F4) . +1240 ¦ . ╎ . +1241 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1242 ¦ . ╎0 edit copy delete . +1243 ¦ . ╎add 1, 1 . +1244 ¦ . ╎2 . +1245 ¦ . ╎─────────────────────────────────────────────────. +1246 ¦ . ╎ . 1247 ] -1248 run [ -1249 ¦ event-loop screen, console, env, resources -1250 ] -1251 # sandbox editor hidden; first sandbox displayed -1252 # cursor moves to first sandbox -1253 screen-should-contain [ -1254 ¦ . run (F4) . -1255 ¦ . ╎─────────────────────────────────────────────────. -1256 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1257 ¦ . ╎add 1, 1 . -1258 ¦ . ╎2 . +1248 # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable +1249 assume-console [ +1250 ¦ press page-down +1251 ] +1252 run [ +1253 ¦ event-loop screen, console, env, resources +1254 ] +1255 # sandbox editor hidden; first sandbox displayed +1256 # cursor moves to first sandbox +1257 screen-should-contain [ +1258 ¦ . run (F4) . 1259 ¦ . ╎─────────────────────────────────────────────────. -1260 ¦ . ╎ . -1261 ] -1262 # hit 'page-up' again -1263 assume-console [ -1264 ¦ press page-up +1260 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1261 ¦ . ╎add 1, 1 . +1262 ¦ . ╎2 . +1263 ¦ . ╎─────────────────────────────────────────────────. +1264 ¦ . ╎ . 1265 ] -1266 run [ -1267 ¦ event-loop screen, console, env, resources -1268 ] -1269 # back to displaying both sandboxes as well as editor -1270 screen-should-contain [ -1271 ¦ . run (F4) . -1272 ¦ . ╎ . -1273 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -1274 ¦ . ╎0 edit copy delete . -1275 ¦ . ╎add 1, 1 . -1276 ¦ . ╎2 . -1277 ¦ . ╎─────────────────────────────────────────────────. -1278 ¦ . ╎ . -1279 ] -1280 # hit 'page-down' -1281 assume-console [ -1282 ¦ press page-down +1266 # hit 'page-up' again +1267 assume-console [ +1268 ¦ press page-up +1269 ] +1270 run [ +1271 ¦ event-loop screen, console, env, resources +1272 ] +1273 # back to displaying both sandboxes as well as editor +1274 screen-should-contain [ +1275 ¦ . run (F4) . +1276 ¦ . ╎ . +1277 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +1278 ¦ . ╎0 edit copy delete . +1279 ¦ . ╎add 1, 1 . +1280 ¦ . ╎2 . +1281 ¦ . ╎─────────────────────────────────────────────────. +1282 ¦ . ╎ . 1283 ] -1284 run [ -1285 ¦ event-loop screen, console, env, resources -1286 ] -1287 # sandbox editor hidden; first sandbox displayed -1288 # cursor moves to first sandbox -1289 screen-should-contain [ -1290 ¦ . run (F4) . -1291 ¦ . ╎─────────────────────────────────────────────────. -1292 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -1293 ¦ . ╎add 1, 1 . -1294 ¦ . ╎2 . +1284 # hit 'page-down' +1285 assume-console [ +1286 ¦ press page-down +1287 ] +1288 run [ +1289 ¦ event-loop screen, console, env, resources +1290 ] +1291 # sandbox editor hidden; first sandbox displayed +1292 # cursor moves to first sandbox +1293 screen-should-contain [ +1294 ¦ . run (F4) . 1295 ¦ . ╎─────────────────────────────────────────────────. -1296 ¦ . ╎ . -1297 ] -1298 ] +1296 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +1297 ¦ . ╎add 1, 1 . +1298 ¦ . ╎2 . +1299 ¦ . ╎─────────────────────────────────────────────────. +1300 ¦ . ╎ . +1301 ] +1302 ] 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 ] diff --git a/html/edit/007-sandbox-delete.mu.html b/html/edit/007-sandbox-delete.mu.html index 327563c0..4d297d8b 100644 --- a/html/edit/007-sandbox-delete.mu.html +++ b/html/edit/007-sandbox-delete.mu.html @@ -127,280 +127,282 @@ if ('onhashchange' in window) { 65 ] 66 ] 67 - 68 after <global-touch> [ + 68 after <global-touch> [ 69 # support 'delete' button 70 { - 71 ¦ delete?:bool <- should-attempt-delete? click-row, click-column, env + 71 ¦ delete?:bool <- should-attempt-delete? click-row, click-column, env 72 ¦ break-unless delete? - 73 ¦ delete?, env <- try-delete-sandbox click-row, env + 73 ¦ delete?, env <- try-delete-sandbox click-row, env 74 ¦ break-unless delete? - 75 ¦ screen <- render-sandbox-side screen, env, render - 76 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env - 77 ¦ loop +next-event - 78 } - 79 ] - 80 - 81 # some preconditions for attempting to delete a sandbox - 82 def should-attempt-delete? click-row:num, click-column:num, env:&:environment -> result:bool [ - 83 local-scope - 84 load-ingredients - 85 # are we below the sandbox editor? - 86 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env - 87 return-unless click-sandbox-area?, 0/false - 88 # narrower, is the click in the columns spanning the 'copy' button? - 89 first-sandbox:&:editor <- get *env, current-sandbox:offset - 90 assert first-sandbox, [!!] - 91 sandbox-left-margin:num <- get *first-sandbox, left:offset - 92 sandbox-right-margin:num <- get *first-sandbox, right:offset - 93 _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - 94 result <- within-range? click-column, delete-button-left, sandbox-right-margin - 95 ] - 96 - 97 def try-delete-sandbox click-row:num, env:&:environment -> clicked-on-delete-button?:bool, env:&:environment [ - 98 local-scope - 99 load-ingredients -100 # identify the sandbox to delete, if the click was actually on the 'delete' button -101 sandbox:&:sandbox <- find-sandbox env, click-row -102 return-unless sandbox, 0/false -103 clicked-on-delete-button? <- copy 1/true -104 env <- delete-sandbox env, sandbox -105 ] -106 -107 def delete-sandbox env:&:environment, sandbox:&:sandbox -> env:&:environment [ -108 local-scope -109 load-ingredients -110 curr-sandbox:&:sandbox <- get *env, sandbox:offset -111 first-sandbox?:bool <- equal curr-sandbox, sandbox -112 { -113 ¦ # first sandbox? pop -114 ¦ break-unless first-sandbox? -115 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset -116 ¦ *env <- put *env, sandbox:offset, next-sandbox -117 } -118 { -119 ¦ # not first sandbox? -120 ¦ break-if first-sandbox? -121 ¦ prev-sandbox:&:sandbox <- copy curr-sandbox -122 ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset -123 ¦ { -124 ¦ ¦ assert curr-sandbox, [sandbox not found! something is wrong.] -125 ¦ ¦ found?:bool <- equal curr-sandbox, sandbox -126 ¦ ¦ break-if found? -127 ¦ ¦ prev-sandbox <- copy curr-sandbox -128 ¦ ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset -129 ¦ ¦ loop -130 ¦ } -131 ¦ # snip sandbox out of its list -132 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset -133 ¦ *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox -134 } -135 # update sandbox count -136 sandbox-count:num <- get *env, number-of-sandboxes:offset -137 sandbox-count <- subtract sandbox-count, 1 -138 *env <- put *env, number-of-sandboxes:offset, sandbox-count -139 # reset scroll if deleted sandbox was last -140 { -141 ¦ break-if next-sandbox -142 ¦ render-from:num <- get *env, render-from:offset -143 ¦ reset-scroll?:bool <- equal render-from, sandbox-count -144 ¦ break-unless reset-scroll? -145 ¦ *env <- put *env, render-from:offset, -1 -146 } -147 ] -148 -149 scenario deleting-sandbox-after-scroll [ -150 local-scope -151 trace-until 100/app # trace too long -152 assume-screen 100/width, 10/height -153 # initialize environment -154 assume-resources [ -155 ] -156 env:&:environment <- new-programming-environment resources, screen, [] -157 render-all screen, env, render -158 # create 2 sandboxes and scroll to second -159 assume-console [ -160 ¦ press ctrl-n -161 ¦ type [add 2, 2] -162 ¦ press F4 -163 ¦ type [add 1, 1] + 75 ¦ hide-screen screen + 76 ¦ screen <- render-sandbox-side screen, env, render + 77 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + 78 ¦ show-screen screen + 79 ¦ loop +next-event + 80 } + 81 ] + 82 + 83 # some preconditions for attempting to delete a sandbox + 84 def should-attempt-delete? click-row:num, click-column:num, env:&:environment -> result:bool [ + 85 local-scope + 86 load-ingredients + 87 # are we below the sandbox editor? + 88 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env + 89 return-unless click-sandbox-area?, 0/false + 90 # narrower, is the click in the columns spanning the 'copy' button? + 91 first-sandbox:&:editor <- get *env, current-sandbox:offset + 92 assert first-sandbox, [!!] + 93 sandbox-left-margin:num <- get *first-sandbox, left:offset + 94 sandbox-right-margin:num <- get *first-sandbox, right:offset + 95 _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + 96 result <- within-range? click-column, delete-button-left, sandbox-right-margin + 97 ] + 98 + 99 def try-delete-sandbox click-row:num, env:&:environment -> clicked-on-delete-button?:bool, env:&:environment [ +100 local-scope +101 load-ingredients +102 # identify the sandbox to delete, if the click was actually on the 'delete' button +103 sandbox:&:sandbox <- find-sandbox env, click-row +104 return-unless sandbox, 0/false +105 clicked-on-delete-button? <- copy 1/true +106 env <- delete-sandbox env, sandbox +107 ] +108 +109 def delete-sandbox env:&:environment, sandbox:&:sandbox -> env:&:environment [ +110 local-scope +111 load-ingredients +112 curr-sandbox:&:sandbox <- get *env, sandbox:offset +113 first-sandbox?:bool <- equal curr-sandbox, sandbox +114 { +115 ¦ # first sandbox? pop +116 ¦ break-unless first-sandbox? +117 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset +118 ¦ *env <- put *env, sandbox:offset, next-sandbox +119 } +120 { +121 ¦ # not first sandbox? +122 ¦ break-if first-sandbox? +123 ¦ prev-sandbox:&:sandbox <- copy curr-sandbox +124 ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset +125 ¦ { +126 ¦ ¦ assert curr-sandbox, [sandbox not found! something is wrong.] +127 ¦ ¦ found?:bool <- equal curr-sandbox, sandbox +128 ¦ ¦ break-if found? +129 ¦ ¦ prev-sandbox <- copy curr-sandbox +130 ¦ ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset +131 ¦ ¦ loop +132 ¦ } +133 ¦ # snip sandbox out of its list +134 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset +135 ¦ *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox +136 } +137 # update sandbox count +138 sandbox-count:num <- get *env, number-of-sandboxes:offset +139 sandbox-count <- subtract sandbox-count, 1 +140 *env <- put *env, number-of-sandboxes:offset, sandbox-count +141 # reset scroll if deleted sandbox was last +142 { +143 ¦ break-if next-sandbox +144 ¦ render-from:num <- get *env, render-from:offset +145 ¦ reset-scroll?:bool <- equal render-from, sandbox-count +146 ¦ break-unless reset-scroll? +147 ¦ *env <- put *env, render-from:offset, -1 +148 } +149 ] +150 +151 scenario deleting-sandbox-after-scroll [ +152 local-scope +153 trace-until 100/app # trace too long +154 assume-screen 100/width, 10/height +155 # initialize environment +156 assume-resources [ +157 ] +158 env:&:environment <- new-programming-environment resources, screen, [] +159 render-all screen, env, render +160 # create 2 sandboxes and scroll to second +161 assume-console [ +162 ¦ press ctrl-n +163 ¦ type [add 2, 2] 164 ¦ press F4 -165 ¦ press page-down -166 ] -167 event-loop screen, console, env, resources -168 screen-should-contain [ -169 ¦ . run (F4) . -170 ¦ . ╎─────────────────────────────────────────────────. -171 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -172 ¦ . ╎add 1, 1 . -173 ¦ . ╎2 . -174 ¦ . ╎─────────────────────────────────────────────────. -175 ¦ . ╎1 edit copy delete . -176 ] -177 # delete the second sandbox -178 assume-console [ -179 ¦ left-click 6, 99 -180 ] -181 run [ -182 ¦ event-loop screen, console, env, resources -183 ] -184 # second sandbox shows in editor; scroll resets to display first sandbox -185 screen-should-contain [ -186 ¦ . run (F4) . -187 ¦ . ╎─────────────────────────────────────────────────. -188 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -189 ¦ . ╎add 1, 1 . -190 ¦ . ╎2 . -191 ¦ . ╎─────────────────────────────────────────────────. -192 ¦ . ╎ . -193 ] -194 ] -195 -196 scenario deleting-top-sandbox-after-scroll [ -197 local-scope -198 trace-until 100/app # trace too long -199 assume-screen 100/width, 10/height -200 # initialize environment -201 assume-resources [ -202 ] -203 env:&:environment <- new-programming-environment resources, screen, [] -204 render-all screen, env, render -205 # create 2 sandboxes and scroll to second -206 assume-console [ -207 ¦ press ctrl-n -208 ¦ type [add 2, 2] -209 ¦ press F4 -210 ¦ type [add 1, 1] +165 ¦ type [add 1, 1] +166 ¦ press F4 +167 ¦ press page-down +168 ] +169 event-loop screen, console, env, resources +170 screen-should-contain [ +171 ¦ . run (F4) . +172 ¦ . ╎─────────────────────────────────────────────────. +173 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +174 ¦ . ╎add 1, 1 . +175 ¦ . ╎2 . +176 ¦ . ╎─────────────────────────────────────────────────. +177 ¦ . ╎1 edit copy delete . +178 ] +179 # delete the second sandbox +180 assume-console [ +181 ¦ left-click 6, 99 +182 ] +183 run [ +184 ¦ event-loop screen, console, env, resources +185 ] +186 # second sandbox shows in editor; scroll resets to display first sandbox +187 screen-should-contain [ +188 ¦ . run (F4) . +189 ¦ . ╎─────────────────────────────────────────────────. +190 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +191 ¦ . ╎add 1, 1 . +192 ¦ . ╎2 . +193 ¦ . ╎─────────────────────────────────────────────────. +194 ¦ . ╎ . +195 ] +196 ] +197 +198 scenario deleting-top-sandbox-after-scroll [ +199 local-scope +200 trace-until 100/app # trace too long +201 assume-screen 100/width, 10/height +202 # initialize environment +203 assume-resources [ +204 ] +205 env:&:environment <- new-programming-environment resources, screen, [] +206 render-all screen, env, render +207 # create 2 sandboxes and scroll to second +208 assume-console [ +209 ¦ press ctrl-n +210 ¦ type [add 2, 2] 211 ¦ press F4 -212 ¦ press page-down -213 ] -214 event-loop screen, console, env, resources -215 screen-should-contain [ -216 ¦ . run (F4) . -217 ¦ . ╎─────────────────────────────────────────────────. -218 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -219 ¦ . ╎add 1, 1 . -220 ¦ . ╎2 . -221 ¦ . ╎─────────────────────────────────────────────────. -222 ¦ . ╎1 edit copy delete . -223 ] -224 # delete the second sandbox -225 assume-console [ -226 ¦ left-click 2, 99 -227 ] -228 run [ -229 ¦ event-loop screen, console, env, resources -230 ] -231 # second sandbox shows in editor; scroll resets to display first sandbox -232 screen-should-contain [ -233 ¦ . run (F4) . -234 ¦ . ╎─────────────────────────────────────────────────. -235 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -236 ¦ . ╎add 2, 2 . -237 ¦ . ╎4 . -238 ¦ . ╎─────────────────────────────────────────────────. -239 ¦ . ╎ . -240 ] -241 ] -242 -243 scenario deleting-final-sandbox-after-scroll [ -244 local-scope -245 trace-until 100/app # trace too long -246 assume-screen 100/width, 10/height -247 # initialize environment -248 assume-resources [ -249 ] -250 env:&:environment <- new-programming-environment resources, screen, [] -251 render-all screen, env, render -252 # create 2 sandboxes and scroll to second -253 assume-console [ -254 ¦ press ctrl-n -255 ¦ type [add 2, 2] -256 ¦ press F4 -257 ¦ type [add 1, 1] +212 ¦ type [add 1, 1] +213 ¦ press F4 +214 ¦ press page-down +215 ] +216 event-loop screen, console, env, resources +217 screen-should-contain [ +218 ¦ . run (F4) . +219 ¦ . ╎─────────────────────────────────────────────────. +220 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +221 ¦ . ╎add 1, 1 . +222 ¦ . ╎2 . +223 ¦ . ╎─────────────────────────────────────────────────. +224 ¦ . ╎1 edit copy delete . +225 ] +226 # delete the second sandbox +227 assume-console [ +228 ¦ left-click 2, 99 +229 ] +230 run [ +231 ¦ event-loop screen, console, env, resources +232 ] +233 # second sandbox shows in editor; scroll resets to display first sandbox +234 screen-should-contain [ +235 ¦ . run (F4) . +236 ¦ . ╎─────────────────────────────────────────────────. +237 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +238 ¦ . ╎add 2, 2 . +239 ¦ . ╎4 . +240 ¦ . ╎─────────────────────────────────────────────────. +241 ¦ . ╎ . +242 ] +243 ] +244 +245 scenario deleting-final-sandbox-after-scroll [ +246 local-scope +247 trace-until 100/app # trace too long +248 assume-screen 100/width, 10/height +249 # initialize environment +250 assume-resources [ +251 ] +252 env:&:environment <- new-programming-environment resources, screen, [] +253 render-all screen, env, render +254 # create 2 sandboxes and scroll to second +255 assume-console [ +256 ¦ press ctrl-n +257 ¦ type [add 2, 2] 258 ¦ press F4 -259 ¦ press page-down -260 ¦ press page-down -261 ] -262 event-loop screen, console, env, resources -263 screen-should-contain [ -264 ¦ . run (F4) . -265 ¦ . ╎─────────────────────────────────────────────────. -266 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -267 ¦ . ╎add 2, 2 . -268 ¦ . ╎4 . -269 ¦ . ╎─────────────────────────────────────────────────. -270 ¦ . ╎ . -271 ] -272 # delete the second sandbox -273 assume-console [ -274 ¦ left-click 2, 99 -275 ] -276 run [ -277 ¦ event-loop screen, console, env, resources -278 ] -279 # implicitly scroll up to first sandbox -280 screen-should-contain [ -281 ¦ . run (F4) . -282 ¦ . ╎ . -283 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -284 ¦ . ╎0 edit copy delete . -285 ¦ . ╎add 1, 1 . -286 ¦ . ╎2 . -287 ¦ . ╎─────────────────────────────────────────────────. -288 ¦ . ╎ . -289 ] -290 ] -291 -292 scenario deleting-updates-sandbox-count [ -293 local-scope -294 trace-until 100/app # trace too long -295 assume-screen 100/width, 10/height -296 # initialize environment -297 assume-resources [ -298 ] -299 env:&:environment <- new-programming-environment resources, screen, [] -300 render-all screen, env, render -301 # create 2 sandboxes -302 assume-console [ -303 ¦ press ctrl-n -304 ¦ type [add 2, 2] -305 ¦ press F4 -306 ¦ type [add 1, 1] +259 ¦ type [add 1, 1] +260 ¦ press F4 +261 ¦ press page-down +262 ¦ press page-down +263 ] +264 event-loop screen, console, env, resources +265 screen-should-contain [ +266 ¦ . run (F4) . +267 ¦ . ╎─────────────────────────────────────────────────. +268 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +269 ¦ . ╎add 2, 2 . +270 ¦ . ╎4 . +271 ¦ . ╎─────────────────────────────────────────────────. +272 ¦ . ╎ . +273 ] +274 # delete the second sandbox +275 assume-console [ +276 ¦ left-click 2, 99 +277 ] +278 run [ +279 ¦ event-loop screen, console, env, resources +280 ] +281 # implicitly scroll up to first sandbox +282 screen-should-contain [ +283 ¦ . run (F4) . +284 ¦ . ╎ . +285 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +286 ¦ . ╎0 edit copy delete . +287 ¦ . ╎add 1, 1 . +288 ¦ . ╎2 . +289 ¦ . ╎─────────────────────────────────────────────────. +290 ¦ . ╎ . +291 ] +292 ] +293 +294 scenario deleting-updates-sandbox-count [ +295 local-scope +296 trace-until 100/app # trace too long +297 assume-screen 100/width, 10/height +298 # initialize environment +299 assume-resources [ +300 ] +301 env:&:environment <- new-programming-environment resources, screen, [] +302 render-all screen, env, render +303 # create 2 sandboxes +304 assume-console [ +305 ¦ press ctrl-n +306 ¦ type [add 2, 2] 307 ¦ press F4 -308 ] -309 event-loop screen, console, env, resources -310 screen-should-contain [ -311 ¦ . run (F4) . -312 ¦ . ╎ . -313 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -314 ¦ . ╎0 edit copy delete . -315 ¦ . ╎add 1, 1 . -316 ¦ . ╎2 . -317 ¦ . ╎─────────────────────────────────────────────────. -318 ¦ . ╎1 edit copy delete . -319 ¦ . ╎add 2, 2 . -320 ¦ . ╎4 . -321 ] -322 # delete the second sandbox, then try to scroll down twice -323 assume-console [ -324 ¦ left-click 3, 99 -325 ¦ press page-down -326 ¦ press page-down -327 ] -328 run [ -329 ¦ event-loop screen, console, env, resources -330 ] -331 # shouldn't go past last sandbox -332 screen-should-contain [ -333 ¦ . run (F4) . -334 ¦ . ╎─────────────────────────────────────────────────. -335 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . -336 ¦ . ╎add 2, 2 . -337 ¦ . ╎4 . -338 ¦ . ╎─────────────────────────────────────────────────. -339 ¦ . ╎ . -340 ] -341 ] +308 ¦ type [add 1, 1] +309 ¦ press F4 +310 ] +311 event-loop screen, console, env, resources +312 screen-should-contain [ +313 ¦ . run (F4) . +314 ¦ . ╎ . +315 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +316 ¦ . ╎0 edit copy delete . +317 ¦ . ╎add 1, 1 . +318 ¦ . ╎2 . +319 ¦ . ╎─────────────────────────────────────────────────. +320 ¦ . ╎1 edit copy delete . +321 ¦ . ╎add 2, 2 . +322 ¦ . ╎4 . +323 ] +324 # delete the second sandbox, then try to scroll down twice +325 assume-console [ +326 ¦ left-click 3, 99 +327 ¦ press page-down +328 ¦ press page-down +329 ] +330 run [ +331 ¦ event-loop screen, console, env, resources +332 ] +333 # shouldn't go past last sandbox +334 screen-should-contain [ +335 ¦ . run (F4) . +336 ¦ . ╎─────────────────────────────────────────────────. +337 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete . +338 ¦ . ╎add 2, 2 . +339 ¦ . ╎4 . +340 ¦ . ╎─────────────────────────────────────────────────. +341 ¦ . ╎ . +342 ] +343 ] diff --git a/html/edit/008-sandbox-edit.mu.html b/html/edit/008-sandbox-edit.mu.html index f1ea0ffb..29b9b889 100644 --- a/html/edit/008-sandbox-edit.mu.html +++ b/html/edit/008-sandbox-edit.mu.html @@ -166,222 +166,224 @@ if ('onhashchange' in window) { 104 ] 105 ] 106 -107 after <global-touch> [ +107 after <global-touch> [ 108 # support 'edit' button 109 { -110 ¦ edit?:bool <- should-attempt-edit? click-row, click-column, env +110 ¦ edit?:bool <- should-attempt-edit? click-row, click-column, env 111 ¦ break-unless edit? -112 ¦ edit?, env <- try-edit-sandbox click-row, env +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 # some preconditions for attempting to edit a sandbox -121 def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> result:bool [ -122 local-scope -123 load-ingredients -124 # are we below the sandbox editor? -125 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env -126 return-unless click-sandbox-area?, 0/false -127 # narrower, is the click in the columns spanning the 'edit' button? -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 # finally, is sandbox editor empty? -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 # identify the sandbox to edit, if the click was actually on the 'edit' button -144 sandbox:&:sandbox <- find-sandbox env, click-row -145 return-unless sandbox, 0/false -146 clicked-on-edit-button? <- copy 1/true -147 # 'edit' button = 'copy' button + 'delete' button -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 # reset scroll -153 *env <- put *env, render-from:offset, -1 -154 # position cursor in sandbox editor -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 # trace too long -161 assume-screen 100/width, 20/height -162 # left editor is empty -163 assume-resources [ -164 ] -165 # right editor contains a print instruction -166 env:&:environment <- new-programming-environment resources, screen, [print screen, 4] -167 # run the sandbox -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 delete . -177 ¦ . ╎print screen, 4 . -178 ¦ . ╎screen: . -179 ¦ . ╎ .4 . . -180 ¦ . ╎ . . . -181 ¦ . ╎ . . . +114 ¦ hide-screen screen +115 ¦ screen <- render-sandbox-side screen, env, render +116 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +117 ¦ show-screen screen +118 ¦ loop +next-event +119 } +120 ] +121 +122 # some preconditions for attempting to edit a sandbox +123 def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> result:bool [ +124 local-scope +125 load-ingredients +126 # are we below the sandbox editor? +127 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env +128 return-unless click-sandbox-area?, 0/false +129 # narrower, is the click in the columns spanning the 'edit' button? +130 first-sandbox:&:editor <- get *env, current-sandbox:offset +131 assert first-sandbox, [!!] +132 sandbox-left-margin:num <- get *first-sandbox, left:offset +133 sandbox-right-margin:num <- get *first-sandbox, right:offset +134 edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin +135 edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right +136 return-unless edit-button-vertical-area?, 0/false +137 # finally, is sandbox editor empty? +138 current-sandbox:&:editor <- get *env, current-sandbox:offset +139 result <- empty-editor? current-sandbox +140 ] +141 +142 def try-edit-sandbox click-row:num, env:&:environment -> clicked-on-edit-button?:bool, env:&:environment [ +143 local-scope +144 load-ingredients +145 # identify the sandbox to edit, if the click was actually on the 'edit' button +146 sandbox:&:sandbox <- find-sandbox env, click-row +147 return-unless sandbox, 0/false +148 clicked-on-edit-button? <- copy 1/true +149 # 'edit' button = 'copy' button + 'delete' button +150 text:text <- get *sandbox, data:offset +151 current-sandbox:&:editor <- get *env, current-sandbox:offset +152 current-sandbox <- insert-text current-sandbox, text +153 env <- delete-sandbox env, sandbox +154 # reset scroll +155 *env <- put *env, render-from:offset, -1 +156 # position cursor in sandbox editor +157 *env <- put *env, sandbox-in-focus?:offset, 1/true +158 ] +159 +160 scenario sandbox-with-print-can-be-edited [ +161 local-scope +162 trace-until 100/app # trace too long +163 assume-screen 100/width, 20/height +164 # left editor is empty +165 assume-resources [ +166 ] +167 # right editor contains a print instruction +168 env:&:environment <- new-programming-environment resources, screen, [print screen, 4] +169 # run the sandbox +170 assume-console [ +171 ¦ press F4 +172 ] +173 event-loop screen, console, env, resources +174 screen-should-contain [ +175 ¦ . run (F4) . +176 ¦ . ╎ . +177 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +178 ¦ . ╎0 edit copy delete . +179 ¦ . ╎print screen, 4 . +180 ¦ . ╎screen: . +181 ¦ . ╎ .4 . . 182 ¦ . ╎ . . . 183 ¦ . ╎ . . . -184 ¦ . ╎─────────────────────────────────────────────────. -185 ¦ . ╎ . -186 ] -187 # edit the sandbox -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 # trace too long -206 assume-screen 100/width, 10/height -207 # initialize environment -208 assume-resources [ -209 ] -210 env:&:environment <- new-programming-environment resources, screen, [] -211 render-all screen, env, render -212 # create 2 sandboxes and scroll to second -213 assume-console [ -214 ¦ press ctrl-n -215 ¦ type [add 2, 2] -216 ¦ press F4 -217 ¦ type [add 1, 1] +184 ¦ . ╎ . . . +185 ¦ . ╎ . . . +186 ¦ . ╎─────────────────────────────────────────────────. +187 ¦ . ╎ . +188 ] +189 # edit the sandbox +190 assume-console [ +191 ¦ left-click 3, 65 +192 ] +193 run [ +194 ¦ event-loop screen, console, env, resources +195 ] +196 screen-should-contain [ +197 ¦ . run (F4) . +198 ¦ . ╎print screen, 4 . +199 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +200 ¦ . ╎ . +201 ¦ . ╎ . +202 ] +203 ] +204 +205 scenario editing-sandbox-after-scrolling-resets-scroll [ +206 local-scope +207 trace-until 100/app # trace too long +208 assume-screen 100/width, 10/height +209 # initialize environment +210 assume-resources [ +211 ] +212 env:&:environment <- new-programming-environment resources, screen, [] +213 render-all screen, env, render +214 # create 2 sandboxes and scroll to second +215 assume-console [ +216 ¦ press ctrl-n +217 ¦ type [add 2, 2] 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 delete . -227 ¦ . ╎add 2, 2 . -228 ¦ . ╎4 . -229 ¦ . ╎─────────────────────────────────────────────────. -230 ¦ . ╎ . -231 ] -232 # edit the second sandbox -233 assume-console [ -234 ¦ left-click 2, 55 -235 ] -236 run [ -237 ¦ event-loop screen, console, env, resources -238 ] -239 # second sandbox shows in editor; scroll resets to display first sandbox -240 screen-should-contain [ -241 ¦ . run (F4) . -242 ¦ . ╎add 2, 2 . -243 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -244 ¦ . ╎0 edit copy 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 # trace too long -255 assume-screen 100/width, 10/height -256 # initialize environment -257 assume-resources [ -258 ] -259 env:&:environment <- new-programming-environment resources, screen, [] -260 render-all screen, env, render -261 # create 2 sandboxes -262 assume-console [ -263 ¦ press ctrl-n -264 ¦ type [add 2, 2] -265 ¦ press F4 -266 ¦ type [add 1, 1] +219 ¦ type [add 1, 1] +220 ¦ press F4 +221 ¦ press page-down +222 ¦ press page-down +223 ] +224 event-loop screen, console, env, resources +225 screen-should-contain [ +226 ¦ . run (F4) . +227 ¦ . ╎─────────────────────────────────────────────────. +228 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +229 ¦ . ╎add 2, 2 . +230 ¦ . ╎4 . +231 ¦ . ╎─────────────────────────────────────────────────. +232 ¦ . ╎ . +233 ] +234 # edit the second sandbox +235 assume-console [ +236 ¦ left-click 2, 55 +237 ] +238 run [ +239 ¦ event-loop screen, console, env, resources +240 ] +241 # second sandbox shows in editor; scroll resets to display first sandbox +242 screen-should-contain [ +243 ¦ . run (F4) . +244 ¦ . ╎add 2, 2 . +245 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +246 ¦ . ╎0 edit copy delete . +247 ¦ . ╎add 1, 1 . +248 ¦ . ╎2 . +249 ¦ . ╎─────────────────────────────────────────────────. +250 ¦ . ╎ . +251 ] +252 ] +253 +254 scenario editing-sandbox-updates-sandbox-count [ +255 local-scope +256 trace-until 100/app # trace too long +257 assume-screen 100/width, 10/height +258 # initialize environment +259 assume-resources [ +260 ] +261 env:&:environment <- new-programming-environment resources, screen, [] +262 render-all screen, env, render +263 # create 2 sandboxes +264 assume-console [ +265 ¦ press ctrl-n +266 ¦ type [add 2, 2] 267 ¦ press F4 -268 ] -269 event-loop screen, console, env, resources -270 screen-should-contain [ -271 ¦ . run (F4) . -272 ¦ . ╎ . -273 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -274 ¦ . ╎0 edit copy delete . -275 ¦ . ╎add 1, 1 . -276 ¦ . ╎2 . -277 ¦ . ╎─────────────────────────────────────────────────. -278 ¦ . ╎1 edit copy delete . -279 ¦ . ╎add 2, 2 . -280 ¦ . ╎4 . -281 ] -282 # edit the second sandbox, then resave -283 assume-console [ -284 ¦ left-click 3, 60 -285 ¦ press F4 -286 ] -287 run [ -288 ¦ event-loop screen, console, env, resources -289 ] -290 # no change in contents -291 screen-should-contain [ -292 ¦ . run (F4) . -293 ¦ . ╎ . -294 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. -295 ¦ . ╎0 edit copy delete . -296 ¦ . ╎add 1, 1 . -297 ¦ . ╎2 . -298 ¦ . ╎─────────────────────────────────────────────────. -299 ¦ . ╎1 edit copy delete . -300 ¦ . ╎add 2, 2 . -301 ¦ . ╎4 . -302 ] -303 # now try to scroll past end -304 assume-console [ -305 ¦ press page-down -306 ¦ press page-down +268 ¦ type [add 1, 1] +269 ¦ press F4 +270 ] +271 event-loop screen, console, env, resources +272 screen-should-contain [ +273 ¦ . run (F4) . +274 ¦ . ╎ . +275 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +276 ¦ . ╎0 edit copy delete . +277 ¦ . ╎add 1, 1 . +278 ¦ . ╎2 . +279 ¦ . ╎─────────────────────────────────────────────────. +280 ¦ . ╎1 edit copy delete . +281 ¦ . ╎add 2, 2 . +282 ¦ . ╎4 . +283 ] +284 # edit the second sandbox, then resave +285 assume-console [ +286 ¦ left-click 3, 60 +287 ¦ press F4 +288 ] +289 run [ +290 ¦ event-loop screen, console, env, resources +291 ] +292 # no change in contents +293 screen-should-contain [ +294 ¦ . run (F4) . +295 ¦ . ╎ . +296 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────. +297 ¦ . ╎0 edit copy delete . +298 ¦ . ╎add 1, 1 . +299 ¦ . ╎2 . +300 ¦ . ╎─────────────────────────────────────────────────. +301 ¦ . ╎1 edit copy delete . +302 ¦ . ╎add 2, 2 . +303 ¦ . ╎4 . +304 ] +305 # now try to scroll past end +306 assume-console [ 307 ¦ press page-down -308 ] -309 run [ -310 ¦ event-loop screen, console, env, resources -311 ] -312 # screen should show just final sandbox with the right index (1) -313 screen-should-contain [ -314 ¦ . run (F4) . -315 ¦ . ╎─────────────────────────────────────────────────. -316 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . -317 ¦ . ╎add 2, 2 . -318 ¦ . ╎4 . -319 ¦ . ╎─────────────────────────────────────────────────. -320 ¦ . ╎ . -321 ] -322 ] +308 ¦ press page-down +309 ¦ press page-down +310 ] +311 run [ +312 ¦ event-loop screen, console, env, resources +313 ] +314 # screen should show just final sandbox with the right index (1) +315 screen-should-contain [ +316 ¦ . run (F4) . +317 ¦ . ╎─────────────────────────────────────────────────. +318 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete . +319 ¦ . ╎add 2, 2 . +320 ¦ . ╎4 . +321 ¦ . ╎─────────────────────────────────────────────────. +322 ¦ . ╎ . +323 ] +324 ] diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index baa7c1ba..80242905 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -174,7 +174,7 @@ if ('onhashchange' in window) { 111 ] 112 113 # clicks on sandbox responses save it as 'expected' -114 after <global-touch> [ +114 after <global-touch> [ 115 # check if it's inside the output of any sandbox 116 { 117 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset @@ -188,83 +188,85 @@ if ('onhashchange' in window) { 125 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins 126 ¦ break-unless below-sandbox-editor? 127 ¦ # identify the sandbox whose output is being clicked on -128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row +128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row 129 ¦ break-unless sandbox 130 ¦ # toggle its expected-response, and save session -131 ¦ sandbox <- toggle-expected-response sandbox +131 ¦ sandbox <- toggle-expected-response sandbox 132 ¦ save-sandboxes env, resources -133 ¦ screen <- render-sandbox-side screen, env, render -134 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -135 ¦ loop +next-event -136 } -137 ] -138 -139 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ -140 local-scope -141 load-ingredients -142 # assert click-row >= sandbox.starting-row-on-screen -143 sandbox:&:sandbox <- get *env, sandbox:offset -144 start:num <- get *sandbox, starting-row-on-screen:offset -145 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start -146 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] -147 # while click-row < sandbox.next-sandbox.starting-row-on-screen -148 { -149 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset -150 ¦ break-unless next-sandbox -151 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset -152 ¦ found?:bool <- lesser-than click-row, next-start -153 ¦ break-if found? -154 ¦ sandbox <- copy next-sandbox -155 ¦ loop -156 } -157 # return sandbox if click is in its output region -158 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset -159 return-unless response-starting-row, 0/no-click-in-sandbox-output -160 click-in-response?:bool <- greater-or-equal click-row, response-starting-row -161 return-unless click-in-response?, 0/no-click-in-sandbox-output -162 return sandbox -163 ] -164 -165 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ -166 local-scope -167 load-ingredients -168 expected-response:text <- get *sandbox, expected-response:offset -169 { -170 ¦ # if expected-response is set, reset -171 ¦ break-unless expected-response -172 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 -173 } -174 { -175 ¦ # if not, set expected response to the current response -176 ¦ break-if expected-response -177 ¦ response:text <- get *sandbox, response:offset -178 ¦ *sandbox <- put *sandbox, expected-response:offset, response -179 } -180 ] -181 -182 # when rendering a sandbox, color it in red/green if expected response exists -183 after <render-sandbox-response> [ -184 { -185 ¦ break-unless sandbox-response -186 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row -187 ¦ expected-response:text <- get *sandbox, expected-response:offset -188 ¦ break-unless expected-response # fall-through to print in grey -189 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response -190 ¦ { -191 ¦ ¦ break-if response-is-expected?:bool -192 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row -193 ¦ } -194 ¦ { -195 ¦ ¦ break-unless response-is-expected?:bool -196 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row -197 ¦ } -198 ¦ jump +render-sandbox-end -199 } -200 ] -201 -202 before <end-render-sandbox-reset-hidden> [ -203 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 -204 ] +133 ¦ hide-screen screen +134 ¦ screen <- render-sandbox-side screen, env, render +135 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +136 ¦ show-screen screen +137 ¦ loop +next-event +138 } +139 ] +140 +141 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ +142 local-scope +143 load-ingredients +144 # assert click-row >= sandbox.starting-row-on-screen +145 sandbox:&:sandbox <- get *env, sandbox:offset +146 start:num <- get *sandbox, starting-row-on-screen:offset +147 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start +148 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] +149 # while click-row < sandbox.next-sandbox.starting-row-on-screen +150 { +151 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset +152 ¦ break-unless next-sandbox +153 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset +154 ¦ found?:bool <- lesser-than click-row, next-start +155 ¦ break-if found? +156 ¦ sandbox <- copy next-sandbox +157 ¦ loop +158 } +159 # return sandbox if click is in its output region +160 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset +161 return-unless response-starting-row, 0/no-click-in-sandbox-output +162 click-in-response?:bool <- greater-or-equal click-row, response-starting-row +163 return-unless click-in-response?, 0/no-click-in-sandbox-output +164 return sandbox +165 ] +166 +167 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ +168 local-scope +169 load-ingredients +170 expected-response:text <- get *sandbox, expected-response:offset +171 { +172 ¦ # if expected-response is set, reset +173 ¦ break-unless expected-response +174 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 +175 } +176 { +177 ¦ # if not, set expected response to the current response +178 ¦ break-if expected-response +179 ¦ response:text <- get *sandbox, response:offset +180 ¦ *sandbox <- put *sandbox, expected-response:offset, response +181 } +182 ] +183 +184 # when rendering a sandbox, color it in red/green if expected response exists +185 after <render-sandbox-response> [ +186 { +187 ¦ break-unless sandbox-response +188 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row +189 ¦ expected-response:text <- get *sandbox, expected-response:offset +190 ¦ break-unless expected-response # fall-through to print in grey +191 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response +192 ¦ { +193 ¦ ¦ break-if response-is-expected?:bool +194 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row +195 ¦ } +196 ¦ { +197 ¦ ¦ break-unless response-is-expected?:bool +198 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row +199 ¦ } +200 ¦ jump +render-sandbox-end +201 } +202 ] +203 +204 before <end-render-sandbox-reset-hidden> [ +205 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 +206 ] diff --git a/html/edit/010-sandbox-trace.mu.html b/html/edit/010-sandbox-trace.mu.html index e1a98ad8..c1950605 100644 --- a/html/edit/010-sandbox-trace.mu.html +++ b/html/edit/010-sandbox-trace.mu.html @@ -243,7 +243,7 @@ if ('onhashchange' in window) { 180 ] 181 182 # clicks on sandbox code toggle its display-trace? flag -183 after <global-touch> [ +183 after <global-touch> [ 184 # check if it's inside the code of any sandbox 185 { 186 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset @@ -257,60 +257,62 @@ if ('onhashchange' in window) { 194 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins 195 ¦ break-unless below-sandbox-editor? 196 ¦ # identify the sandbox whose code is being clicked on -197 ¦ sandbox:&:sandbox <- find-click-in-sandbox-code env, click-row +197 ¦ sandbox:&:sandbox <- find-click-in-sandbox-code env, click-row 198 ¦ break-unless sandbox 199 ¦ # toggle its display-trace? property 200 ¦ x:bool <- get *sandbox, display-trace?:offset 201 ¦ x <- not x 202 ¦ *sandbox <- put *sandbox, display-trace?:offset, x -203 ¦ screen <- render-sandbox-side screen, env, render -204 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -205 ¦ loop +next-event -206 } -207 ] -208 -209 def find-click-in-sandbox-code env:&:environment, click-row:num -> sandbox:&:sandbox [ -210 local-scope -211 load-ingredients -212 # assert click-row >= sandbox.starting-row-on-screen -213 sandbox <- get *env, sandbox:offset -214 start:num <- get *sandbox, starting-row-on-screen:offset -215 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start -216 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] -217 # while click-row < sandbox.next-sandbox.starting-row-on-screen -218 { -219 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset -220 ¦ break-unless next-sandbox -221 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset -222 ¦ found?:bool <- lesser-than click-row, next-start -223 ¦ break-if found? -224 ¦ sandbox <- copy next-sandbox -225 ¦ loop -226 } -227 # return sandbox if click is in its code region -228 code-ending-row:num <- get *sandbox, code-ending-row-on-screen:offset -229 click-above-response?:bool <- lesser-than click-row, code-ending-row -230 start:num <- get *sandbox, starting-row-on-screen:offset -231 click-below-menu?:bool <- greater-than click-row, start -232 click-on-sandbox-code?:bool <- and click-above-response?, click-below-menu? -233 { -234 ¦ break-if click-on-sandbox-code? -235 ¦ return 0/no-click-in-sandbox-output -236 } -237 return sandbox -238 ] -239 -240 # when rendering a sandbox, dump its trace before response/warning if display-trace? property is set -241 after <render-sandbox-results> [ -242 { -243 ¦ display-trace?:bool <- get *sandbox, display-trace?:offset -244 ¦ break-unless display-trace? -245 ¦ sandbox-trace:text <- get *sandbox, trace:offset -246 ¦ break-unless sandbox-trace # nothing to print; move on -247 ¦ row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row -248 } -249 <render-sandbox-trace-done> -250 ] +203 ¦ hide-screen screen +204 ¦ screen <- render-sandbox-side screen, env, render +205 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +206 ¦ show-screen screen +207 ¦ loop +next-event +208 } +209 ] +210 +211 def find-click-in-sandbox-code env:&:environment, click-row:num -> sandbox:&:sandbox [ +212 local-scope +213 load-ingredients +214 # assert click-row >= sandbox.starting-row-on-screen +215 sandbox <- get *env, sandbox:offset +216 start:num <- get *sandbox, starting-row-on-screen:offset +217 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start +218 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] +219 # while click-row < sandbox.next-sandbox.starting-row-on-screen +220 { +221 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset +222 ¦ break-unless next-sandbox +223 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset +224 ¦ found?:bool <- lesser-than click-row, next-start +225 ¦ break-if found? +226 ¦ sandbox <- copy next-sandbox +227 ¦ loop +228 } +229 # return sandbox if click is in its code region +230 code-ending-row:num <- get *sandbox, code-ending-row-on-screen:offset +231 click-above-response?:bool <- lesser-than click-row, code-ending-row +232 start:num <- get *sandbox, starting-row-on-screen:offset +233 click-below-menu?:bool <- greater-than click-row, start +234 click-on-sandbox-code?:bool <- and click-above-response?, click-below-menu? +235 { +236 ¦ break-if click-on-sandbox-code? +237 ¦ return 0/no-click-in-sandbox-output +238 } +239 return sandbox +240 ] +241 +242 # when rendering a sandbox, dump its trace before response/warning if display-trace? property is set +243 after <render-sandbox-results> [ +244 { +245 ¦ display-trace?:bool <- get *sandbox, display-trace?:offset +246 ¦ break-unless display-trace? +247 ¦ sandbox-trace:text <- get *sandbox, trace:offset +248 ¦ break-unless sandbox-trace # nothing to print; move on +249 ¦ row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row +250 } +251 <render-sandbox-trace-done> +252 ] diff --git a/html/edit/011-errors.mu.html b/html/edit/011-errors.mu.html index f40faa20..4d09cebb 100644 --- a/html/edit/011-errors.mu.html +++ b/html/edit/011-errors.mu.html @@ -86,7 +86,7 @@ if ('onhashchange' in window) { 23 errors-found? <- copy 0/false 24 ] 25 - 26 before <render-components-end> [ + 26 before <render-components-end> [ 27 trace 11, [app], [render status] 28 recipe-errors:text <- get *env, recipe-errors:offset 29 { @@ -95,7 +95,7 @@ if ('onhashchange' in window) { 32 } 33 ] 34 - 35 before <render-recipe-components-end> [ + 35 before <render-recipe-components-end> [ 36 { 37 ¦ recipe-errors:text <- get *env, recipe-errors:offset 38 ¦ break-unless recipe-errors @@ -124,7 +124,7 @@ if ('onhashchange' in window) { 61 } 62 ] 63 - 64 before <render-components-end> [ + 64 before <render-components-end> [ 65 { 66 ¦ break-if recipe-errors 67 ¦ error-index:num <- get *env, error-index:offset @@ -166,7 +166,7 @@ if ('onhashchange' in window) { 103 ] 104 105 # make sure we render any trace -106 after <render-sandbox-trace-done> [ +106 after <render-sandbox-trace-done> [ 107 { 108 ¦ sandbox-errors:text <- get *sandbox, errors:offset 109 ¦ break-unless sandbox-errors @@ -189,7 +189,7 @@ if ('onhashchange' in window) { 126 ¦ ] 127 ] 128 env:&:environment <- new-programming-environment resources, screen, [foo] -129 render-all screen, env, render +129 render-all screen, env, render 130 screen-should-contain [ 131 ¦ . run (F4) . 132 ¦ .recipe foo [ ╎foo . diff --git a/html/edit/012-editor-undo.mu.html b/html/edit/012-editor-undo.mu.html index 2c227c0f..490d67f9 100644 --- a/html/edit/012-editor-undo.mu.html +++ b/html/edit/012-editor-undo.mu.html @@ -165,7 +165,7 @@ if ('onhashchange' in window) { 102 local-scope 103 # create an editor and type a character 104 assume-screen 10/width, 5/height - 105 e:&:editor <- new-editor [], 0/left, 10/right + 105 e:&:editor <- new-editor [], 0/left, 10/right 106 editor-render screen, e 107 assume-console [ 108 ¦ type [0] @@ -294,7 +294,7 @@ if ('onhashchange' in window) { 231 local-scope 232 # create an editor and type multiple characters 233 assume-screen 10/width, 5/height - 234 e:&:editor <- new-editor [], 0/left, 10/right + 234 e:&:editor <- new-editor [], 0/left, 10/right 235 editor-render screen, e 236 assume-console [ 237 ¦ type [012] @@ -320,7 +320,7 @@ if ('onhashchange' in window) { 257 local-scope 258 # create an editor with some text 259 assume-screen 10/width, 5/height - 260 e:&:editor <- new-editor [a], 0/left, 10/right + 260 e:&:editor <- new-editor [a], 0/left, 10/right 261 editor-render screen, e 262 # type some characters 263 assume-console [ @@ -366,7 +366,7 @@ if ('onhashchange' in window) { 303 local-scope 304 # create an editor with some text 305 assume-screen 10/width, 5/height - 306 e:&:editor <- new-editor [ abc], 0/left, 10/right + 306 e:&:editor <- new-editor [ abc], 0/left, 10/right 307 editor-render screen, e 308 # new line 309 assume-console [ @@ -429,7 +429,7 @@ if ('onhashchange' in window) { 366 local-scope 367 # create an editor, type something, undo 368 assume-screen 10/width, 5/height - 369 e:&:editor <- new-editor [a], 0/left, 10/right + 369 e:&:editor <- new-editor [a], 0/left, 10/right 370 editor-render screen, e 371 assume-console [ 372 ¦ type [012] @@ -493,7 +493,7 @@ if ('onhashchange' in window) { 430 local-scope 431 # create an editor, type something, undo 432 assume-screen 10/width, 5/height - 433 e:&:editor <- new-editor [], 0/left, 10/right + 433 e:&:editor <- new-editor [], 0/left, 10/right 434 editor-render screen, e 435 assume-console [ 436 ¦ type [012] @@ -542,7 +542,7 @@ if ('onhashchange' in window) { 479 contents:text <- new [abc 480 def 481 ghi] - 482 e:&:editor <- new-editor contents, 0/left, 10/right + 482 e:&:editor <- new-editor contents, 0/left, 10/right 483 editor-render screen, e 484 assume-console [ 485 ¦ type [1] @@ -582,7 +582,7 @@ if ('onhashchange' in window) { 519 local-scope 520 # create an editor 521 assume-screen 10/width, 5/height - 522 e:&:editor <- new-editor [], 0/left, 10/right + 522 e:&:editor <- new-editor [], 0/left, 10/right 523 editor-render screen, e 524 # insert some text and tabs, hit enter, some more text and tabs 525 assume-console [ @@ -742,7 +742,7 @@ if ('onhashchange' in window) { 679 contents:text <- new [abc 680 def 681 ghi] - 682 e:&:editor <- new-editor contents, 0/left, 10/right + 682 e:&:editor <- new-editor contents, 0/left, 10/right 683 editor-render screen, e 684 # move the cursor 685 assume-console [ @@ -834,7 +834,7 @@ if ('onhashchange' in window) { 771 contents:text <- new [a 772 b 773 cdefgh] - 774 e:&:editor <- new-editor contents, 0/left, 5/right + 774 e:&:editor <- new-editor contents, 0/left, 5/right 775 # position cursor at end of screen and try to move right 776 assume-console [ 777 ¦ left-click 3, 3 @@ -897,7 +897,7 @@ if ('onhashchange' in window) { 834 contents:text <- new [abc 835 def 836 ghi] - 837 e:&:editor <- new-editor contents, 0/left, 10/right + 837 e:&:editor <- new-editor contents, 0/left, 10/right 838 editor-render screen, e 839 # move the cursor 840 assume-console [ @@ -942,7 +942,7 @@ if ('onhashchange' in window) { 879 contents:text <- new [abc 880 def 881 ghi] - 882 e:&:editor <- new-editor contents, 0/left, 10/right + 882 e:&:editor <- new-editor contents, 0/left, 10/right 883 editor-render screen, e 884 # move the cursor 885 assume-console [ @@ -993,7 +993,7 @@ if ('onhashchange' in window) { 930 contents:text <- new [abc 931 def 932 ghi] - 933 e:&:editor <- new-editor contents, 0/left, 10/right + 933 e:&:editor <- new-editor contents, 0/left, 10/right 934 editor-render screen, e 935 # move the cursor 936 assume-console [ @@ -1041,7 +1041,7 @@ if ('onhashchange' in window) { 978 d 979 e 980 f] - 981 e:&:editor <- new-editor contents, 0/left, 10/right + 981 e:&:editor <- new-editor contents, 0/left, 10/right 982 editor-render screen, e 983 # scroll the page 984 assume-console [ @@ -1075,7 +1075,7 @@ if ('onhashchange' in window) { 1012 d 1013 e 1014 f] -1015 e:&:editor <- new-editor contents, 0/left, 10/right +1015 e:&:editor <- new-editor contents, 0/left, 10/right 1016 editor-render screen, e 1017 # scroll the page 1018 assume-console [ @@ -1109,7 +1109,7 @@ if ('onhashchange' in window) { 1046 d 1047 e 1048 f] -1049 e:&:editor <- new-editor contents, 0/left, 10/right +1049 e:&:editor <- new-editor contents, 0/left, 10/right 1050 editor-render screen, e 1051 # scroll the page down and up 1052 assume-console [ @@ -1144,7 +1144,7 @@ if ('onhashchange' in window) { 1081 d 1082 e 1083 f] -1084 e:&:editor <- new-editor contents, 0/left, 10/right +1084 e:&:editor <- new-editor contents, 0/left, 10/right 1085 editor-render screen, e 1086 # scroll the page down and up 1087 assume-console [ @@ -1176,7 +1176,7 @@ if ('onhashchange' in window) { 1113 contents:text <- new [abc 1114 def 1115 ghi] -1116 e:&:editor <- new-editor contents, 0/left, 10/right +1116 e:&:editor <- new-editor contents, 0/left, 10/right 1117 editor-render screen, e 1118 # move the cursor, then to start of line 1119 assume-console [ @@ -1221,7 +1221,7 @@ if ('onhashchange' in window) { 1158 contents:text <- new [abc 1159 def 1160 ghi] -1161 e:&:editor <- new-editor contents, 0/left, 10/right +1161 e:&:editor <- new-editor contents, 0/left, 10/right 1162 editor-render screen, e 1163 # move the cursor, then to start of line 1164 assume-console [ @@ -1266,7 +1266,7 @@ if ('onhashchange' in window) { 1203 contents:text <- new [abc 1204 def 1205 ghi] -1206 e:&:editor <- new-editor contents, 0/left, 10/right +1206 e:&:editor <- new-editor contents, 0/left, 10/right 1207 editor-render screen, e 1208 # move the cursor, then to start of line 1209 assume-console [ @@ -1311,7 +1311,7 @@ if ('onhashchange' in window) { 1248 contents:text <- new [abc 1249 def 1250 ghi] -1251 e:&:editor <- new-editor contents, 0/left, 10/right +1251 e:&:editor <- new-editor contents, 0/left, 10/right 1252 editor-render screen, e 1253 # move the cursor, then to start of line 1254 assume-console [ @@ -1356,7 +1356,7 @@ if ('onhashchange' in window) { 1293 contents:text <- new [abc 1294 def 1295 ghi] -1296 e:&:editor <- new-editor contents, 0/left, 10/right +1296 e:&:editor <- new-editor contents, 0/left, 10/right 1297 editor-render screen, e 1298 # move the cursor 1299 assume-console [ @@ -1411,7 +1411,7 @@ if ('onhashchange' in window) { 1348 contents:text <- new [abc 1349 def 1350 ghi] -1351 e:&:editor <- new-editor contents, 0/left, 10/right +1351 e:&:editor <- new-editor contents, 0/left, 10/right 1352 editor-render screen, e 1353 assume-console [ 1354 ¦ left-click 3, 1 @@ -1466,7 +1466,7 @@ if ('onhashchange' in window) { 1403 local-scope 1404 # create an editor, type some text, move the cursor, type some more text 1405 assume-screen 10/width, 5/height -1406 e:&:editor <- new-editor [], 0/left, 10/right +1406 e:&:editor <- new-editor [], 0/left, 10/right 1407 editor-render screen, e 1408 assume-console [ 1409 ¦ type [abc] @@ -1615,7 +1615,7 @@ if ('onhashchange' in window) { 1552 local-scope 1553 # create an editor 1554 assume-screen 10/width, 5/height -1555 e:&:editor <- new-editor [], 0/left, 10/right +1555 e:&:editor <- new-editor [], 0/left, 10/right 1556 editor-render screen, e 1557 # insert some text and hit backspace 1558 assume-console [ @@ -1760,7 +1760,7 @@ if ('onhashchange' in window) { 1697 local-scope 1698 # create an editor 1699 assume-screen 10/width, 5/height -1700 e:&:editor <- new-editor [], 0/left, 10/right +1700 e:&:editor <- new-editor [], 0/left, 10/right 1701 editor-render screen, e 1702 # insert some text and hit delete and backspace a few times 1703 assume-console [ @@ -1951,7 +1951,7 @@ if ('onhashchange' in window) { 1888 assume-screen 10/width, 5/height 1889 contents:text <- new [abc 1890 def] -1891 e:&:editor <- new-editor contents, 0/left, 10/right +1891 e:&:editor <- new-editor contents, 0/left, 10/right 1892 editor-render screen, e 1893 # insert some text and hit delete and backspace a few times 1894 assume-console [ @@ -2054,7 +2054,7 @@ if ('onhashchange' in window) { 1991 assume-screen 10/width, 5/height 1992 contents:text <- new [abc 1993 def] -1994 e:&:editor <- new-editor contents, 0/left, 10/right +1994 e:&:editor <- new-editor contents, 0/left, 10/right 1995 editor-render screen, e 1996 # insert some text and hit delete and backspace a few times 1997 assume-console [ @@ -2154,7 +2154,7 @@ if ('onhashchange' in window) { 2091 local-scope 2092 # create an editor 2093 assume-screen 10/width, 5/height -2094 e:&:editor <- new-editor [], 0/left, 10/right +2094 e:&:editor <- new-editor [], 0/left, 10/right 2095 editor-render screen, e 2096 # insert some text and hit delete and backspace a few times 2097 assume-console [ -- cgit 1.4.1-2-gfad0