From f918675c8b11adb80a83000a3a984e4ff3bdcf1b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 23 Oct 2016 19:45:36 -0700 Subject: 3569 Update syntax highlighting to not color numeric locations like literals. --- html/edit/001-editor.mu.html | 232 ++-- html/edit/002-typing.mu.html | 596 +++++------ html/edit/003-shortcuts.mu.html | 1418 ++++++++++++------------- html/edit/004-programming-environment.mu.html | 414 ++++---- html/edit/005-sandbox.mu.html | 474 ++++----- html/edit/006-sandbox-copy.mu.html | 90 +- html/edit/007-sandbox-delete.mu.html | 84 +- html/edit/008-sandbox-edit.mu.html | 64 +- html/edit/009-sandbox-test.mu.html | 80 +- html/edit/010-sandbox-trace.mu.html | 90 +- html/edit/011-errors.mu.html | 132 +-- html/edit/012-editor-undo.mu.html | 888 ++++++++-------- 12 files changed, 2281 insertions(+), 2281 deletions(-) (limited to 'html/edit') diff --git a/html/edit/001-editor.mu.html b/html/edit/001-editor.mu.html index a0044e7a..01b0bf0a 100644 --- a/html/edit/001-editor.mu.html +++ b/html/edit/001-editor.mu.html @@ -87,22 +87,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # no clipping of bounds - right <- subtract right, 1 - result <- new editor:type + right <- subtract right, 1 + result <- new editor:type # initialize screen-related fields - *result <- put *result, left:offset, left - *result <- put *result, right:offset, right + *result <- put *result, left:offset, left + *result <- put *result, right:offset, right # initialize cursor coordinates - *result <- put *result, cursor-row:offset, 1/top - *result <- put *result, cursor-column:offset, left + *result <- put *result, cursor-row:offset, 1/top + *result <- put *result, cursor-column:offset, left # initialize empty contents - init:&:duplex-list:char <- push 167/§, 0/tail - *result <- put *result, data:offset, init - *result <- put *result, top-of-screen:offset, init - *result <- put *result, before-cursor:offset, init - result <- insert-text result, s + init:&:duplex-list:char <- push 167/§, 0/tail + *result <- put *result, data:offset, init + *result <- put *result, top-of-screen:offset, init + *result <- put *result, before-cursor:offset, init + result <- insert-text result, s # initial render to screen, just for some old tests - _, _, screen, result <- render screen, result + _, _, screen, result <- render screen, result <editor-initialization> ] @@ -110,42 +110,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # early exit if text is empty - return-unless text, editor/same-as-ingredient:0 - len:num <- length *text - return-unless len, editor/same-as-ingredient:0 - idx:num <- copy 0 + return-unless text, editor/same-as-ingredient:0 + len:num <- length *text + return-unless len, editor/same-as-ingredient:0 + idx:num <- copy 0 # now we can start appending the rest, character by character - curr:&:duplex-list:char <- get *editor, data:offset + curr:&:duplex-list:char <- get *editor, data:offset { - done?:bool <- greater-or-equal idx, len + done?:bool <- greater-or-equal idx, len break-if done? - c:char <- index *text, idx + c:char <- index *text, idx insert c, curr # next iter - curr <- next curr - idx <- add idx, 1 + curr <- next curr + idx <- add idx, 1 loop } - return editor/same-as-ingredient:0 + return editor/same-as-ingredient:0 ] scenario editor-initializes-without-data [ local-scope assume-screen 5/width, 3/height run [ - e:&:editor <- new-editor 0/data, screen:&:screen, 2/left, 5/right - 2:editor/raw <- copy *e + e:&:editor <- new-editor 0/data, screen:&:screen, 2/left, 5/right + 2:editor/raw <- copy *e ] memory-should-contain [ # 2 (data) <- just the § sentinel # 3 (top of screen) <- the § sentinel - 4 <- 0 # bottom-of-screen; null since text fits on screen + 4 <- 0 # bottom-of-screen; null since text fits on screen # 5 (before cursor) <- the § sentinel - 6 <- 2 # left - 7 <- 4 # right (inclusive) - 8 <- 1 # bottom - 9 <- 1 # cursor row - 10 <- 2 # cursor column + 6 <- 2 # left + 7 <- 4 # right (inclusive) + 8 <- 1 # bottom + 9 <- 1 # cursor row + 10 <- 2 # cursor column ] screen-should-contain [ . . @@ -160,102 +160,102 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ local-scope load-ingredients - return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 - left:num <- get *editor, left:offset - screen-height:num <- screen-height screen - right:num <- get *editor, right:offset + return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + left:num <- get *editor, left:offset + screen-height:num <- screen-height screen + right:num <- get *editor, right:offset # traversing editor - curr:&:duplex-list:char <- get *editor, top-of-screen:offset - prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev - curr <- next curr + curr:&:duplex-list:char <- get *editor, top-of-screen:offset + prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev + curr <- next curr # traversing screen +render-loop-initialization - color:num <- copy 7/white - row:num <- copy 1/top - column:num <- copy left - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - screen <- move-cursor screen, row, column + color:num <- copy 7/white + row:num <- copy 1/top + column:num <- copy left + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + screen <- move-cursor screen, row, column { +next-character break-unless curr - off-screen?:bool <- greater-or-equal row, screen-height + off-screen?:bool <- greater-or-equal row, screen-height break-if off-screen? # update editor.before-cursor # Doing so at the start of each iteration ensures it stays one step behind # the current character. { - at-cursor-row?:bool <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - at-cursor?:bool <- equal column, cursor-column + at-cursor?:bool <- equal column, cursor-column break-unless at-cursor? - before-cursor <- copy prev + before-cursor <- copy prev } - c:char <- get *curr, value:offset + c:char <- get *curr, value:offset <character-c-received> { # newline? move to left rather than 0 - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # adjust cursor if necessary { - at-cursor-row?:bool <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - left-of-cursor?:bool <- lesser-than column, cursor-column + left-of-cursor?:bool <- lesser-than column, cursor-column break-unless left-of-cursor? - cursor-column <- copy column - before-cursor <- prev curr + cursor-column <- copy column + before-cursor <- prev curr } # clear rest of line in this window clear-line-until screen, right # skip to next line - row <- add row, 1 - column <- copy left - screen <- move-cursor screen, row, column - curr <- next curr - prev <- next prev + row <- add row, 1 + column <- copy left + screen <- move-cursor screen, row, column + curr <- next curr + prev <- next prev loop +next-character } { # at right? wrap. even if there's only one more letter left; we need # room for clicking on the cursor after it. - at-right?:bool <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? # print wrap icon - wrap-icon:char <- copy 8617/loop-back-to-left + wrap-icon:char <- copy 8617/loop-back-to-left print screen, wrap-icon, 245/grey - column <- copy left - row <- add row, 1 - screen <- move-cursor screen, row, column + column <- copy left + row <- add row, 1 + screen <- move-cursor screen, row, column # don't increment curr loop +next-character } print screen, c, color - curr <- next curr - prev <- next prev - column <- add column, 1 + curr <- next curr + prev <- next prev + column <- add column, 1 loop } # save first character off-screen - *editor <- put *editor, bottom-of-screen:offset, curr + *editor <- put *editor, bottom-of-screen:offset, curr # is cursor to the right of the last line? move to end { - at-cursor-row?:bool <- equal row, cursor-row - cursor-outside-line?:bool <- lesser-or-equal column, cursor-column - before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? - above-cursor-row?:bool <- lesser-than row, cursor-row - before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? + at-cursor-row?:bool <- equal row, cursor-row + cursor-outside-line?:bool <- lesser-or-equal column, cursor-column + before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? + above-cursor-row?:bool <- lesser-than row, cursor-row + before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? break-unless before-cursor? - cursor-row <- copy row - cursor-column <- copy column - before-cursor <- copy prev + cursor-row <- copy row + cursor-column <- copy column + before-cursor <- copy prev } - *editor <- put *editor, bottom:offset, row - *editor <- put *editor, cursor-row:offset, cursor-row - *editor <- put *editor, cursor-column:offset, cursor-column - *editor <- put *editor, before-cursor:offset, before-cursor - return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + *editor <- put *editor, bottom:offset, row + *editor <- put *editor, cursor-row:offset, cursor-row + *editor <- put *editor, cursor-column:offset, cursor-column + *editor <- put *editor, before-cursor:offset, before-cursor + return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [ @@ -265,27 +265,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { break-if screen clear-display-from row, column, left, right - return screen/same-as-ingredient:0 + return screen/same-as-ingredient:0 } # if not, go the slower route - screen <- move-cursor screen, row, column + screen <- move-cursor screen, row, column clear-line-until screen, right clear-rest-of-screen screen, row, left, right - return screen/same-as-ingredient:0 + return screen/same-as-ingredient:0 ] def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ local-scope load-ingredients - row <- add row, 1 - screen <- move-cursor screen, row, left - screen-height:num <- screen-height screen + row <- add row, 1 + screen <- move-cursor screen, row, left + screen-height:num <- screen-height screen { - at-bottom-of-screen?:bool <- greater-or-equal row, screen-height + at-bottom-of-screen?:bool <- greater-or-equal row, screen-height break-if at-bottom-of-screen? - screen <- move-cursor screen, row, left + screen <- move-cursor screen, row, left clear-line-until screen, right - row <- add row, 1 + row <- add row, 1 loop } ] @@ -294,7 +294,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abc + s:text <- new [abc def] new-editor s, screen:&:screen, 0/left, 5/right ] @@ -310,7 +310,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abc] + s:text <- new [abc] new-editor s, screen:&:screen, 1/left, 5/right ] screen-should-contain [ @@ -324,7 +324,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abc + s:text <- new [abc def] new-editor s, screen:&:screen, 1/left, 5/right ] @@ -340,7 +340,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abc def] + s:text <- new [abc def] new-editor s, screen:&:screen, 0/left, 5/right ] screen-should-contain [ @@ -361,7 +361,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abcde] + s:text <- new [abcde] new-editor s, screen:&:screen, 0/left, 5/right ] # still wrap, even though the line would fit. We need room to click on the @@ -384,9 +384,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - e:&:editor <- new-editor [], screen:&:screen, 0/left, 5/right - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + e:&:editor <- new-editor [], screen:&:screen, 0/left, 5/right + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -394,8 +394,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 # cursor row - 4 <- 0 # cursor column + 3 <- 1 # cursor row + 4 <- 0 # cursor column ] ] @@ -405,7 +405,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 5/width, 5/height run [ - s:text <- new [abc + s:text <- new [abc # de f] new-editor s, screen:&:screen, 0/left, 5/right @@ -434,48 +434,48 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <character-c-received> [ - color <- get-color color, c + color <- get-color color, c ] # so far the previous color is all the information we need; that may change def get-color color:num, c:char -> color:num [ local-scope load-ingredients - color-is-white?:bool <- equal color, 7/white + color-is-white?:bool <- equal color, 7/white # if color is white and next character is '#', switch color to blue { break-unless color-is-white? - starting-comment?:bool <- equal c, 35/# + starting-comment?:bool <- equal c, 35/# break-unless starting-comment? - trace 90, [app], [switch color back to blue] - color <- copy 12/lightblue + trace 90, [app], [switch color back to blue] + color <- copy 12/lightblue jump +exit } # if color is blue and next character is newline, switch color to white { - color-is-blue?:bool <- equal color, 12/lightblue + color-is-blue?:bool <- equal color, 12/lightblue break-unless color-is-blue? - ending-comment?:bool <- equal c, 10/newline + ending-comment?:bool <- equal c, 10/newline break-unless ending-comment? - trace 90, [app], [switch color back to white] - color <- copy 7/white + trace 90, [app], [switch color back to white] + color <- copy 7/white jump +exit } # if color is white (no comments) and next character is '<', switch color to red { break-unless color-is-white? - starting-assignment?:bool <- equal c, 60/< + starting-assignment?:bool <- equal c, 60/< break-unless starting-assignment? - color <- copy 1/red + color <- copy 1/red jump +exit } # if color is red and next character is space, switch color to white { - color-is-red?:bool <- equal color, 1/red + color-is-red?:bool <- equal color, 1/red break-unless color-is-red? - ending-assignment?:bool <- equal c, 32/space + ending-assignment?:bool <- equal c, 32/space break-unless ending-assignment? - color <- copy 7/white + color <- copy 7/white jump +exit } # otherwise no change @@ -487,7 +487,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 8/width, 5/height run [ - s:text <- new [abc + s:text <- new [abc d <- e f] new-editor s, screen:&:screen, 0/left, 8/right diff --git a/html/edit/002-typing.mu.html b/html/edit/002-typing.mu.html index 325e7f6e..dbca61b2 100644 --- a/html/edit/002-typing.mu.html +++ b/html/edit/002-typing.mu.html @@ -41,7 +41,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients open-console - editor:&:editor <- new-editor text, 0/screen, 5/left, 45/right + editor:&:editor <- new-editor text, 0/screen, 5/left, 45/right editor-event-loop 0/screen, 0/console, editor close-console ] @@ -52,15 +52,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { # looping over each (keyboard or touch) event as it occurs +next-event - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - screen <- move-cursor screen, cursor-row, cursor-column - e:event, found?:bool, quit?:bool, console <- read-event console + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + screen <- move-cursor screen, cursor-row, cursor-column + e:event, found?:bool, quit?:bool, console <- read-event console loop-unless found? break-if quit? # only in tests - trace 10, [app], [next-event] + trace 10, [app], [next-event] # 'touch' event - t:touch-event, is-touch?:bool <- maybe-convert e, touch:variant + t:touch-event, is-touch?:bool <- maybe-convert e, touch:variant { break-unless is-touch? move-cursor-in-editor screen, editor, t @@ -69,10 +69,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # keyboard events { break-if is-touch? - screen, editor, go-render?:bool <- handle-keyboard-event screen, editor, e + screen, editor, go-render?:bool <- handle-keyboard-event screen, editor, e { break-unless go-render? - screen <- editor-render screen, editor + screen <- editor-render screen, editor } } loop @@ -84,19 +84,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients return-unless editor, 0/false - click-row:num <- get t, row:offset + click-row:num <- get t, row:offset return-unless click-row, 0/false # ignore clicks on 'menu' - click-column:num <- get t, column:offset - left:num <- get *editor, left:offset - too-far-left?:bool <- lesser-than click-column, left + click-column:num <- get t, column:offset + left:num <- get *editor, left:offset + too-far-left?:bool <- lesser-than click-column, left return-if too-far-left?, 0/false - right:num <- get *editor, right:offset - too-far-right?:bool <- greater-than click-column, right + right:num <- get *editor, right:offset + too-far-right?:bool <- greater-than click-column, right return-if too-far-right?, 0/false # position cursor <move-cursor-begin> - editor <- snap-cursor screen, editor, click-row, click-column - undo-coalesce-tag:num <- copy 0/never + editor <- snap-cursor screen, editor, click-row, click-column + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> # gain focus return 1/true @@ -109,88 +109,88 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients return-unless editor - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - screen-height:num <- screen-height screen + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + screen-height:num <- screen-height screen # count newlines until screen row - curr:&:duplex-list:char <- get *editor, top-of-screen:offset - prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev - curr <- next curr - row:num <- copy 1/top - column:num <- copy left - *editor <- put *editor, cursor-row:offset, target-row - cursor-row:num <- copy target-row - *editor <- put *editor, cursor-column:offset, target-column - cursor-column:num <- copy target-column - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + curr:&:duplex-list:char <- get *editor, top-of-screen:offset + prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev + curr <- next curr + row:num <- copy 1/top + column:num <- copy left + *editor <- put *editor, cursor-row:offset, target-row + cursor-row:num <- copy target-row + *editor <- put *editor, cursor-column:offset, target-column + cursor-column:num <- copy target-column + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset { +next-character break-unless curr - off-screen?:bool <- greater-or-equal row, screen-height + off-screen?:bool <- greater-or-equal row, screen-height break-if off-screen? # update editor.before-cursor # Doing so at the start of each iteration ensures it stays one step behind # the current character. { - at-cursor-row?:bool <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - at-cursor?:bool <- equal column, cursor-column + at-cursor?:bool <- equal column, cursor-column break-unless at-cursor? - before-cursor <- copy prev - *editor <- put *editor, before-cursor:offset, before-cursor + before-cursor <- copy prev + *editor <- put *editor, before-cursor:offset, before-cursor } - c:char <- get *curr, value:offset + c:char <- get *curr, value:offset { # newline? move to left rather than 0 - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # adjust cursor if necessary { - at-cursor-row?:bool <- equal row, cursor-row + at-cursor-row?:bool <- equal row, cursor-row break-unless at-cursor-row? - left-of-cursor?:bool <- lesser-than column, cursor-column + left-of-cursor?:bool <- lesser-than column, cursor-column break-unless left-of-cursor? - cursor-column <- copy column - *editor <- put *editor, cursor-column:offset, cursor-column - before-cursor <- copy prev - *editor <- put *editor, before-cursor:offset, before-cursor + cursor-column <- copy column + *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- copy prev + *editor <- put *editor, before-cursor:offset, before-cursor } # skip to next line - row <- add row, 1 - column <- copy left - curr <- next curr - prev <- next prev + row <- add row, 1 + column <- copy left + curr <- next curr + prev <- next prev loop +next-character } { # at right? wrap. even if there's only one more letter left; we need # room for clicking on the cursor after it. - at-right?:bool <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? - column <- copy left - row <- add row, 1 + column <- copy left + row <- add row, 1 # don't increment curr/prev loop +next-character } - curr <- next curr - prev <- next prev - column <- add column, 1 + curr <- next curr + prev <- next prev + column <- add column, 1 loop } # is cursor to the right of the last line? move to end { - at-cursor-row?:bool <- equal row, cursor-row - cursor-outside-line?:bool <- lesser-or-equal column, cursor-column - before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? - above-cursor-row?:bool <- lesser-than row, cursor-row - before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? + at-cursor-row?:bool <- equal row, cursor-row + cursor-outside-line?:bool <- lesser-or-equal column, cursor-column + before-cursor-on-same-line?:bool <- and at-cursor-row?, cursor-outside-line? + above-cursor-row?:bool <- lesser-than row, cursor-row + before-cursor?:bool <- or before-cursor-on-same-line?, above-cursor-row? break-unless before-cursor? - cursor-row <- copy row - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- copy column - *editor <- put *editor, cursor-column:offset, cursor-column - before-cursor <- copy prev - *editor <- put *editor, before-cursor:offset, before-cursor + cursor-row <- copy row + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- copy column + *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- copy prev + *editor <- put *editor, before-cursor:offset, before-cursor } ] @@ -199,105 +199,105 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> screen:&:screen, editor:&:editor, go-render?:bool [ local-scope load-ingredients - go-render? <- copy 0/false + go-render? <- copy 0/false return-unless editor - screen-width:num <- screen-width screen - screen-height:num <- screen-height screen - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - save-row:num <- copy cursor-row - save-column:num <- copy cursor-column + screen-width:num <- screen-width screen + screen-height:num <- screen-height screen + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + save-row:num <- copy cursor-row + save-column:num <- copy cursor-column # character { - c:char, is-unicode?:bool <- maybe-convert e, text:variant + c:char, is-unicode?:bool <- maybe-convert e, text:variant break-unless is-unicode? - trace 10, [app], [handle-keyboard-event: special character] + trace 10, [app], [handle-keyboard-event: special character] # exceptions for special characters go here <handle-special-character> # ignore any other special characters - regular-character?:bool <- greater-or-equal c, 32/space - go-render? <- copy 0/false + regular-character?:bool <- greater-or-equal c, 32/space + go-render? <- copy 0/false return-unless regular-character? # otherwise type it in <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, c, screen + editor, screen, go-render?:bool <- insert-at-cursor editor, c, screen <insert-character-end> return } # special key to modify the text or move the cursor - k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant + k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant assert is-keycode?, [event was of unknown type; neither keyboard nor mouse] # handlers for each special key will go here <handle-special-key> - go-render? <- copy 1/true + go-render? <- copy 1/true return ] def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset insert c, before-cursor - before-cursor <- next before-cursor - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - save-row:num <- copy cursor-row - save-column:num <- copy cursor-column - screen-width:num <- screen-width screen - screen-height:num <- screen-height screen + before-cursor <- next before-cursor + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + save-row:num <- copy cursor-row + save-column:num <- copy cursor-column + screen-width:num <- screen-width screen + screen-height:num <- screen-height screen # occasionally we'll need to mess with the cursor <insert-character-special-case> # but mostly we'll just move the cursor right - cursor-column <- add cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column - next:&:duplex-list:char <- next before-cursor + cursor-column <- add cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column + next:&:duplex-list:char <- next before-cursor { # at end of all text? no need to scroll? just print the character and leave - at-end?:bool <- equal next, 0/null + at-end?:bool <- equal next, 0/null break-unless at-end? - bottom:num <- subtract screen-height, 1 - at-bottom?:bool <- equal save-row, bottom - at-right?:bool <- equal save-column, right - overflow?:bool <- and at-bottom?, at-right? + bottom:num <- subtract screen-height, 1 + at-bottom?:bool <- equal save-row, bottom + at-right?:bool <- equal save-column, right + overflow?:bool <- and at-bottom?, at-right? break-if overflow? move-cursor screen, save-row, save-column print screen, c - go-render? <- copy 0/false + go-render? <- copy 0/false return } { # not at right margin? print the character and rest of line break-unless next - at-right?:bool <- greater-or-equal cursor-column, screen-width + at-right?:bool <- greater-or-equal cursor-column, screen-width break-if at-right? - curr:&:duplex-list:char <- copy before-cursor + curr:&:duplex-list:char <- copy before-cursor move-cursor screen, save-row, save-column - curr-column:num <- copy save-column + curr-column:num <- copy save-column { # hit right margin? give up and let caller render - go-render? <- copy 1/true - at-right?:bool <- greater-than curr-column, right + go-render? <- copy 1/true + at-right?:bool <- greater-than curr-column, right return-if at-right? break-unless curr # newline? done. - currc:char <- get *curr, value:offset - at-newline?:bool <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? print screen, currc - curr-column <- add curr-column, 1 - curr <- next curr + curr-column <- add curr-column, 1 + curr <- next curr loop } - go-render? <- copy 0/false + go-render? <- copy 0/false return } - go-render? <- copy 1/true + go-render? <- copy 1/true return ] @@ -305,20 +305,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def editor-render screen:&:screen, editor:&:editor -> screen:&:screen, editor:&:editor [ local-scope load-ingredients - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - row:num, column:num <- render screen, editor + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + row:num, column:num <- render screen, editor clear-line-until screen, right - row <- add row, 1 + row <- add row, 1 draw-horizontal screen, row, left, right, 9480/horizontal-dotted - row <- add row, 1 + row <- add row, 1 clear-screen-from screen, row, left, left, right ] scenario editor-handles-empty-event-queue [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e assume-console [] run [ @@ -335,16 +335,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-mouse-clicks [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 1 # on the 'b' + left-click 1, 1 # on the 'b' ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -353,91 +353,91 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 # cursor is at row 0.. - 4 <- 1 # ..and column 1 + 3 <- 1 # cursor is at row 0.. + 4 <- 1 # ..and column 1 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-handles-mouse-clicks-outside-text [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right $clear-trace assume-console [ - left-click 1, 7 # last line, to the right of text + left-click 1, 7 # last line, to the right of text ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 # cursor row - 4 <- 3 # cursor column + 3 <- 1 # cursor row + 4 <- 3 # cursor column ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-handles-mouse-clicks-outside-text-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right $clear-trace assume-console [ - left-click 1, 7 # interior line, to the right of text + left-click 1, 7 # interior line, to the right of text ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 # cursor row - 4 <- 3 # cursor column + 3 <- 1 # cursor row + 4 <- 3 # cursor column ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-handles-mouse-clicks-outside-text-3 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right $clear-trace assume-console [ - left-click 3, 7 # below text + left-click 3, 7 # below text ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 # cursor row - 4 <- 3 # cursor column + 3 <- 2 # cursor row + 4 <- 3 # cursor column ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-handles-mouse-clicks-outside-column [ local-scope assume-screen 10/width, 5/height # editor occupies only left half of screen - e:&:editor <- new-editor [abc], screen, 0/left, 5/right + e:&:editor <- new-editor [abc], screen, 0/left, 5/right editor-render screen, e $clear-trace assume-console [ # click on right half of screen - left-click 3, 8 + left-click 3, 8 ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -446,38 +446,38 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 # no change to cursor row - 4 <- 0 # ..or column + 3 <- 1 # no change to cursor row + 4 <- 0 # ..or column ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-handles-mouse-clicks-in-menu-area [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 5/right + e:&:editor <- new-editor [abc], screen, 0/left, 5/right editor-render screen, e $clear-trace assume-console [ # click on first, 'menu' row - left-click 0, 3 + left-click 0, 3 ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # no change to cursor memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] ] scenario editor-inserts-characters-into-empty-editor [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 5/right + e:&:editor <- new-editor [], screen, 0/left, 5/right editor-render screen, e $clear-trace assume-console [ @@ -492,19 +492,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌ . . . ] - check-trace-count-for-label 3, [print-character] + check-trace-count-for-label 3, [print-character] ] scenario editor-inserts-characters-at-cursor [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace # type two letters at different places assume-console [ type [0] - left-click 1, 2 + left-click 1, 2 type [d] ] run [ @@ -516,17 +516,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 7, [print-character] # 4 for first letter, 3 for second + check-trace-count-for-label 7, [print-character] # 4 for first letter, 3 for second ] scenario editor-inserts-characters-at-cursor-2 [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 5 # right of last line + left-click 1, 5 # right of last line type [d] ] run [ @@ -538,19 +538,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 1, [print-character] + check-trace-count-for-label 1, [print-character] ] scenario editor-inserts-characters-at-cursor-5 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 5 # right of non-last line + left-click 1, 5 # right of non-last line type [e] ] run [ @@ -563,17 +563,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 1, [print-character] + check-trace-count-for-label 1, [print-character] ] scenario editor-inserts-characters-at-cursor-3 [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 3, 5 # below all text + left-click 3, 5 # below all text type [d] ] run [ @@ -585,19 +585,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 1, [print-character] + check-trace-count-for-label 1, [print-character] ] scenario editor-inserts-characters-at-cursor-4 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 3, 5 # below all text + left-click 3, 5 # below all text type [e] ] run [ @@ -610,19 +610,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 1, [print-character] + check-trace-count-for-label 1, [print-character] ] scenario editor-inserts-characters-at-cursor-6 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 3, 5 # below all text + left-click 3, 5 # below all text type [ef] ] run [ @@ -635,13 +635,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 2, [print-character] + check-trace-count-for-label 2, [print-character] ] scenario editor-moves-cursor-after-inserting-characters [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [ab], screen, 0/left, 5/right + e:&:editor <- new-editor [ab], screen, 0/left, 5/right editor-render screen, e assume-console [ type [01] @@ -662,7 +662,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-line-on-insert [ local-scope assume-screen 5/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 5/right + e:&:editor <- new-editor [abc], screen, 0/left, 5/right editor-render screen, e # type a letter assume-console [ @@ -700,24 +700,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - s:text <- new [abcdefg + s:text <- new [abcdefg defg] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right editor-render screen, e # type more text at the start assume-console [ - left-click 3, 0 + left-click 3, 0 type [abc] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor is not wrapped memory-should-contain [ - 3 <- 3 - 4 <- 3 + 3 <- 3 + 4 <- 3 ] # but line is wrapped screen-should-contain [ @@ -735,47 +735,47 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # if either: # a) we're at the end of the line and at the column of the wrap indicator, or # b) we're not at end of line and just before the column of the wrap indicator - wrap-column:num <- copy right - before-wrap-column:num <- subtract wrap-column, 1 - at-wrap?:bool <- greater-or-equal cursor-column, wrap-column - just-before-wrap?:bool <- greater-or-equal cursor-column, before-wrap-column - next:&:duplex-list:char <- next before-cursor + wrap-column:num <- copy right + before-wrap-column:num <- subtract wrap-column, 1 + at-wrap?:bool <- greater-or-equal cursor-column, wrap-column + just-before-wrap?:bool <- greater-or-equal cursor-column, before-wrap-column + next:&:duplex-list:char <- next before-cursor # at end of line? next == 0 || next.value == 10/newline - at-end-of-line?:bool <- equal next, 0 + at-end-of-line?:bool <- equal next, 0 { break-if at-end-of-line? - next-character:char <- get *next, value:offset - at-end-of-line? <- equal next-character, 10/newline + next-character:char <- get *next, value:offset + at-end-of-line? <- equal next-character, 10/newline } # break unless ((eol? and at-wrap?) or (~eol? and just-before-wrap?)) - move-cursor-to-next-line?:bool <- copy 0/false + move-cursor-to-next-line?:bool <- copy 0/false { break-if at-end-of-line? - move-cursor-to-next-line? <- copy just-before-wrap? + move-cursor-to-next-line? <- copy just-before-wrap? # if we're moving the cursor because it's in the middle of a wrapping # line, adjust it to left-most column - potential-new-cursor-column:num <- copy left + potential-new-cursor-column:num <- copy left } { break-unless at-end-of-line? - move-cursor-to-next-line? <- copy at-wrap? + move-cursor-to-next-line? <- copy at-wrap? # if we're moving the cursor because it's at the end of a wrapping line, # adjust it to one past the left-most column to make room for the # newly-inserted wrap-indicator - potential-new-cursor-column:num <- add left, 1/make-room-for-wrap-indicator + potential-new-cursor-column:num <- add left, 1/make-room-for-wrap-indicator } break-unless move-cursor-to-next-line? - cursor-column <- copy potential-new-cursor-column - *editor <- put *editor, cursor-column:offset, cursor-column - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- copy potential-new-cursor-column + *editor <- put *editor, cursor-column:offset, cursor-column + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row # if we're out of the screen, scroll down { - below-screen?:bool <- greater-or-equal cursor-row, screen-height + below-screen?:bool <- greater-or-equal cursor-row, screen-height break-unless below-screen? <scroll-down> } - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -783,15 +783,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-cursor-after-inserting-characters-in-middle-of-line [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abcde], screen, 0/left, 5/right + e:&:editor <- new-editor [abcde], screen, 0/left, 5/right assume-console [ - left-click 1, 3 # right before the wrap icon + left-click 1, 3 # right before the wrap icon type [f] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -801,8 +801,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 2 # cursor row - 4 <- 0 # cursor column + 3 <- 2 # cursor row + 4 <- 0 # cursor column ] ] @@ -810,9 +810,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # create an editor containing two lines - s:text <- new [abc + s:text <- new [abc xyz] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right screen-should-contain [ . . .abc . @@ -820,7 +820,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] assume-console [ - left-click 1, 4 # at end of first line + left-click 1, 4 # at end of first line type [de] # trigger wrap ] run [ @@ -838,15 +838,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-wraps-cursor-to-left-margin [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abcde], screen, 2/left, 7/right + e:&:editor <- new-editor [abcde], screen, 2/left, 7/right assume-console [ - left-click 1, 5 # line is full; no wrap icon yet + left-click 1, 5 # line is full; no wrap icon yet type [01] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -856,8 +856,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 2 # cursor row - 4 <- 3 # cursor column + 3 <- 2 # cursor row + 4 <- 3 # cursor column ] ] @@ -868,13 +868,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <editor-initialization> [ - *result <- put *result, indent?:offset, 1/true + *result <- put *result, indent?:offset, 1/true ] scenario editor-moves-cursor-down-after-inserting-newline [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right assume-console [ type [0 1] @@ -893,12 +893,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-special-character> [ { - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? <insert-enter-begin> - editor <- insert-new-line-and-indent editor, screen + editor <- insert-new-line-and-indent editor, screen <insert-enter-end> - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -906,41 +906,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool [ local-scope load-ingredients - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - screen-height:num <- screen-height screen + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + screen-height:num <- screen-height screen # insert newline insert 10/newline, before-cursor - before-cursor <- next before-cursor - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- next before-cursor + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column # maybe scroll { - below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater + below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater break-unless below-screen? <scroll-down> - go-render? <- copy 1/true - cursor-row <- subtract cursor-row, 1 # bring back into screen range - *editor <- put *editor, cursor-row:offset, cursor-row + go-render? <- copy 1/true + cursor-row <- subtract cursor-row, 1 # bring back into screen range + *editor <- put *editor, cursor-row:offset, cursor-row } # indent if necessary - indent?:bool <- get *editor, indent?:offset + indent?:bool <- get *editor, indent?:offset return-unless indent? - d:&:duplex-list:char <- get *editor, data:offset - end-of-previous-line:&:duplex-list:char <- prev before-cursor - indent:num <- line-indent end-of-previous-line, d - i:num <- copy 0 + d:&:duplex-list:char <- get *editor, data:offset + end-of-previous-line:&:duplex-list:char <- prev before-cursor + indent:num <- line-indent end-of-previous-line, d + i:num <- copy 0 { - indent-done?:bool <- greater-or-equal i, indent + indent-done?:bool <- greater-or-equal i, indent break-if indent-done? - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen - i <- add i, 1 + editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + i <- add i, 1 loop } ] @@ -950,28 +950,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def line-indent curr:&:duplex-list:char, start:&:duplex-list:char -> result:num [ local-scope load-ingredients - result:num <- copy 0 + result:num <- copy 0 return-unless curr - at-start?:bool <- equal curr, start + at-start?:bool <- equal curr, start return-if at-start? { - curr <- prev curr + curr <- prev curr break-unless curr - at-start?:bool <- equal curr, start + at-start?:bool <- equal curr, start break-if at-start? - c:char <- get *curr, value:offset - at-newline?:bool <- equal c, 10/newline + c:char <- get *curr, value:offset + at-newline?:bool <- equal c, 10/newline break-if at-newline? # if c is a space, increment result - is-space?:bool <- equal c, 32/space + is-space?:bool <- equal c, 32/space { break-unless is-space? - result <- add result, 1 + result <- add result, 1 } # if c is not a space, reset result { break-if is-space? - result <- copy 0 + result <- copy 0 } loop } @@ -980,7 +980,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-down-after-inserting-newline-2 [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 1/left, 10/right + e:&:editor <- new-editor [abc], screen, 1/left, 10/right assume-console [ type [0 1] @@ -1000,7 +1000,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-clears-previous-line-completely-after-inserting-newline [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abcde], screen, 0/left, 5/right + e:&:editor <- new-editor [abcde], screen, 0/left, 5/right assume-console [ press enter ] @@ -1027,70 +1027,70 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-inserts-indent-after-newline [ local-scope assume-screen 10/width, 10/height - s:text <- new [ab + s:text <- new [ab cd ef] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' assume-console [ - left-click 2, 8 + left-click 2, 8 type [ ] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ - 3 <- 3 # cursor row - 4 <- 2 # cursor column (indented) + 3 <- 3 # cursor row + 4 <- 2 # cursor column (indented) ] ] scenario editor-skips-indent-around-paste [ local-scope assume-screen 10/width, 10/height - s:text <- new [ab + s:text <- new [ab cd ef] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # position cursor after 'cd' and hit 'newline' surrounded by paste markers assume-console [ - left-click 2, 8 - press 65507 # start paste + left-click 2, 8 + press 65507 # start paste press enter - press 65506 # end paste + press 65506 # end paste ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ - 3 <- 3 # cursor row - 4 <- 0 # cursor column (not indented) + 3 <- 3 # cursor row + 4 <- 0 # cursor column (not indented) ] ] after <handle-special-key> [ { - paste-start?:bool <- equal k, 65507/paste-start + paste-start?:bool <- equal k, 65507/paste-start break-unless paste-start? - *editor <- put *editor, indent?:offset, 0/false - go-render? <- copy 1/true + *editor <- put *editor, indent?:offset, 0/false + go-render? <- copy 1/true return } ] after <handle-special-key> [ { - paste-end?:bool <- equal k, 65506/paste-end + paste-end?:bool <- equal k, 65506/paste-end break-unless paste-end? - *editor <- put *editor, indent?:offset, 1/true - go-render? <- copy 1/true + *editor <- put *editor, indent?:offset, 1/true + go-render? <- copy 1/true return } ] @@ -1100,28 +1100,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def draw-horizontal screen:&:screen, row:num, x:num, right:num -> screen:&:screen [ local-scope load-ingredients - style:char, style-found?:bool <- next-ingredient + style:char, style-found?:bool <- next-ingredient { break-if style-found? - style <- copy 9472/horizontal + style <- copy 9472/horizontal } - color:num, color-found?:bool <- next-ingredient + color:num, color-found?:bool <- next-ingredient { # default color to white break-if color-found? - color <- copy 245/grey + color <- copy 245/grey } - bg-color:num, bg-color-found?:bool <- next-ingredient + bg-color:num, bg-color-found?:bool <- next-ingredient { break-if bg-color-found? - bg-color <- copy 0/black + bg-color <- copy 0/black } - screen <- move-cursor screen, row, x + screen <- move-cursor screen, row, x { - continue?:bool <- lesser-or-equal x, right # right is inclusive, to match editor semantics + continue?:bool <- lesser-or-equal x, right # right is inclusive, to match editor semantics break-unless continue? print screen, style, color, bg-color - x <- add x, 1 + x <- add x, 1 loop } ] diff --git a/html/edit/003-shortcuts.mu.html b/html/edit/003-shortcuts.mu.html index 2dc6965f..cc243281 100644 --- a/html/edit/003-shortcuts.mu.html +++ b/html/edit/003-shortcuts.mu.html @@ -42,9 +42,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # just one character in final line - s:text <- new [ab + s:text <- new [ab cd] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right assume-console [ press tab ] @@ -60,13 +60,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-special-character> [ { - tab?:bool <- equal c, 9/tab + tab?:bool <- equal c, 9/tab break-unless tab? <insert-character-begin> - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen - editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen + editor, screen, go-render?:bool <- insert-at-cursor editor, 32/space, screen <insert-character-end> - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -76,17 +76,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-backspace-key [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 1 + left-click 1, 1 press backspace ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -95,18 +95,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 4 <- 1 - 5 <- 0 + 4 <- 1 + 5 <- 0 ] - check-trace-count-for-label 3, [print-character] # length of original line to overwrite + check-trace-count-for-label 3, [print-character] # length of original line to overwrite ] after <handle-special-character> [ { - delete-previous-character?:bool <- equal c, 8/backspace + delete-previous-character?:bool <- equal c, 8/backspace break-unless delete-previous-character? <backspace-character-begin> - editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen + editor, screen, go-render?:bool, backspaced-cell:&:duplex-list:char <- delete-before-cursor editor, screen <backspace-character-end> return } @@ -118,114 +118,114 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def delete-before-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, backspaced-cell:&:duplex-list:char [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - data:&:duplex-list:char <- get *editor, data:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + data:&:duplex-list:char <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return - prev:&:duplex-list:char <- prev before-cursor - go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted + prev:&:duplex-list:char <- prev before-cursor + go-render?, backspaced-cell <- copy 0/no-more-render, 0/nothing-deleted return-unless prev - trace 10, [app], [delete-before-cursor] - original-row:num <- get *editor, cursor-row:offset - editor, scroll?:bool <- move-cursor-coordinates-left editor - backspaced-cell:&:duplex-list:char <- copy before-cursor - data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor - before-cursor <- copy prev - *editor <- put *editor, before-cursor:offset, before-cursor - go-render? <- copy 1/true + trace 10, [app], [delete-before-cursor] + original-row:num <- get *editor, cursor-row:offset + editor, scroll?:bool <- move-cursor-coordinates-left editor + backspaced-cell:&:duplex-list:char <- copy before-cursor + data <- remove before-cursor, data # will also neatly trim next/prev pointers in backspaced-cell/before-cursor + before-cursor <- copy prev + *editor <- put *editor, before-cursor:offset, before-cursor + go-render? <- copy 1/true return-if scroll? - screen-width:num <- screen-width screen - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset + screen-width:num <- screen-width screen + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset # did we just backspace over a newline? - same-row?:bool <- equal cursor-row, original-row - go-render? <- copy 1/true + same-row?:bool <- equal cursor-row, original-row + go-render? <- copy 1/true return-unless same-row? - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - curr:&:duplex-list:char <- next before-cursor - screen <- move-cursor screen, cursor-row, cursor-column - curr-column:num <- copy cursor-column + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + curr:&:duplex-list:char <- next before-cursor + screen <- move-cursor screen, cursor-row, cursor-column + curr-column:num <- copy cursor-column { # hit right margin? give up and let caller render - at-right?:bool <- greater-or-equal curr-column, right - go-render? <- copy 1/true + at-right?:bool <- greater-or-equal curr-column, right + go-render? <- copy 1/true return-if at-right? break-unless curr # newline? done. - currc:char <- get *curr, value:offset - at-newline?:bool <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? - screen <- print screen, currc - curr-column <- add curr-column, 1 - curr <- next curr + screen <- print screen, currc + curr-column <- add curr-column, 1 + curr <- next curr loop } # we're guaranteed not to be at the right margin - space:char <- copy 32/space - screen <- print screen, space - go-render? <- copy 0/false + space:char <- copy 32/space + screen <- print screen, space + go-render? <- copy 0/false ] def move-cursor-coordinates-left editor:&:editor -> editor:&:editor, go-render?:bool [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - left:num <- get *editor, left:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + left:num <- get *editor, left:offset # if not at left margin, move one character left { - at-left-margin?:bool <- equal cursor-column, left + at-left-margin?:bool <- equal cursor-column, left break-if at-left-margin? - trace 10, [app], [decrementing cursor column] - cursor-column <- subtract cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column - go-render? <- copy 0/false + trace 10, [app], [decrementing cursor column] + cursor-column <- subtract cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column + go-render? <- copy 0/false return } # if at left margin, we must move to previous row: - top-of-screen?:bool <- equal cursor-row, 1 # exclude menu bar - go-render?:bool <- copy 0/false + top-of-screen?:bool <- equal cursor-row, 1 # exclude menu bar + go-render?:bool <- copy 0/false { break-if top-of-screen? - cursor-row <- subtract cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row + cursor-row <- subtract cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row } { break-unless top-of-screen? <scroll-up> - go-render? <- copy 1/true + go-render? <- copy 1/true } { # case 1: if previous character was newline, figure out how long the previous line is - previous-character:char <- get *before-cursor, value:offset - previous-character-is-newline?:bool <- equal previous-character, 10/newline + previous-character:char <- get *before-cursor, value:offset + previous-character-is-newline?:bool <- equal previous-character, 10/newline break-unless previous-character-is-newline? # compute length of previous line - trace 10, [app], [switching to previous line] - d:&:duplex-list:char <- get *editor, data:offset - end-of-line:num <- previous-line-length before-cursor, d - right:num <- get *editor, right:offset - width:num <- subtract right, left - wrap?:bool <- greater-than end-of-line, width + trace 10, [app], [switching to previous line] + d:&:duplex-list:char <- get *editor, data:offset + end-of-line:num <- previous-line-length before-cursor, d + right:num <- get *editor, right:offset + width:num <- subtract right, left + wrap?:bool <- greater-than end-of-line, width { break-unless wrap? - _, column-offset:num <- divide-with-remainder end-of-line, width - cursor-column <- add left, column-offset - *editor <- put *editor, cursor-column:offset, cursor-column + _, column-offset:num <- divide-with-remainder end-of-line, width + cursor-column <- add left, column-offset + *editor <- put *editor, cursor-column:offset, cursor-column } { break-if wrap? - cursor-column <- add left, end-of-line - *editor <- put *editor, cursor-column:offset, cursor-column + cursor-column <- add left, end-of-line + *editor <- put *editor, cursor-column:offset, cursor-column } return } # case 2: if previous-character was not newline, we're just at a wrapped line - trace 10, [app], [wrapping to previous line] - right:num <- get *editor, right:offset - cursor-column <- subtract right, 1 # leave room for wrap icon - *editor <- put *editor, cursor-column:offset, cursor-column + trace 10, [app], [wrapping to previous line] + right:num <- get *editor, right:offset + cursor-column <- subtract right, 1 # leave room for wrap icon + *editor <- put *editor, cursor-column:offset, cursor-column ] # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts @@ -233,19 +233,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def previous-line-length curr:&:duplex-list:char, start:&:duplex-list:char -> result:num [ local-scope load-ingredients - result:num <- copy 0 + result:num <- copy 0 return-unless curr - at-start?:bool <- equal curr, start + at-start?:bool <- equal curr, start return-if at-start? { - curr <- prev curr + curr <- prev curr break-unless curr - at-start?:bool <- equal curr, start + at-start?:bool <- equal curr, start break-if at-start? - c:char <- get *curr, value:offset - at-newline?:bool <- equal c, 10/newline + c:char <- get *curr, value:offset + at-newline?:bool <- equal c, 10/newline break-if at-newline? - result <- add result, 1 + result <- add result, 1 loop } ] @@ -254,17 +254,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # just one character in final line - s:text <- new [ab + s:text <- new [ab cd] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right assume-console [ - left-click 2, 0 # cursor at only character in final line + left-click 2, 0 # cursor at only character in final line press backspace ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -273,8 +273,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 4 <- 1 - 5 <- 2 + 4 <- 1 + 5 <- 2 ] ] @@ -282,14 +282,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # initialize editor with two long-ish but non-wrapping lines - s:text <- new [abc def + s:text <- new [abc def ghi jkl] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # position the cursor at the start of the second and hit backspace assume-console [ - left-click 2, 0 + left-click 2, 0 press backspace ] run [ @@ -309,7 +309,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # initialize editor in part of the screen with a long line - e:&:editor <- new-editor [abc def ghij], screen, 0/left, 8/right + e:&:editor <- new-editor [abc def ghij], screen, 0/left, 8/right editor-render screen, e # confirm that it wraps screen-should-contain [ @@ -321,7 +321,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color $clear-trace # position the cursor somewhere in the middle of the top screen line and hit backspace assume-console [ - left-click 1, 4 + left-click 1, 4 press backspace ] run [ @@ -342,7 +342,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-handles-delete-key [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ @@ -357,7 +357,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 3, [print-character] # length of original line to overwrite + check-trace-count-for-label 3, [print-character] # length of original line to overwrite $clear-trace assume-console [ press delete @@ -371,15 +371,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 2, [print-character] # new length to overwrite + check-trace-count-for-label 2, [print-character] # new length to overwrite ] after <handle-special-key> [ { - delete-next-character?:bool <- equal k, 65522/delete + delete-next-character?:bool <- equal k, 65522/delete break-unless delete-next-character? <delete-character-begin> - editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen + editor, screen, go-render?:bool, deleted-cell:&:duplex-list:char <- delete-at-cursor editor, screen <delete-character-end> return } @@ -388,42 +388,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def delete-at-cursor editor:&:editor, screen:&:screen -> editor:&:editor, screen:&:screen, go-render?:bool, deleted-cell:&:duplex-list:char [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - data:&:duplex-list:char <- get *editor, data:offset - deleted-cell:&:duplex-list:char <- next before-cursor - go-render? <- copy 0/false + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + data:&:duplex-list:char <- get *editor, data:offset + deleted-cell:&:duplex-list:char <- next before-cursor + go-render? <- copy 0/false return-unless deleted-cell - currc:char <- get *deleted-cell, value:offset - data <- remove deleted-cell, data - deleted-newline?:bool <- equal currc, 10/newline - go-render? <- copy 1/true + currc:char <- get *deleted-cell, value:offset + data <- remove deleted-cell, data + deleted-newline?:bool <- equal currc, 10/newline + go-render? <- copy 1/true return-if deleted-newline? # wasn't a newline? render rest of line - curr:&:duplex-list:char <- next before-cursor # refresh after remove above - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - screen <- move-cursor screen, cursor-row, cursor-column - curr-column:num <- copy cursor-column - screen-width:num <- screen-width screen + curr:&:duplex-list:char <- next before-cursor # refresh after remove above + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + screen <- move-cursor screen, cursor-row, cursor-column + curr-column:num <- copy cursor-column + screen-width:num <- screen-width screen { # hit right margin? give up and let caller render - at-right?:bool <- greater-or-equal curr-column, screen-width - go-render? <- copy 1/true + at-right?:bool <- greater-or-equal curr-column, screen-width + go-render? <- copy 1/true return-if at-right? break-unless curr # newline? done. - currc:char <- get *curr, value:offset - at-newline?:bool <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? - screen <- print screen, currc - curr-column <- add curr-column, 1 - curr <- next curr + screen <- print screen, currc + curr-column <- add curr-column, 1 + curr <- next curr loop } # we're guaranteed not to be at the right margin - space:char <- copy 32/space - screen <- print screen, space - go-render? <- copy 0/false + space:char <- copy 32/space + screen <- print screen, space + go-render? <- copy 0/false ] # right arrow @@ -431,7 +431,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-right-with-key [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ @@ -447,23 +447,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 3, [print-character] # 0 and following characters + check-trace-count-for-label 3, [print-character] # 0 and following characters ] after <handle-special-key> [ { - move-to-next-character?:bool <- equal k, 65514/right-arrow + move-to-next-character?:bool <- equal k, 65514/right-arrow break-unless move-to-next-character? # if not at end of text - next-cursor:&:duplex-list:char <- next before-cursor + next-cursor:&:duplex-list:char <- next before-cursor break-unless next-cursor # scan to next character <move-cursor-begin> - before-cursor <- copy next-cursor - *editor <- put *editor, before-cursor:offset, before-cursor - editor, go-render?:bool <- move-cursor-coordinates-right editor, screen-height - screen <- move-cursor screen, cursor-row, cursor-column - undo-coalesce-tag:num <- copy 2/right-arrow + before-cursor <- copy next-cursor + *editor <- put *editor, before-cursor:offset, before-cursor + editor, go-render?:bool <- move-cursor-coordinates-right editor, screen-height + screen <- move-cursor screen, cursor-row, cursor-column + undo-coalesce-tag:num <- copy 2/right-arrow <move-cursor-end> return } @@ -472,65 +472,65 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def move-cursor-coordinates-right editor:&:editor, screen-height:num -> editor:&:editor, go-render?:bool [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor before-cursor:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset + before-cursor:&:duplex-list:char <- get *editor before-cursor:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset # if crossed a newline, move cursor to start of next row { - old-cursor-character:char <- get *before-cursor, value:offset - was-at-newline?:bool <- equal old-cursor-character, 10/newline + old-cursor-character:char <- get *before-cursor, value:offset + was-at-newline?:bool <- equal old-cursor-character, 10/newline break-unless was-at-newline? - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column - below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - go-render? <- copy 0/false + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column + below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal + go-render? <- copy 0/false return-unless below-screen? <scroll-down> - cursor-row <- subtract cursor-row, 1 # bring back into screen range - *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true + cursor-row <- subtract cursor-row, 1 # bring back into screen range + *editor <- put *editor, cursor-row:offset, cursor-row + go-render? <- copy 1/true return } # if the line wraps, move cursor to start of next row { # if we're at the column just before the wrap indicator - wrap-column:num <- subtract right, 1 - at-wrap?:bool <- equal cursor-column, wrap-column + wrap-column:num <- subtract right, 1 + at-wrap?:bool <- equal cursor-column, wrap-column break-unless at-wrap? # and if next character isn't newline - next:&:duplex-list:char <- next before-cursor + next:&:duplex-list:char <- next before-cursor break-unless next - next-character:char <- get *next, value:offset - newline?:bool <- equal next-character, 10/newline + next-character:char <- get *next, value:offset + newline?:bool <- equal next-character, 10/newline break-if newline? - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column - below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - return-unless below-screen?, editor/same-as-ingredient:0, 0/no-more-render + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column + below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal + return-unless below-screen?, editor/same-as-ingredient:0, 0/no-more-render <scroll-down> - cursor-row <- subtract cursor-row, 1 # bring back into screen range - *editor <- put *editor, cursor-row:offset, cursor-row - go-render? <- copy 1/true + cursor-row <- subtract cursor-row, 1 # bring back into screen range + *editor <- put *editor, cursor-row:offset, cursor-row + go-render? <- copy 1/true return } # otherwise move cursor one character right - cursor-column <- add cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column - go-render? <- copy 0/false + cursor-column <- add cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column + go-render? <- copy 0/false ] scenario editor-moves-cursor-to-next-line-with-right-arrow [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # type right-arrow a few times to get to start of second line @@ -543,7 +543,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] # type something and ensure it goes where it should assume-console [ type [0] @@ -558,15 +558,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 2, [print-character] # new length of second line + check-trace-count-for-label 2, [print-character] # new length of second line ] scenario editor-moves-cursor-to-next-line-with-right-arrow-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 1/left, 10/right + e:&:editor <- new-editor s, screen, 1/left, 10/right editor-render screen, e assume-console [ press right-arrow @@ -590,17 +590,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abcdef], screen, 0/left, 5/right + e:&:editor <- new-editor [abcdef], screen, 0/left, 5/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 3 + left-click 1, 3 press right-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -610,32 +610,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 2 - 4 <- 0 + 3 <- 2 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ local-scope assume-screen 10/width, 5/height # line just barely wrapping - e:&:editor <- new-editor [abcde], screen, 0/left, 5/right + e:&:editor <- new-editor [abcde], screen, 0/left, 5/right editor-render screen, e $clear-trace # position cursor at last character before wrap and hit right-arrow assume-console [ - left-click 1, 3 + left-click 1, 3 press right-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 - 4 <- 0 + 3 <- 2 + 4 <- 0 ] # now hit right arrow again assume-console [ @@ -643,30 +643,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abcdef], screen, 1/left, 6/right + e:&:editor <- new-editor [abcdef], screen, 1/left, 6/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 4 + left-click 1, 4 press right-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] screen-should-contain [ . . @@ -676,23 +676,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # move to end of line, press right-arrow, type a character assume-console [ - left-click 1, 3 + left-click 1, 3 press right-arrow type [0] ] @@ -707,7 +707,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 2, [print-character] + check-trace-count-for-label 2, [print-character] ] # todo: ctrl-right: next word-end @@ -717,11 +717,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color scenario editor-moves-cursor-left-with-key [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 2 + left-click 1, 2 press left-arrow type [0] ] @@ -734,23 +734,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 3, [print-character] + check-trace-count-for-label 3, [print-character] ] after <handle-special-key> [ { - move-to-previous-character?:bool <- equal k, 65515/left-arrow + move-to-previous-character?:bool <- equal k, 65515/left-arrow break-unless move-to-previous-character? - trace 10, [app], [left arrow] + trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) - prev:&:duplex-list:char <- prev before-cursor - go-render? <- copy 0/false + prev:&:duplex-list:char <- prev before-cursor + go-render? <- copy 0/false return-unless prev <move-cursor-begin> - editor, go-render? <- move-cursor-coordinates-left editor - before-cursor <- copy prev - *editor <- put *editor, before-cursor:offset, before-cursor - undo-coalesce-tag:num <- copy 1/left-arrow + editor, go-render? <- move-cursor-coordinates-left editor + before-cursor <- copy prev + *editor <- put *editor, before-cursor:offset, before-cursor + undo-coalesce-tag:num <- copy 1/left-arrow <move-cursor-end> return } @@ -760,42 +760,42 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope assume-screen 10/width, 5/height # initialize editor with two lines - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # position cursor at start of second line (so there's no previous newline) assume-console [ - left-click 2, 0 + left-click 2, 0 press left-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ local-scope assume-screen 10/width, 5/height # initialize editor with three lines - s:text <- new [abc + s:text <- new [abc def g] - e:&:editor <- new-editor s:text, screen, 0/left, 10/right + e:&:editor <- new-editor s:text, screen, 0/left, 10/right editor-render screen, e $clear-trace # position cursor further down (so there's a newline before the character at # the cursor) assume-console [ - left-click 3, 0 + left-click 3, 0 press left-arrow type [0] ] @@ -809,21 +809,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .g . .╌╌╌╌╌╌╌╌╌╌. ] - check-trace-count-for-label 1, [print-character] # just the '0' + check-trace-count-for-label 1, [print-character] # just the '0' ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc def g] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # position cursor at start of text, press left-arrow, then type a character assume-console [ - left-click 1, 0 + left-click 1, 0 press left-arrow type [0] ] @@ -838,22 +838,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .g . .╌╌╌╌╌╌╌╌╌╌. ] - check-trace-count-for-label 4, [print-character] # length of first line + check-trace-count-for-label 4, [print-character] # length of first line ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ local-scope assume-screen 10/width, 5/height # initialize editor with text containing an empty line - s:text <- new [abc + s:text <- new [abc d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e:&:editor $clear-trace # position cursor right after empty line assume-console [ - left-click 3, 0 + left-click 3, 0 press left-arrow type [0] ] @@ -867,14 +867,14 @@ d] .d . .╌╌╌╌╌╌╌╌╌╌. ] - check-trace-count-for-label 1, [print-character] # just the '0' + check-trace-count-for-label 1, [print-character] # just the '0' ] scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ local-scope assume-screen 10/width, 5/height # initialize editor with a wrapping line - e:&:editor <- new-editor [abcdef], screen, 0/left, 5/right + e:&:editor <- new-editor [abcdef], screen, 0/left, 5/right editor-render screen, e $clear-trace screen-should-contain [ @@ -886,28 +886,28 @@ d] ] # position cursor right after empty line assume-console [ - left-click 2, 0 + left-click 2, 0 press left-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 # previous row - 4 <- 3 # right margin except wrap icon + 3 <- 1 # previous row + 4 <- 3 # right margin except wrap icon ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-across-screen-lines-to-wrapping-line-with-left-arrow [ local-scope assume-screen 10/width, 5/height # initialize editor with a wrapping line followed by a second line - s:text <- new [abcdef + s:text <- new [abcdef g] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right editor-render screen, e $clear-trace screen-should-contain [ @@ -919,28 +919,28 @@ d] ] # position cursor right after empty line assume-console [ - left-click 3, 0 + left-click 3, 0 press left-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 # previous row - 4 <- 2 # end of wrapped line + 3 <- 2 # previous row + 4 <- 2 # end of wrapped line ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-across-screen-lines-to-non-wrapping-line-with-left-arrow [ local-scope assume-screen 10/width, 5/height # initialize editor with a line on the verge of wrapping, followed by a second line - s:text <- new [abcd + s:text <- new [abcd e] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right editor-render screen, e $clear-trace screen-should-contain [ @@ -952,19 +952,19 @@ d] ] # position cursor right after empty line assume-console [ - left-click 2, 0 + left-click 2, 0 press left-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 # previous row - 4 <- 4 # end of wrapped line + 3 <- 1 # previous row + 4 <- 4 # end of wrapped line ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] # todo: ctrl-left: previous word-start @@ -974,25 +974,25 @@ d] scenario editor-moves-to-previous-line-with-up-arrow [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 2, 1 + left-click 2, 1 press up-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1010,11 +1010,11 @@ d] after <handle-special-key> [ { - move-to-previous-line?:bool <- equal k, 65517/up-arrow + move-to-previous-line?:bool <- equal k, 65517/up-arrow break-unless move-to-previous-line? <move-cursor-begin> - editor, go-render? <- move-to-previous-line editor - undo-coalesce-tag:num <- copy 3/up-arrow + editor, go-render? <- move-to-previous-line editor + undo-coalesce-tag:num <- copy 3/up-arrow <move-cursor-end> return } @@ -1023,67 +1023,67 @@ d] def move-to-previous-line editor:&:editor -> editor:&:editor, go-render?:bool [ local-scope load-ingredients - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - already-at-top?:bool <- lesser-or-equal cursor-row, 1/top + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + already-at-top?:bool <- lesser-or-equal cursor-row, 1/top { # if cursor not at top, move it break-if already-at-top? # if not at newline, move to start of line (previous newline) # then scan back another line # if either step fails, give up without modifying cursor or coordinates - curr:&:duplex-list:char <- copy before-cursor + curr:&:duplex-list:char <- copy before-cursor { - old:&:duplex-list:char <- copy curr - c2:char <- get *curr, value:offset - at-newline?:bool <- equal c2, 10/newline + old:&:duplex-list:char <- copy curr + c2:char <- get *curr, value:offset + at-newline?:bool <- equal c2, 10/newline break-if at-newline? - curr:&:duplex-list:char <- before-previous-line curr, editor - no-motion?:bool <- equal curr, old - go-render? <- copy 0/false + curr:&:duplex-list:char <- before-previous-line curr, editor + no-motion?:bool <- equal curr, old + go-render? <- copy 0/false return-if no-motion? } { - old <- copy curr - curr <- before-previous-line curr, editor - no-motion?:bool <- equal curr, old - go-render? <- copy 0/false + old <- copy curr + curr <- before-previous-line curr, editor + no-motion?:bool <- equal curr, old + go-render? <- copy 0/false return-if no-motion? } - before-cursor <- copy curr - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-row <- subtract cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row + before-cursor <- copy curr + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-row <- subtract cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row # scan ahead to right column or until end of line - target-column:num <- copy cursor-column - cursor-column <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column + target-column:num <- copy cursor-column + cursor-column <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column { - done?:bool <- greater-or-equal cursor-column, target-column + done?:bool <- greater-or-equal cursor-column, target-column break-if done? - curr:&:duplex-list:char <- next before-cursor + curr:&:duplex-list:char <- next before-cursor break-unless curr - currc:char <- get *curr, value:offset - at-newline?:bool <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? # - before-cursor <- copy curr - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-column <- add cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- copy curr + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-column <- add cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column loop } - go-render? <- copy 0/false + go-render? <- copy 0/false return } { # if cursor already at top, scroll up break-unless already-at-top? <scroll-up> - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -1091,25 +1091,25 @@ d] scenario editor-adjusts-column-at-previous-line [ local-scope assume-screen 10/width, 5/height - s:text <- new [ab + s:text <- new [ab def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 2, 3 + left-click 2, 3 press up-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1128,25 +1128,25 @@ d] scenario editor-adjusts-column-at-empty-line [ local-scope assume-screen 10/width, 5/height - s:text <- new [ + s:text <- new [ def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 2, 3 + left-click 2, 3 press up-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1166,27 +1166,27 @@ d] local-scope assume-screen 10/width, 5/height # start out with three lines - s:text <- new [abc + s:text <- new [abc def ghi] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # click on the third line and hit up-arrow, so you end up just after a newline assume-console [ - left-click 3, 0 + left-click 3, 0 press up-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 - 4 <- 0 + 3 <- 2 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1207,9 +1207,9 @@ d] scenario editor-moves-to-next-line-with-down-arrow [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc def] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # cursor starts out at (1, 0) @@ -1218,15 +1218,15 @@ d] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # ..and ends at (2, 0) memory-should-contain [ - 3 <- 2 - 4 <- 0 + 3 <- 2 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1244,11 +1244,11 @@ d] after <handle-special-key> [ { - move-to-next-line?:bool <- equal k, 65516/down-arrow + move-to-next-line?:bool <- equal k, 65516/down-arrow break-unless move-to-next-line? <move-cursor-begin> - editor, go-render? <- move-to-next-line editor, screen-height - undo-coalesce-tag:num <- copy 4/down-arrow + editor, go-render? <- move-to-next-line editor, screen-height + undo-coalesce-tag:num <- copy 4/down-arrow <move-cursor-end> return } @@ -1257,81 +1257,81 @@ d] def move-to-next-line editor:&:editor, screen-height:num -> editor:&:editor, go-render?:bool [ local-scope load-ingredients - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - last-line:num <- subtract screen-height, 1 - already-at-bottom?:bool <- greater-or-equal cursor-row, last-line + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + last-line:num <- subtract screen-height, 1 + already-at-bottom?:bool <- greater-or-equal cursor-row, last-line { # if cursor not at bottom, move it break-if already-at-bottom? # scan to start of next line, then to right column or until end of line - max:num <- subtract right, left - next-line:&:duplex-list:char <- before-start-of-next-line before-cursor, max + max:num <- subtract right, left + next-line:&:duplex-list:char <- before-start-of-next-line before-cursor, max { # already at end of buffer? try to scroll up (so we can see more # warnings or sandboxes below) - no-motion?:bool <- equal next-line, before-cursor + no-motion?:bool <- equal next-line, before-cursor break-unless no-motion? - scroll?:bool <- greater-than cursor-row, 1 + scroll?:bool <- greater-than cursor-row, 1 break-if scroll?, +try-to-scroll - go-render? <- copy 0/false + go-render? <- copy 0/false return } - cursor-row <- add cursor-row, 1 - *editor <- put *editor, cursor-row:offset, cursor-row - before-cursor <- copy next-line - *editor <- put *editor, before-cursor:offset, before-cursor - target-column:num <- copy cursor-column - cursor-column <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column + cursor-row <- add cursor-row, 1 + *editor <- put *editor, cursor-row:offset, cursor-row + before-cursor <- copy next-line + *editor <- put *editor, before-cursor:offset, before-cursor + target-column:num <- copy cursor-column + cursor-column <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column { - done?:bool <- greater-or-equal cursor-column, target-column + done?:bool <- greater-or-equal cursor-column, target-column break-if done? - curr:&:duplex-list:char <- next before-cursor + curr:&:duplex-list:char <- next before-cursor break-unless curr - currc:char <- get *curr, value:offset - at-newline?:bool <- equal currc, 10/newline + currc:char <- get *curr, value:offset + at-newline?:bool <- equal currc, 10/newline break-if at-newline? # - before-cursor <- copy curr - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-column <- add cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- copy curr + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-column <- add cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column loop } - go-render? <- copy 0/false + go-render? <- copy 0/false return } +try-to-scroll <scroll-down> - go-render? <- copy 1/true + go-render? <- copy 1/true ] scenario editor-adjusts-column-at-next-line [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc de] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace assume-console [ - left-click 1, 3 + left-click 1, 3 press down-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 3 <- 2 - 4 <- 2 + 3 <- 2 + 4 <- 2 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [0] ] @@ -1352,51 +1352,51 @@ d] scenario editor-moves-to-start-of-line-with-ctrl-a [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on second line, press ctrl-a assume-console [ - left-click 2, 3 + left-click 2, 3 press ctrl-a ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ - 4 <- 2 - 5 <- 0 + 4 <- 2 + 5 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] after <handle-special-character> [ { - move-to-start-of-line?:bool <- equal c, 1/ctrl-a + move-to-start-of-line?:bool <- equal c, 1/ctrl-a break-unless move-to-start-of-line? <move-cursor-begin> move-to-start-of-line editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false + go-render? <- copy 0/false return } ] after <handle-special-key> [ { - move-to-start-of-line?:bool <- equal k, 65521/home + move-to-start-of-line?:bool <- equal k, 65521/home break-unless move-to-start-of-line? <move-cursor-begin> move-to-start-of-line editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false + go-render? <- copy 0/false return } ] @@ -1405,21 +1405,21 @@ d] local-scope load-ingredients # update cursor column - left:num <- get *editor, left:offset - cursor-column:num <- copy left - *editor <- put *editor, cursor-column:offset, cursor-column + left:num <- get *editor, left:offset + cursor-column:num <- copy left + *editor <- put *editor, cursor-column:offset, cursor-column # update before-cursor - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - init:&:duplex-list:char <- get *editor, data:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + init:&:duplex-list:char <- get *editor, data:offset # while not at start of line, move { - at-start-of-text?:bool <- equal before-cursor, init + at-start-of-text?:bool <- equal before-cursor, init break-if at-start-of-text? - prev:char <- get *before-cursor, value:offset - at-start-of-line?:bool <- equal prev, 10/newline + prev:char <- get *before-cursor, value:offset + at-start-of-line?:bool <- equal prev, 10/newline break-if at-start-of-line? - before-cursor <- prev before-cursor - *editor <- put *editor, before-cursor:offset, before-cursor + before-cursor <- prev before-cursor + *editor <- put *editor, before-cursor:offset, before-cursor assert before-cursor, [move-to-start-of-line tried to move before start of text] loop } @@ -1428,78 +1428,78 @@ d] scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on first line (no newline before), press ctrl-a assume-console [ - left-click 1, 3 + left-click 1, 3 press ctrl-a ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ - 4 <- 1 - 5 <- 0 + 4 <- 1 + 5 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-to-start-of-line-with-home [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right $clear-trace # start on second line, press 'home' assume-console [ - left-click 2, 3 + left-click 2, 3 press home ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ - 3 <- 2 - 4 <- 0 + 3 <- 2 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-to-start-of-line-with-home-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on first line (no newline before), press 'home' assume-console [ - left-click 1, 3 + left-click 1, 3 press home ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] # ctrl-e/end - move cursor to end of line @@ -1507,39 +1507,39 @@ d] scenario editor-moves-to-end-of-line-with-ctrl-e [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on first line, press ctrl-e assume-console [ - left-click 1, 1 + left-click 1, 1 press ctrl-e ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ - 4 <- 1 - 5 <- 3 + 4 <- 1 + 5 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] # editor inserts future characters at cursor assume-console [ type [z] ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] memory-should-contain [ - 4 <- 1 - 5 <- 4 + 4 <- 1 + 5 <- 4 ] screen-should-contain [ . . @@ -1548,31 +1548,31 @@ d] .╌╌╌╌╌╌╌╌╌╌. . . ] - check-trace-count-for-label 1, [print-character] + check-trace-count-for-label 1, [print-character] ] after <handle-special-character> [ { - move-to-end-of-line?:bool <- equal c, 5/ctrl-e + move-to-end-of-line?:bool <- equal c, 5/ctrl-e break-unless move-to-end-of-line? <move-cursor-begin> move-to-end-of-line editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false + go-render? <- copy 0/false return } ] after <handle-special-key> [ { - move-to-end-of-line?:bool <- equal k, 65520/end + move-to-end-of-line?:bool <- equal k, 65520/end break-unless move-to-end-of-line? <move-cursor-begin> move-to-end-of-line editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - go-render? <- copy 0/false + go-render? <- copy 0/false return } ] @@ -1580,19 +1580,19 @@ d] def move-to-end-of-line editor:&:editor -> editor:&:editor [ local-scope load-ingredients - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + cursor-column:num <- get *editor, cursor-column:offset # while not at start of line, move { - next:&:duplex-list:char <- next before-cursor + next:&:duplex-list:char <- next before-cursor break-unless next # end of text - nextc:char <- get *next, value:offset - at-end-of-line?:bool <- equal nextc, 10/newline + nextc:char <- get *next, value:offset + at-end-of-line?:bool <- equal nextc, 10/newline break-if at-end-of-line? - before-cursor <- copy next - *editor <- put *editor, before-cursor:offset, before-cursor - cursor-column <- add cursor-column, 1 - *editor <- put *editor, cursor-column:offset, cursor-column + before-cursor <- copy next + *editor <- put *editor, before-cursor:offset, before-cursor + cursor-column <- add cursor-column, 1 + *editor <- put *editor, cursor-column:offset, cursor-column loop } ] @@ -1600,79 +1600,79 @@ d] scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on second line (no newline after), press ctrl-e assume-console [ - left-click 2, 1 + left-click 2, 1 press ctrl-e ] run [ editor-event-loop screen, console, e - 4:num/raw <- get *e, cursor-row:offset - 5:num/raw <- get *e, cursor-column:offset + 4:num/raw <- get *e, cursor-row:offset + 5:num/raw <- get *e, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ - 4 <- 2 - 5 <- 3 + 4 <- 2 + 5 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-to-end-of-line-with-end [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on first line, press 'end' assume-console [ - left-click 1, 1 + left-click 1, 1 press end ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] scenario editor-moves-to-end-of-line-with-end-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # start on second line (no newline after), press 'end' assume-console [ - left-click 2, 1 + left-click 2, 1 press end ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ - 3 <- 2 - 4 <- 3 + 3 <- 2 + 4 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] ] # ctrl-u - delete text from start of line until (but not at) cursor @@ -1680,12 +1680,12 @@ d] scenario editor-deletes-to-start-of-line-with-ctrl-u [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start on second line, press ctrl-u assume-console [ - left-click 2, 2 + left-click 2, 2 press ctrl-u ] run [ @@ -1703,12 +1703,12 @@ d] after <handle-special-character> [ { - delete-to-start-of-line?:bool <- equal c, 21/ctrl-u + delete-to-start-of-line?:bool <- equal c, 21/ctrl-u break-unless delete-to-start-of-line? <delete-to-start-of-line-begin> - deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor + deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor <delete-to-start-of-line-end> - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -1717,39 +1717,39 @@ d] local-scope load-ingredients # compute range to delete - init:&:duplex-list:char <- get *editor, data:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - start:&:duplex-list:char <- copy before-cursor - end:&:duplex-list:char <- next before-cursor + init:&:duplex-list:char <- get *editor, data:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + start:&:duplex-list:char <- copy before-cursor + end:&:duplex-list:char <- next before-cursor { - at-start-of-text?:bool <- equal start, init + at-start-of-text?:bool <- equal start, init break-if at-start-of-text? - curr:char <- get *start, value:offset - at-start-of-line?:bool <- equal curr, 10/newline + curr:char <- get *start, value:offset + at-start-of-line?:bool <- equal curr, 10/newline break-if at-start-of-line? - start <- prev start + start <- prev start assert start, [delete-to-start-of-line tried to move before start of text] loop } # snip it out - result:&:duplex-list:char <- next start + result:&:duplex-list:char <- next start remove-between start, end # adjust cursor - before-cursor <- copy start - *editor <- put *editor, before-cursor:offset, before-cursor - left:num <- get *editor, left:offset - *editor <- put *editor, cursor-column:offset, left + before-cursor <- copy start + *editor <- put *editor, before-cursor:offset, before-cursor + left:num <- get *editor, left:offset + *editor <- put *editor, cursor-column:offset, left ] scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start on first line (no newline before), press ctrl-u assume-console [ - left-click 1, 2 + left-click 1, 2 press ctrl-u ] run [ @@ -1768,12 +1768,12 @@ d] scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start past end of line, press ctrl-u assume-console [ - left-click 1, 3 + left-click 1, 3 press ctrl-u ] run [ @@ -1792,12 +1792,12 @@ d] scenario editor-deletes-to-start-of-final-line-with-ctrl-u [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start past end of final line, press ctrl-u assume-console [ - left-click 2, 3 + left-click 2, 3 press ctrl-u ] run [ @@ -1818,12 +1818,12 @@ d] scenario editor-deletes-to-end-of-line-with-ctrl-k [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start on first line, press ctrl-k assume-console [ - left-click 1, 1 + left-click 1, 1 press ctrl-k ] run [ @@ -1841,12 +1841,12 @@ d] after <handle-special-character> [ { - delete-to-end-of-line?:bool <- equal c, 11/ctrl-k + delete-to-end-of-line?:bool <- equal c, 11/ctrl-k break-unless delete-to-end-of-line? <delete-to-end-of-line-begin> - deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor + deleted-cells:&:duplex-list:char <- delete-to-end-of-line editor <delete-to-end-of-line-end> - go-render? <- copy 1/true + go-render? <- copy 1/true return } ] @@ -1855,31 +1855,31 @@ d] local-scope load-ingredients # compute range to delete - start:&:duplex-list:char <- get *editor, before-cursor:offset - end:&:duplex-list:char <- next start + start:&:duplex-list:char <- get *editor, before-cursor:offset + end:&:duplex-list:char <- next start { - at-end-of-text?:bool <- equal end, 0/null + at-end-of-text?:bool <- equal end, 0/null break-if at-end-of-text? - curr:char <- get *end, value:offset - at-end-of-line?:bool <- equal curr, 10/newline + curr:char <- get *end, value:offset + at-end-of-line?:bool <- equal curr, 10/newline break-if at-end-of-line? - end <- next end + end <- next end loop } # snip it out - result <- next start + result <- next start remove-between start, end ] scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start on second line (no newline after), press ctrl-k assume-console [ - left-click 2, 1 + left-click 2, 1 press ctrl-k ] run [ @@ -1898,12 +1898,12 @@ d] scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start at end of line assume-console [ - left-click 1, 2 + left-click 1, 2 press ctrl-k ] run [ @@ -1922,12 +1922,12 @@ d] scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start past end of line assume-console [ - left-click 1, 3 + left-click 1, 3 press ctrl-k ] run [ @@ -1946,12 +1946,12 @@ d] scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start at end of text assume-console [ - left-click 2, 2 + left-click 2, 2 press ctrl-k ] run [ @@ -1970,12 +1970,12 @@ d] scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [ local-scope assume-screen 10/width, 5/height - s:text <- new [123 + s:text <- new [123 456] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right # start past end of text assume-console [ - left-click 2, 3 + left-click 2, 3 press ctrl-k ] run [ @@ -1998,11 +1998,11 @@ d] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2011,7 +2011,7 @@ d] ] # position cursor at last line, then try to move further down assume-console [ - left-click 3, 0 + left-click 3, 0 press down-arrow ] run [ @@ -2027,16 +2027,16 @@ d] ] after <scroll-down> [ - trace 10, [app], [scroll down] - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - max:num <- subtract right, left - old-top:&:duplex-list:char <- copy top-of-screen - top-of-screen <- before-start-of-next-line top-of-screen, max - *editor <- put *editor, top-of-screen:offset, top-of-screen - no-movement?:bool <- equal old-top, top-of-screen - go-render? <- copy 0/false + trace 10, [app], [scroll down] + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + max:num <- subtract right, left + old-top:&:duplex-list:char <- copy top-of-screen + top-of-screen <- before-start-of-next-line top-of-screen, max + *editor <- put *editor, top-of-screen:offset, top-of-screen + no-movement?:bool <- equal old-top, top-of-screen + go-render? <- copy 0/false return-if no-movement? ] @@ -2046,25 +2046,25 @@ d] def before-start-of-next-line original:&:duplex-list:char, max:num -> curr:&:duplex-list:char [ local-scope load-ingredients - count:num <- copy 0 - curr:&:duplex-list:char <- copy original + count:num <- copy 0 + curr:&:duplex-list:char <- copy original # skip the initial newline if it exists { - c:char <- get *curr, value:offset - at-newline?:bool <- equal c, 10/newline + c:char <- get *curr, value:offset + at-newline?:bool <- equal c, 10/newline break-unless at-newline? - curr <- next curr - count <- add count, 1 + curr <- next curr + count <- add count, 1 } { return-unless curr, original - done?:bool <- greater-or-equal count, max + done?:bool <- greater-or-equal count, max break-if done? - c:char <- get *curr, value:offset - at-newline?:bool <- equal c, 10/newline + c:char <- get *curr, value:offset + at-newline?:bool <- equal c, 10/newline break-if at-newline? - curr <- next curr - count <- add count, 1 + curr <- next curr + count <- add count, 1 loop } return-unless curr, original @@ -2077,11 +2077,11 @@ d] assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - s:text <- new [abcdef + s:text <- new [abcdef g h i] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2090,7 +2090,7 @@ d] ] # position cursor at last line, then try to move further down assume-console [ - left-click 3, 0 + left-click 3, 0 press down-arrow ] run [ @@ -2110,14 +2110,14 @@ d] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # editor starts with a long line wrapping twice - s:text <- new [abcdefghij + s:text <- new [abcdefghij k l m] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at last line, then try to move further down assume-console [ - left-click 3, 0 + left-click 3, 0 press down-arrow ] run [ @@ -2151,19 +2151,19 @@ d] # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a long line in the third line - s:text <- new [a + s:text <- new [a b cdef] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at end, type a character assume-console [ - left-click 3, 4 + left-click 3, 4 type [g] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2173,8 +2173,8 @@ d] .g . ] memory-should-contain [ - 3 <- 3 - 4 <- 1 + 3 <- 3 + 4 <- 1 ] ] @@ -2182,19 +2182,19 @@ d] local-scope assume-screen 5/width, 4/height # position cursor after last line and type newline - s:text <- new [a + s:text <- new [a b c] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right assume-console [ - left-click 3, 4 + left-click 3, 4 type [ ] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2204,8 +2204,8 @@ d] . . ] memory-should-contain [ - 3 <- 3 - 4 <- 0 + 3 <- 3 + 4 <- 0 ] ] @@ -2214,19 +2214,19 @@ d] # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - s:text <- new [a + s:text <- new [a b cdefgh] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ - left-click 3, 3 + left-click 3, 3 press right-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2236,8 +2236,8 @@ d] .gh . ] memory-should-contain [ - 3 <- 3 - 4 <- 0 + 3 <- 3 + 4 <- 0 ] ] @@ -2246,20 +2246,20 @@ d] # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains more lines than can fit on screen - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ - left-click 3, 3 + left-click 3, 3 press right-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2269,33 +2269,33 @@ d] .d . ] memory-should-contain [ - 3 <- 3 - 4 <- 0 + 3 <- 3 + 4 <- 0 ] ] scenario editor-scrolls-at-end-on-down-arrow [ local-scope assume-screen 10/width, 5/height - s:text <- new [abc + s:text <- new [abc de] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e $clear-trace # try to move down past end of text assume-console [ - left-click 2, 0 + left-click 2, 0 press down-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen should scroll, moving cursor to end of text memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] assume-console [ type [0] @@ -2312,20 +2312,20 @@ d] # try to move down again $clear-trace assume-console [ - left-click 2, 0 + left-click 2, 0 press down-arrow ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen stops scrolling because cursor is already at top memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] - check-trace-count-for-label 0, [print-character] + check-trace-count-for-label 0, [print-character] assume-console [ type [1] ] @@ -2345,18 +2345,18 @@ d] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with a few pages of lines - s:text <- new [a + s:text <- new [a b c d e f g] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # scroll down one page and one line assume-console [ press page-down - left-click 3, 0 + left-click 3, 0 press down-arrow ] run [ @@ -2378,11 +2378,11 @@ d] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2407,13 +2407,13 @@ d] ] after <scroll-up> [ - trace 10, [app], [scroll up] - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - old-top:&:duplex-list:char <- copy top-of-screen - top-of-screen <- before-previous-line top-of-screen, editor - *editor <- put *editor, top-of-screen:offset, top-of-screen - no-movement?:bool <- equal old-top, top-of-screen - go-render? <- copy 0/false + trace 10, [app], [scroll up] + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + old-top:&:duplex-list:char <- copy top-of-screen + top-of-screen <- before-previous-line top-of-screen, editor + *editor <- put *editor, top-of-screen:offset, top-of-screen + no-movement?:bool <- equal old-top, top-of-screen + go-render? <- copy 0/false return-if no-movement? ] @@ -2423,39 +2423,39 @@ d] def before-previous-line in:&:duplex-list:char, editor:&:editor -> out:&:duplex-list:char [ local-scope load-ingredients - curr:&:duplex-list:char <- copy in - c:char <- get *curr, value:offset + curr:&:duplex-list:char <- copy in + c:char <- get *curr, value:offset # compute max, number of characters to skip # 1 + len%(width-1) # except rotate second term to vary from 1 to width-1 rather than 0 to width-2 - left:num <- get *editor, left:offset - right:num <- get *editor, right:offset - max-line-length:num <- subtract right, left, -1/exclusive-right, 1/wrap-icon - sentinel:&:duplex-list:char <- get *editor, data:offset - len:num <- previous-line-length curr, sentinel + left:num <- get *editor, left:offset + right:num <- get *editor, right:offset + max-line-length:num <- subtract right, left, -1/exclusive-right, 1/wrap-icon + sentinel:&:duplex-list:char <- get *editor, data:offset + len:num <- previous-line-length curr, sentinel { break-if len # empty line; just skip this newline - prev:&:duplex-list:char <- prev curr + prev:&:duplex-list:char <- prev curr return-unless prev, curr return prev } - _, max:num <- divide-with-remainder len, max-line-length + _, max:num <- divide-with-remainder len, max-line-length # remainder 0 => scan one width-worth { break-if max - max <- copy max-line-length + max <- copy max-line-length } - max <- add max, 1 - count:num <- copy 0 + max <- add max, 1 + count:num <- copy 0 # skip 'max' characters { - done?:bool <- greater-or-equal count, max + done?:bool <- greater-or-equal count, max break-if done? - prev:&:duplex-list:char <- prev curr + prev:&:duplex-list:char <- prev curr break-unless prev - curr <- copy prev - count <- add count, 1 + curr <- copy prev + count <- add count, 1 loop } return curr @@ -2467,11 +2467,11 @@ d] assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - s:text <- new [abcdef + s:text <- new [abcdef g h i] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right screen-should-contain [ . . .abcd↩ . @@ -2512,11 +2512,11 @@ d] # screen has 1 line for menu + 4 lines assume-screen 10/width, 5/height # editor starts with a long line wrapping twice, occupying 3 of the 4 lines - s:text <- new [abcdefghij + s:text <- new [abcdefghij k l m] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down @@ -2586,11 +2586,11 @@ d] assume-screen 10/width, 4/height # initialize editor with a long, wrapped line and more than a screen of # other lines - s:text <- new [abcdef + s:text <- new [abcdef g h i] - e:&:editor <- new-editor s, screen, 0/left, 6/right + e:&:editor <- new-editor s, screen, 0/left, 6/right screen-should-contain [ . . .abcde↩ . @@ -2631,13 +2631,13 @@ d] local-scope assume-screen 10/width, 4/height # initialize editor with some lines around an empty line - s:text <- new [a + s:text <- new [a b c d e] - e:&:editor <- new-editor s, screen, 0/left, 6/right + e:&:editor <- new-editor s, screen, 0/left, 6/right assume-console [ press page-down ] @@ -2681,12 +2681,12 @@ e] # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains >3 lines - s:text <- new [a + s:text <- new [a b c d e] - e:&:editor <- new-editor s, screen, 0/left, 5/right + e:&:editor <- new-editor s, screen, 0/left, 5/right # position cursor at top of second page assume-console [ press page-down @@ -2706,8 +2706,8 @@ e] ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen scrolls screen-should-contain [ @@ -2717,8 +2717,8 @@ e] .d . ] memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] ] @@ -2727,11 +2727,11 @@ e] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with >3 lines - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2776,11 +2776,11 @@ e] scenario editor-can-scroll [ local-scope assume-screen 10/width, 4/height - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -2805,32 +2805,32 @@ e] after <handle-special-character> [ { - page-down?:bool <- equal c, 6/ctrl-f + page-down?:bool <- equal c, 6/ctrl-f break-unless page-down? - old-top:&:duplex-list:char <- get *editor, top-of-screen:offset + old-top:&:duplex-list:char <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + no-movement?:bool <- equal top-of-screen, old-top + go-render? <- not no-movement? return } ] after <handle-special-key> [ { - page-down?:bool <- equal k, 65518/page-down + page-down?:bool <- equal k, 65518/page-down break-unless page-down? - old-top:&:duplex-list:char <- get *editor, top-of-screen:offset + old-top:&:duplex-list:char <- get *editor, top-of-screen:offset <move-cursor-begin> page-down editor - undo-coalesce-tag:num <- copy 0/never + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + no-movement?:bool <- equal top-of-screen, old-top + go-render? <- not no-movement? return } ] @@ -2841,32 +2841,32 @@ e] local-scope load-ingredients # if editor contents don't overflow screen, do nothing - bottom-of-screen:&:duplex-list:char <- get *editor, bottom-of-screen:offset + bottom-of-screen:&:duplex-list:char <- get *editor, bottom-of-screen:offset return-unless bottom-of-screen # if not, position cursor at final character - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - before-cursor:&:duplex-list:char <- prev bottom-of-screen - *editor <- put *editor, before-cursor:offset, before-cursor + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + before-cursor:&:duplex-list:char <- prev bottom-of-screen + *editor <- put *editor, before-cursor:offset, before-cursor # keep one line in common with previous page { - last:char <- get *before-cursor, value:offset - newline?:bool <- equal last, 10/newline + last:char <- get *before-cursor, value:offset + newline?:bool <- equal last, 10/newline break-unless newline?:bool - before-cursor <- prev before-cursor - *editor <- put *editor, before-cursor:offset, before-cursor + before-cursor <- prev before-cursor + *editor <- put *editor, before-cursor:offset, before-cursor } # move cursor and top-of-screen to start of that line move-to-start-of-line editor - before-cursor <- get *editor, before-cursor:offset - *editor <- put *editor, top-of-screen:offset, before-cursor + before-cursor <- get *editor, before-cursor:offset + *editor <- put *editor, top-of-screen:offset, before-cursor ] scenario editor-does-not-scroll-past-end [ local-scope assume-screen 10/width, 4/height - s:text <- new [a + s:text <- new [a b] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right editor-render screen, e screen-should-contain [ . . @@ -2895,11 +2895,11 @@ e] # screen has 1 line for menu + 3 lines for text assume-screen 10/width, 4/height # editor contains a long last line - s:text <- new [a + s:text <- new [a b cdefgh] # editor screen triggers wrap of last line - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2929,9 +2929,9 @@ e] assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - s:text <- new [a + s:text <- new [a bcdefgh] - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -2960,11 +2960,11 @@ e] scenario editor-can-scroll-up [ local-scope assume-screen 10/width, 4/height - s:text <- new [a + s:text <- new [a b c d] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -3003,33 +3003,33 @@ e] after <handle-special-character> [ { - page-up?:bool <- equal c, 2/ctrl-b + page-up?:bool <- equal c, 2/ctrl-b break-unless page-up? - old-top:&:duplex-list:char <- get *editor, top-of-screen:offset + old-top:&:duplex-list:char <- get *editor, top-of-screen:offset <move-cursor-begin> - editor <- page-up editor, screen-height - undo-coalesce-tag:num <- copy 0/never + editor <- page-up editor, screen-height + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top - go-render? <- not no-movement? + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + no-movement?:bool <- equal top-of-screen, old-top + go-render? <- not no-movement? return } ] after <handle-special-key> [ { - page-up?:bool <- equal k, 65519/page-up + page-up?:bool <- equal k, 65519/page-up break-unless page-up? - old-top:&:duplex-list:char <- get *editor, top-of-screen:offset + old-top:&:duplex-list:char <- get *editor, top-of-screen:offset <move-cursor-begin> - editor <- page-up editor, screen-height - undo-coalesce-tag:num <- copy 0/never + editor <- page-up editor, screen-height + undo-coalesce-tag:num <- copy 0/never <move-cursor-end> - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - no-movement?:bool <- equal top-of-screen, old-top + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + no-movement?:bool <- equal top-of-screen, old-top # don't bother re-rendering if nothing changed. todo: test this - go-render? <- not no-movement? + go-render? <- not no-movement? return } ] @@ -3037,17 +3037,17 @@ e] def page-up editor:&:editor, screen-height:num -> editor:&:editor [ local-scope load-ingredients - max:num <- subtract screen-height, 1/menu-bar, 1/overlapping-line - count:num <- copy 0 - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + max:num <- subtract screen-height, 1/menu-bar, 1/overlapping-line + count:num <- copy 0 + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset { - done?:bool <- greater-or-equal count, max + done?:bool <- greater-or-equal count, max break-if done? - prev:&:duplex-list:char <- before-previous-line top-of-screen, editor + prev:&:duplex-list:char <- before-previous-line top-of-screen, editor break-unless prev - top-of-screen <- copy prev - *editor <- put *editor, top-of-screen:offset, top-of-screen - count <- add count, 1 + top-of-screen <- copy prev + *editor <- put *editor, top-of-screen:offset, top-of-screen + count <- add count, 1 loop } ] @@ -3057,7 +3057,7 @@ e] # screen has 1 line for menu + 3 lines assume-screen 10/width, 4/height # initialize editor with 8 lines - s:text <- new [a + s:text <- new [a b c d @@ -3065,7 +3065,7 @@ e] f g h] - e:&:editor <- new-editor s, screen, 0/left, 10/right + e:&:editor <- new-editor s, screen, 0/left, 10/right screen-should-contain [ . . .a . @@ -3122,7 +3122,7 @@ e] # screen has 1 line for menu + 5 lines for text assume-screen 10/width, 6/height # editor contains a long line in the first page - s:text <- new [a + s:text <- new [a b cdefgh i @@ -3133,7 +3133,7 @@ e] n o] # editor screen triggers wrap of last line - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3146,7 +3146,7 @@ e] # scroll down a page and a line assume-console [ press page-down - left-click 5, 0 + left-click 5, 0 press down-arrow ] run [ @@ -3185,9 +3185,9 @@ e] assume-screen 10/width, 4/height # editor contains a very long line that occupies last two lines of screen # and still has something left over - s:text <- new [a + s:text <- new [a bcdefgh] - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right # some part of last line is not displayed screen-should-contain [ . . @@ -3229,7 +3229,7 @@ e] local-scope assume-screen 10/width, 4/height # text with empty line in second screen - s:text <- new [axx + s:text <- new [axx bxx cxx dxx @@ -3238,7 +3238,7 @@ e] gxx hxx ] - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right screen-should-contain [ . . .axx . @@ -3288,7 +3288,7 @@ e] local-scope assume-screen 10/width, 4/height # text with empty line in second screen - s:text <- new [axy + s:text <- new [axy bxy cxy @@ -3297,7 +3297,7 @@ exy fxy gxy ] - e:&:editor <- new-editor s, screen, 0/left, 4/right + e:&:editor <- new-editor s, screen, 0/left, 4/right screen-should-contain [ . . .axy . diff --git a/html/edit/004-programming-environment.mu.html b/html/edit/004-programming-environment.mu.html index 14ff221b..9019e0d1 100644 --- a/html/edit/004-programming-environment.mu.html +++ b/html/edit/004-programming-environment.mu.html @@ -41,10 +41,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def! main [ local-scope open-console - initial-recipe:text <- restore [recipes.mu] - initial-sandbox:text <- new [] + initial-recipe:text <- restore [recipes.mu] + initial-sandbox:text <- new [] hide-screen 0/screen - env:&:environment <- new-programming-environment 0/screen, initial-recipe, initial-sandbox + env:&:environment <- new-programming-environment 0/screen, initial-recipe, initial-sandbox render-all 0/screen, env, render event-loop 0/screen, 0/console, env # never gets here @@ -59,111 +59,111 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def new-programming-environment screen:&:screen, initial-recipe-contents:text, initial-sandbox-contents:text -> result:&:environment, screen:&:screen [ local-scope load-ingredients - width:num <- screen-width screen - height:num <- screen-height screen + width:num <- screen-width screen + height:num <- screen-height screen # top menu - result <- new environment:type - draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey - button-start:num <- subtract width, 20 - button-on-screen?:bool <- greater-or-equal button-start, 0 + result <- new environment:type + draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey + button-start:num <- subtract width, 20 + button-on-screen?:bool <- greater-or-equal button-start, 0 assert button-on-screen?, [screen too narrow for menu] - screen <- move-cursor screen, 0/row, button-start + screen <- move-cursor screen, 0/row, button-start print screen, [ run (F4) ], 255/white, 161/reddish # dotted line down the middle - divider:num, _ <- divide-with-remainder width, 2 + divider:num, _ <- divide-with-remainder width, 2 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted # recipe editor on the left - recipes:&:editor <- new-editor initial-recipe-contents, screen, 0/left, divider/right + recipes:&:editor <- new-editor initial-recipe-contents, screen, 0/left, divider/right # sandbox editor on the right - sandbox-left:num <- add divider, 1 - current-sandbox:&:editor <- new-editor initial-sandbox-contents, screen, sandbox-left, width/right - *result <- put *result, recipes:offset, recipes - *result <- put *result, current-sandbox:offset, current-sandbox - *result <- put *result, sandbox-in-focus?:offset, 0/false + sandbox-left:num <- add divider, 1 + current-sandbox:&:editor <- new-editor initial-sandbox-contents, screen, sandbox-left, width/right + *result <- put *result, recipes:offset, recipes + *result <- put *result, current-sandbox:offset, current-sandbox + *result <- put *result, sandbox-in-focus?:offset, 0/false <programming-environment-initialization> ] def event-loop screen:&:screen, console:&:console, env:&:environment -> screen:&:screen, console:&:console, env:&:environment [ local-scope load-ingredients - recipes:&:editor <- get *env, recipes:offset - current-sandbox:&:editor <- get *env, current-sandbox:offset - sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset + recipes:&:editor <- get *env, recipes:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset + sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset # if we fall behind we'll stop updating the screen, but then we have to # render the entire screen when we catch up. # todo: test this - render-all-on-no-more-events?:bool <- copy 0/false + render-all-on-no-more-events?:bool <- copy 0/false { # looping over each (keyboard or touch) event as it occurs +next-event - e:event, found?:bool, quit?:bool, console <- read-event console + e:event, found?:bool, quit?:bool, console <- read-event console loop-unless found? break-if quit? # only in tests - trace 10, [app], [next-event] + trace 10, [app], [next-event] <handle-event> # check for global events that will trigger regardless of which editor has focus { - k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant + k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant break-unless is-keycode? <global-keypress> } { - c:char, is-unicode?:bool <- maybe-convert e:event, text:variant + c:char, is-unicode?:bool <- maybe-convert e:event, text:variant break-unless is-unicode? <global-type> } # 'touch' event - send to both sides, see what picks it up { - t:touch-event, is-touch?:bool <- maybe-convert e:event, touch:variant + t:touch-event, is-touch?:bool <- maybe-convert e:event, touch:variant break-unless is-touch? # ignore all but 'left-click' events for now # todo: test this - touch-type:num <- get t, type:offset - is-left-click?:bool <- equal touch-type, 65513/mouse-left + touch-type:num <- get t, type:offset + is-left-click?:bool <- equal touch-type, 65513/mouse-left loop-unless is-left-click?, +next-event - click-row:num <- get t, row:offset - click-column:num <- get t, column:offset + click-row:num <- get t, row:offset + click-column:num <- get t, column:offset # later exceptions for non-editor touches will go here <global-touch> # send to both editors - _ <- move-cursor-in-editor screen, recipes, t - sandbox-in-focus?:bool <- move-cursor-in-editor screen, current-sandbox, t - *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + _ <- move-cursor-in-editor screen, recipes, t + sandbox-in-focus?:bool <- move-cursor-in-editor screen, current-sandbox, t + *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env loop +next-event } # 'resize' event - redraw editor # todo: test this after supporting resize in assume-console { - r:resize-event, is-resize?:bool <- maybe-convert e:event, resize:variant + r:resize-event, is-resize?:bool <- maybe-convert e:event, resize:variant break-unless is-resize? # if more events, we're still resizing; wait until we stop - more-events?:bool <- has-more-events? console + more-events?:bool <- has-more-events? console { break-unless more-events? - render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event + render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event } { break-if more-events? - env, screen <- resize screen, env - screen <- render-all screen, env, render-without-moving-cursor - render-all-on-no-more-events? <- copy 0/false # full render done + env, screen <- resize screen, env + screen <- render-all screen, env, render-without-moving-cursor + render-all-on-no-more-events? <- copy 0/false # full render done } loop +next-event } # if it's not global and not a touch event, send to appropriate editor { hide-screen screen - sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset + sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset { break-if sandbox-in-focus? - screen, recipes, render?:bool <- handle-keyboard-event screen, recipes, e:event + screen, recipes, render?:bool <- handle-keyboard-event screen, recipes, e:event # refresh screen only if no more events # if there are more events to process, wait for them to clear up, then make sure you render-all afterward. - more-events?:bool <- has-more-events? console + more-events?:bool <- has-more-events? console { break-unless more-events? - render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event + render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event jump +finish-event } { @@ -171,27 +171,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { break-unless render-all-on-no-more-events? # no more events, and we have to force render - screen <- render-all screen, env, render - render-all-on-no-more-events? <- copy 0/false + screen <- render-all screen, env, render + render-all-on-no-more-events? <- copy 0/false jump +finish-event } # no more events, no force render { break-unless render? - screen <- render-recipes screen, env, render + screen <- render-recipes screen, env, render jump +finish-event } } } { break-unless sandbox-in-focus? - screen, current-sandbox, render?:bool <- handle-keyboard-event screen, current-sandbox, e:event + screen, current-sandbox, render?:bool <- handle-keyboard-event screen, current-sandbox, e:event # refresh screen only if no more events # if there are more events to process, wait for them to clear up, then make sure you render-all afterward. - more-events?:bool <- has-more-events? console + more-events?:bool <- has-more-events? console { break-unless more-events? - render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event + render-all-on-no-more-events? <- copy 1/true # no rendering now, full rendering on some future event jump +finish-event } { @@ -199,20 +199,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { break-unless render-all-on-no-more-events? # no more events, and we have to force render - screen <- render-all screen, env, render - render-all-on-no-more-events? <- copy 0/false + screen <- render-all screen, env, render + render-all-on-no-more-events? <- copy 0/false jump +finish-event } # no more events, no force render { break-unless render? - screen <- render-sandbox-side screen, env, render + screen <- render-sandbox-side screen, env, render jump +finish-event } } } +finish-event - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen } loop @@ -223,24 +223,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients clear-screen screen # update screen dimensions - width:num <- screen-width screen - divider:num, _ <- divide-with-remainder width, 2 + width:num <- screen-width screen + divider:num, _ <- divide-with-remainder width, 2 # update recipe editor - recipes:&:editor <- get *env, recipes:offset - right:num <- subtract divider, 1 - *recipes <- put *recipes, right:offset, right + recipes:&:editor <- get *env, recipes:offset + right:num <- subtract divider, 1 + *recipes <- put *recipes, right:offset, right # reset cursor (later we'll try to preserve its position) - *recipes <- put *recipes, cursor-row:offset, 1 - *recipes <- put *recipes, cursor-column:offset, 0 + *recipes <- put *recipes, cursor-row:offset, 1 + *recipes <- put *recipes, cursor-column:offset, 0 # update sandbox editor - current-sandbox:&:editor <- get *env, current-sandbox:offset - left:num <- add divider, 1 - *current-sandbox <- put *current-sandbox, left:offset, left - right:num <- subtract width, 1 - *current-sandbox <- put *current-sandbox, right:offset, right + current-sandbox:&:editor <- get *env, current-sandbox:offset + left:num <- add divider, 1 + *current-sandbox <- put *current-sandbox, left:offset, left + right:num <- subtract width, 1 + *current-sandbox <- put *current-sandbox, right:offset, right # reset cursor (later we'll try to preserve its position) - *current-sandbox <- put *current-sandbox, cursor-row:offset, 1 - *current-sandbox <- put *current-sandbox, cursor-column:offset, left + *current-sandbox <- put *current-sandbox, cursor-row:offset, 1 + *current-sandbox <- put *current-sandbox, cursor-column:offset, left ] # Variant of 'render' that updates cursor-row and cursor-column based on @@ -249,81 +249,81 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def render-without-moving-cursor screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ local-scope load-ingredients - return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 - left:num <- get *editor, left:offset - screen-height:num <- screen-height screen - right:num <- get *editor, right:offset - curr:&:duplex-list:char <- get *editor, top-of-screen:offset - prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev - curr <- next curr + return-unless editor, 1/top, 0/left, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + left:num <- get *editor, left:offset + screen-height:num <- screen-height screen + right:num <- get *editor, right:offset + curr:&:duplex-list:char <- get *editor, top-of-screen:offset + prev:&:duplex-list:char <- copy curr # just in case curr becomes null and we can't compute prev + curr <- next curr +render-loop-initialization - color:num <- copy 7/white - row:num <- copy 1/top - column:num <- copy left + color:num <- copy 7/white + row:num <- copy 1/top + column:num <- copy left # save before-cursor - old-before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + old-before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset # initialze cursor-row/cursor-column/before-cursor to the top of the screen # by default - *editor <- put *editor, cursor-row:offset, row - *editor <- put *editor, cursor-column:offset, column - top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset - *editor <- put *editor, before-cursor:offset, top-of-screen - screen <- move-cursor screen, row, column + *editor <- put *editor, cursor-row:offset, row + *editor <- put *editor, cursor-column:offset, column + top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset + *editor <- put *editor, before-cursor:offset, top-of-screen + screen <- move-cursor screen, row, column { +next-character break-unless curr - off-screen?:bool <- greater-or-equal row, screen-height + off-screen?:bool <- greater-or-equal row, screen-height break-if off-screen? # if we find old-before-cursor still on the new resized screen, update # editor.cursor-row and editor.cursor-column based on # old-before-cursor { - at-cursor?:bool <- equal old-before-cursor, prev + at-cursor?:bool <- equal old-before-cursor, prev break-unless at-cursor? - *editor <- put *editor, cursor-row:offset, row - *editor <- put *editor, cursor-column:offset, column - *editor <- put *editor, before-cursor:offset, old-before-cursor + *editor <- put *editor, cursor-row:offset, row + *editor <- put *editor, cursor-column:offset, column + *editor <- put *editor, before-cursor:offset, old-before-cursor } - c:char <- get *curr, value:offset + c:char <- get *curr, value:offset <character-c-received> { # newline? move to left rather than 0 - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # clear rest of line in this window clear-line-until screen, right # skip to next line - row <- add row, 1 - column <- copy left - screen <- move-cursor screen, row, column - curr <- next curr - prev <- next prev + row <- add row, 1 + column <- copy left + screen <- move-cursor screen, row, column + curr <- next curr + prev <- next prev loop +next-character } { # at right? wrap. even if there's only one more letter left; we need # room for clicking on the cursor after it. - at-right?:bool <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? # print wrap icon - wrap-icon:char <- copy 8617/loop-back-to-left + wrap-icon:char <- copy 8617/loop-back-to-left print screen, wrap-icon, 245/grey - column <- copy left - row <- add row, 1 - screen <- move-cursor screen, row, column + column <- copy left + row <- add row, 1 + screen <- move-cursor screen, row, column # don't increment curr loop +next-character } print screen, c, color - curr <- next curr - prev <- next prev - column <- add column, 1 + curr <- next curr + prev <- next prev + column <- add column, 1 loop } # save first character off-screen - *editor <- put *editor, bottom-of-screen:offset, curr - *editor <- put *editor, bottom:offset, row - return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 + *editor <- put *editor, bottom-of-screen:offset, curr + *editor <- put *editor, bottom:offset, row + return row, column, screen/same-as-ingredient:0, editor/same-as-ingredient:1 ] @@ -332,23 +332,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize both halves of screen - env:&:environment <- new-programming-environment screen, [abc], [def] + env:&:environment <- new-programming-environment screen, [abc], [def] # focus on both sides assume-console [ - left-click 1, 1 - left-click 1, 17 + left-click 1, 1 + left-click 1, 17 ] # check cursor column in each run [ event-loop screen, console, env - recipes:&:editor <- get *env, recipes:offset - 5:num/raw <- get *recipes, cursor-column:offset - sandbox:&:editor <- get *env, current-sandbox:offset - 7:num/raw <- get *sandbox, cursor-column:offset + recipes:&:editor <- get *env, recipes:offset + 5:num/raw <- get *recipes, cursor-column:offset + sandbox:&:editor <- get *env, current-sandbox:offset + 7:num/raw <- get *sandbox, cursor-column:offset ] memory-should-contain [ - 5 <- 1 - 7 <- 17 + 5 <- 1 + 7 <- 17 ] ] @@ -357,21 +357,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize both halves of screen - env:&:environment <- new-programming-environment screen, [abc], [def] + env:&:environment <- new-programming-environment screen, [abc], [def] render-all screen, env, render # type one letter in each of them assume-console [ - left-click 1, 1 + left-click 1, 1 type [0] - left-click 1, 17 + left-click 1, 17 type [1] ] run [ event-loop screen, console, env - recipes:&:editor <- get *env, recipes:offset - 5:num/raw <- get *recipes, cursor-column:offset - sandbox:&:editor <- get *env, current-sandbox:offset - 7:num/raw <- get *sandbox, cursor-column:offset + recipes:&:editor <- get *env, recipes:offset + 5:num/raw <- get *recipes, cursor-column:offset + sandbox:&:editor <- get *env, current-sandbox:offset + 7:num/raw <- get *sandbox, cursor-column:offset ] screen-should-contain [ . run (F4) . # this line has a different background, but we don't test that yet @@ -380,12 +380,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . ╎ . ] memory-should-contain [ - 5 <- 2 # cursor column of recipe editor - 7 <- 18 # cursor column of sandbox editor + 5 <- 2 # cursor column of recipe editor + 7 <- 18 # cursor column of sandbox editor ] # show the cursor at the right window run [ - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] screen-should-contain [ @@ -401,7 +401,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 60/width, 10/height run [ - env:&:environment <- new-programming-environment screen, [abc], [def] + env:&:environment <- new-programming-environment screen, [abc], [def] render-all screen, env, render ] # divider isn't messed up @@ -418,13 +418,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 30/width, 5/height - env:&:environment <- new-programming-environment screen, [abc], [def] + env:&:environment <- new-programming-environment screen, [abc], [def] render-all screen, env, render # initialize programming environment and highlight cursor assume-console [] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # is cursor at the right place? @@ -440,7 +440,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # cursor should still be right @@ -457,9 +457,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 30/width, 5/height # initialize sandbox side with two lines - s:text <- new [abc + s:text <- new [abc def] - env:&:environment <- new-programming-environment screen, [], s:text + env:&:environment <- new-programming-environment screen, [], s:text render-all screen, env, render screen-should-contain [ . run (F4) . @@ -470,12 +470,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # position cursor at start of second line and hit backspace assume-console [ - left-click 2, 16 + left-click 2, 16 press backspace ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # cursor moves to end of old line @@ -490,31 +490,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def render-all screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ local-scope load-ingredients - trace 10, [app], [render all] + trace 10, [app], [render all] hide-screen screen # top menu - trace 11, [app], [render top menu] - width:num <- screen-width screen - draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey - button-start:num <- subtract width, 20 - button-on-screen?:bool <- greater-or-equal button-start, 0 + trace 11, [app], [render top menu] + width:num <- screen-width screen + draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey + button-start:num <- subtract width, 20 + button-on-screen?:bool <- greater-or-equal button-start, 0 assert button-on-screen?, [screen too narrow for menu] - screen <- move-cursor screen, 0/row, button-start + screen <- move-cursor screen, 0/row, button-start print screen, [ run (F4) ], 255/white, 161/reddish # dotted line down the middle - trace 11, [app], [render divider] - divider:num, _ <- divide-with-remainder width, 2 - height:num <- screen-height screen + trace 11, [app], [render divider] + divider:num, _ <- divide-with-remainder width, 2 + height:num <- screen-height screen draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted # - screen <- render-recipes screen, env, render-editor - screen <- render-sandbox-side screen, env, render-editor + screen <- render-recipes screen, env, render-editor + screen <- render-sandbox-side screen, env, render-editor <render-components-end> # - recipes:&:editor <- get *env, recipes:offset - current-sandbox:&:editor <- get *env, current-sandbox:offset - sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + recipes:&:editor <- get *env, recipes:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset + sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env # show-screen screen ] @@ -522,18 +522,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def render-recipes screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [ local-scope load-ingredients - trace 11, [app], [render recipes] - recipes:&:editor <- get *env, recipes:offset + trace 11, [app], [render recipes] + recipes:&:editor <- get *env, recipes:offset # render recipes - left:num <- get *recipes, left:offset - right:num <- get *recipes, right:offset - row:num, column:num, screen <- call render-editor, screen, recipes + left:num <- get *recipes, left:offset + right:num <- get *recipes, right:offset + row:num, column:num, screen <- call render-editor, screen, recipes clear-line-until screen, right - row <- add row, 1 + row <- add row, 1 <render-recipe-components-end> # draw dotted line after recipes draw-horizontal screen, row, left, right, 9480/horizontal-dotted - row <- add row, 1 + row <- add row, 1 clear-screen-from screen, row, left, left, right ] @@ -541,15 +541,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 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 [ local-scope load-ingredients - current-sandbox:&:editor <- get *env, current-sandbox:offset - left:num <- get *current-sandbox, left:offset - right:num <- get *current-sandbox, right:offset - row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox + current-sandbox:&:editor <- get *env, current-sandbox:offset + left:num <- get *current-sandbox, left:offset + right:num <- get *current-sandbox, right:offset + row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox clear-line-until screen, right - row <- add row, 1 + row <- add row, 1 # draw solid line after code (you'll see why in later layers) draw-horizontal screen, row, left, right - row <- add row, 1 + row <- add row, 1 clear-screen-from screen, row, left, left, right ] @@ -559,15 +559,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <update-cursor-special-cases> { break-if sandbox-in-focus? - cursor-row:num <- get *recipes, cursor-row:offset - cursor-column:num <- get *recipes, cursor-column:offset + cursor-row:num <- get *recipes, cursor-row:offset + cursor-column:num <- get *recipes, cursor-column:offset } { break-unless sandbox-in-focus? - cursor-row:num <- get *current-sandbox, cursor-row:offset - cursor-column:num <- get *current-sandbox, cursor-column:offset + cursor-row:num <- get *current-sandbox, cursor-row:offset + cursor-column:num <- get *current-sandbox, cursor-column:offset } - screen <- move-cursor screen, cursor-row, cursor-column + screen <- move-cursor screen, cursor-row, cursor-column ] # like 'render' for texts, but with colorization for comments like in the editor @@ -575,60 +575,60 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients return-unless s - color:num <- copy 7/white - column:num <- copy left - screen <- move-cursor screen, row, column - screen-height:num <- screen-height screen - i:num <- copy 0 - len:num <- length *s + color:num <- copy 7/white + column:num <- copy left + screen <- move-cursor screen, row, column + screen-height:num <- screen-height screen + i:num <- copy 0 + len:num <- length *s { +next-character - done?:bool <- greater-or-equal i, len + done?:bool <- greater-or-equal i, len break-if done? - done? <- greater-or-equal row, screen-height + done? <- greater-or-equal row, screen-height break-if done? - c:char <- index *s, i + c:char <- index *s, i <character-c-received> # only line different from render { # at right? wrap. - at-right?:bool <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? # print wrap icon - wrap-icon:char <- copy 8617/loop-back-to-left + wrap-icon:char <- copy 8617/loop-back-to-left print screen, wrap-icon, 245/grey - column <- copy left - row <- add row, 1 - screen <- move-cursor screen, row, column + column <- copy left + row <- add row, 1 + screen <- move-cursor screen, row, column loop +next-character # retry i } - i <- add i, 1 + i <- add i, 1 { # newline? move to left rather than 0 - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # clear rest of line in this window { - done?:bool <- greater-than column, right + done?:bool <- greater-than column, right break-if done? - space:char <- copy 32/space + space:char <- copy 32/space print screen, space - column <- add column, 1 + column <- add column, 1 loop } - row <- add row, 1 - column <- copy left - screen <- move-cursor screen, row, column + row <- add row, 1 + column <- copy left + screen <- move-cursor screen, row, column loop +next-character } print screen, c, color - column <- add column, 1 + column <- add column, 1 loop } - was-at-left?:bool <- equal column, left + was-at-left?:bool <- equal column, left clear-line-until screen, right { break-if was-at-left? - row <- add row, 1 + row <- add row, 1 } move-cursor screen, row, left ] @@ -637,9 +637,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-type> [ { - redraw-screen?:bool <- equal c, 12/ctrl-l + redraw-screen?:bool <- equal c, 12/ctrl-l break-unless redraw-screen? - screen <- render-all screen, env:&:environment, render + screen <- render-all screen, env:&:environment, render sync-screen screen loop +next-event } @@ -650,12 +650,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-type> [ { - switch-side?:bool <- equal c, 14/ctrl-n + switch-side?:bool <- equal c, 14/ctrl-n break-unless switch-side? - sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset - sandbox-in-focus? <- not sandbox-in-focus? - *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset + sandbox-in-focus? <- not sandbox-in-focus? + *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus? + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env loop +next-event } ] @@ -665,23 +665,23 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [ local-scope load-ingredients - style:char, style-found?:bool <- next-ingredient + style:char, style-found?:bool <- next-ingredient { break-if style-found? - style <- copy 9474/vertical + style <- copy 9474/vertical } - color:num, color-found?:bool <- next-ingredient + color:num, color-found?:bool <- next-ingredient { # default color to white break-if color-found? - color <- copy 245/grey + color <- copy 245/grey } { - continue?:bool <- lesser-than y, bottom + continue?:bool <- lesser-than y, bottom break-unless continue? - screen <- move-cursor screen, y, col + screen <- move-cursor screen, y, col print screen, style, color - y <- add y, 1 + y <- add y, 1 loop } ] diff --git a/html/edit/005-sandbox.mu.html b/html/edit/005-sandbox.mu.html index 735a45de..91e61166 100644 --- a/html/edit/005-sandbox.mu.html +++ b/html/edit/005-sandbox.mu.html @@ -45,11 +45,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def! main [ local-scope open-console - initial-recipe:text <- restore [recipes.mu] - initial-sandbox:text <- new [] + initial-recipe:text <- restore [recipes.mu] + initial-sandbox:text <- new [] hide-screen 0/screen - env:&:environment <- new-programming-environment 0/screen, initial-recipe, initial-sandbox - env <- restore-sandboxes env + env:&:environment <- new-programming-environment 0/screen, initial-recipe, initial-sandbox + env <- restore-sandboxes env render-all 0/screen, env, render event-loop 0/screen, 0/console, env # never gets here @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <programming-environment-initialization> [ - *result <- put *result, render-from:offset, -1 + *result <- put *result, render-from:offset, -1 ] container sandbox [ @@ -82,7 +82,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 100/width, 15/height # recipe editor is empty # sandbox editor contains an instruction without storing outputs - env:&:environment <- new-programming-environment screen, [], [divide-with-remainder 11, 3] + env:&:environment <- new-programming-environment screen, [], [divide-with-remainder 11, 3] # run the code in the editors assume-console [ press F4 @@ -133,7 +133,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # run another command assume-console [ - left-click 1, 80 + left-click 1, 80 type [add 2, 2] press F4 ] @@ -161,17 +161,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-keypress> [ # F4? load all code and run all sandboxes. { - do-run?:bool <- equal k, 65532/F4 + do-run?:bool <- equal k, 65532/F4 break-unless do-run? - screen <- update-status screen, [running... ], 245/grey - error?:bool, env, screen <- run-sandboxes env, screen + screen <- update-status screen, [running... ], 245/grey + error?:bool, env, screen <- run-sandboxes env, screen # F4 might update warnings and results on both sides - screen <- render-all screen, env, render + screen <- render-all screen, env, render { break-if error? - screen <- update-status screen, [ ], 245/grey + screen <- update-status screen, [ ], 245/grey } - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env loop +next-event } ] @@ -179,41 +179,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def run-sandboxes env:&:environment, screen:&:screen -> errors-found?:bool, env:&:environment, screen:&:screen [ local-scope load-ingredients - errors-found?:bool, env, screen <- update-recipes env, screen + errors-found?:bool, env, screen <- update-recipes env, screen return-if errors-found? # check contents of right editor (sandbox) <run-sandboxes-begin> - current-sandbox:&:editor <- get *env, current-sandbox:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset { - sandbox-contents:text <- editor-contents current-sandbox + sandbox-contents:text <- editor-contents current-sandbox break-unless sandbox-contents # if contents exist, first save them # run them and turn them into a new sandbox - new-sandbox:&:sandbox <- new sandbox:type - *new-sandbox <- put *new-sandbox, data:offset, sandbox-contents + new-sandbox:&:sandbox <- new sandbox:type + *new-sandbox <- put *new-sandbox, data:offset, sandbox-contents # push to head of sandbox list - dest:&:sandbox <- get *env, sandbox:offset - *new-sandbox <- put *new-sandbox, next-sandbox:offset, dest - *env <- put *env, sandbox:offset, new-sandbox + dest:&:sandbox <- get *env, sandbox:offset + *new-sandbox <- put *new-sandbox, next-sandbox:offset, dest + *env <- put *env, sandbox:offset, new-sandbox # update sandbox count - sandbox-count:num <- get *env, number-of-sandboxes:offset - sandbox-count <- add sandbox-count, 1 - *env <- put *env, number-of-sandboxes:offset, sandbox-count + sandbox-count:num <- get *env, number-of-sandboxes:offset + sandbox-count <- add sandbox-count, 1 + *env <- put *env, number-of-sandboxes:offset, sandbox-count # clear sandbox editor - init:&:duplex-list:char <- push 167/§, 0/tail - *current-sandbox <- put *current-sandbox, data:offset, init - *current-sandbox <- put *current-sandbox, top-of-screen:offset, init + init:&:duplex-list:char <- push 167/§, 0/tail + *current-sandbox <- put *current-sandbox, data:offset, init + *current-sandbox <- put *current-sandbox, top-of-screen:offset, init } # save all sandboxes before running, just in case we die when running save-sandboxes env # run all sandboxes - curr:&:sandbox <- get *env, sandbox:offset - idx:num <- copy 0 + curr:&:sandbox <- get *env, sandbox:offset + idx:num <- copy 0 { break-unless curr - curr <- update-sandbox curr, env, idx - curr <- get *curr, next-sandbox:offset - idx <- add idx, 1 + curr <- update-sandbox curr, env, idx + curr <- get *curr, next-sandbox:offset + idx <- add idx, 1 loop } <run-sandboxes-end> @@ -224,46 +224,46 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def update-recipes env:&:environment, screen:&:screen -> errors-found?:bool, env:&:environment, screen:&:screen [ local-scope load-ingredients - recipes:&:editor <- get *env, recipes:offset - in:text <- editor-contents recipes + recipes:&:editor <- get *env, recipes:offset + in:text <- editor-contents recipes save [recipes.mu], in # newlayer: persistence reload in - errors-found? <- copy 0/false + errors-found? <- copy 0/false ] # replaced in a later layer def! update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [ local-scope load-ingredients - data:text <- get *sandbox, data:offset - response:text, _, fake-screen:&:screen <- run-sandboxed data - *sandbox <- put *sandbox, response:offset, response - *sandbox <- put *sandbox, screen:offset, fake-screen + data:text <- get *sandbox, data:offset + response:text, _, fake-screen:&:screen <- run-sandboxed data + *sandbox <- put *sandbox, response:offset, response + *sandbox <- put *sandbox, screen:offset, fake-screen ] def update-status screen:&:screen, msg:text, color:num -> screen:&:screen [ local-scope load-ingredients - screen <- move-cursor screen, 0, 2 - screen <- print screen, msg, color, 238/grey/background + screen <- move-cursor screen, 0, 2 + screen <- print screen, msg, color, 238/grey/background ] def save-sandboxes env:&:environment [ local-scope load-ingredients - current-sandbox:&:editor <- get *env, current-sandbox:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset # first clear previous versions, in case we deleted some sandbox - $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' - curr:&:sandbox <- get *env, sandbox:offset - idx:num <- copy 0 + $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' + curr:&:sandbox <- get *env, sandbox:offset + idx:num <- copy 0 { break-unless curr - data:text <- get *curr, data:offset - filename:text <- to-text idx + data:text <- get *curr, data:offset + filename:text <- to-text idx save filename, data <end-save-sandbox> - idx <- add idx, 1 - curr <- get *curr, next-sandbox:offset + idx <- add idx, 1 + curr <- get *curr, next-sandbox:offset loop } ] @@ -271,24 +271,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 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 [ local-scope load-ingredients - trace 11, [app], [render sandbox side] - current-sandbox:&:editor <- get *env, current-sandbox:offset - row:num, column:num <- copy 1, 0 - left:num <- get *current-sandbox, left:offset - right:num <- get *current-sandbox, right:offset + trace 11, [app], [render sandbox side] + current-sandbox:&:editor <- get *env, current-sandbox:offset + row:num, column:num <- copy 1, 0 + left:num <- get *current-sandbox, left:offset + right:num <- get *current-sandbox, right:offset # render sandbox editor - render-from:num <- get *env, render-from:offset + render-from:num <- get *env, render-from:offset { - render-current-sandbox?:bool <- equal render-from, -1 + render-current-sandbox?:bool <- equal render-from, -1 break-unless render-current-sandbox? - row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox + row, column, screen, current-sandbox <- call render-editor, screen, current-sandbox clear-screen-from screen, row, column, left, right - row <- add row, 1 + row <- add row, 1 } # render sandboxes draw-horizontal screen, row, left, right - sandbox:&:sandbox <- get *env, sandbox:offset - row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from + sandbox:&:sandbox <- get *env, sandbox:offset + row, screen <- render-sandboxes screen, sandbox, left, right, row, render-from clear-rest-of-screen screen, row, left, right ] @@ -296,40 +296,40 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients return-unless sandbox - screen-height:num <- screen-height screen - at-bottom?:bool <- greater-or-equal row, screen-height + screen-height:num <- screen-height screen + at-bottom?:bool <- greater-or-equal row, screen-height return-if at-bottom?:bool - hidden?:bool <- lesser-than idx, render-from + hidden?:bool <- lesser-than idx, render-from { break-if hidden? # render sandbox menu - row <- add row, 1 - screen <- move-cursor screen, row, left - screen <- render-sandbox-menu screen, idx, left, right + row <- add row, 1 + screen <- move-cursor screen, row, left + screen <- render-sandbox-menu screen, idx, left, right # save menu row so we can detect clicks to it later - *sandbox <- put *sandbox, starting-row-on-screen:offset, row + *sandbox <- put *sandbox, starting-row-on-screen:offset, row # render sandbox contents - row <- add row, 1 - screen <- move-cursor screen, row, left - sandbox-data:text <- get *sandbox, data:offset - row, screen <- render-code screen, sandbox-data, left, right, row - *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row + row <- add row, 1 + screen <- move-cursor screen, row, left + sandbox-data:text <- get *sandbox, data:offset + row, screen <- render-code screen, sandbox-data, left, right, row + *sandbox <- put *sandbox, code-ending-row-on-screen:offset, row # render sandbox warnings, screen or response, in that order - sandbox-response:text <- get *sandbox, response:offset + sandbox-response:text <- get *sandbox, response:offset <render-sandbox-results> { - sandbox-screen:&:screen <- get *sandbox, screen:offset - empty-screen?:bool <- fake-screen-is-empty? sandbox-screen + sandbox-screen:&:screen <- get *sandbox, screen:offset + empty-screen?:bool <- fake-screen-is-empty? sandbox-screen break-if empty-screen? - row, screen <- render-screen screen, sandbox-screen, left, right, row + row, screen <- render-screen screen, sandbox-screen, left, right, row } { break-unless empty-screen? <render-sandbox-response> - row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row + row, screen <- render-text screen, sandbox-response, left, right, 245/grey, row } +render-sandbox-end - at-bottom?:bool <- greater-or-equal row, screen-height + at-bottom?:bool <- greater-or-equal row, screen-height return-if at-bottom? # draw solid line after sandbox draw-horizontal screen, row, left, right @@ -337,33 +337,33 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # if hidden, reset row attributes { break-unless hidden? - *sandbox <- put *sandbox, starting-row-on-screen:offset, 0 - *sandbox <- put *sandbox, code-ending-row-on-screen:offset, 0 + *sandbox <- put *sandbox, starting-row-on-screen:offset, 0 + *sandbox <- put *sandbox, code-ending-row-on-screen:offset, 0 <end-render-sandbox-reset-hidden> } # draw next sandbox - next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset - next-idx:num <- add idx, 1 - row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx + next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset + next-idx:num <- add idx, 1 + row, screen <- render-sandboxes screen, next-sandbox, left, right, row, render-from, next-idx ] def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num -> screen:&:screen [ local-scope load-ingredients move-cursor-to-column screen, left - 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 + 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 print screen, sandbox-index, 232/dark-grey, 245/grey - start-buttons:num <- subtract edit-button-left, 1 + start-buttons:num <- subtract edit-button-left, 1 clear-line-until screen, start-buttons, 245/grey print screen, [edit], 232/black, 94/background-orange clear-line-until screen, edit-button-right, 94/background-orange - _, col:num <- cursor-position screen - at-start-of-copy-button?:bool <- equal col, copy-button-left + _, col:num <- cursor-position screen + at-start-of-copy-button?:bool <- equal col, copy-button-left assert at-start-of-copy-button?, [aaa] print screen, [copy], 232/black, 58/background-green clear-line-until screen, copy-button-right, 58/background-green - _, col:num <- cursor-position screen - at-start-of-delete-button?:bool <- equal col, delete-button-left + _, col:num <- cursor-position screen + at-start-of-delete-button?:bool <- equal col, delete-button-left assert at-start-of-delete-button?, [bbb] print screen, [delete], 232/black, 52/background-red clear-line-until screen, right, 52/background-red @@ -375,16 +375,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def sandbox-menu-columns left:num, right:num -> edit-button-left:num, edit-button-right:num, copy-button-left:num, copy-button-right:num, delete-button-left:num [ local-scope load-ingredients - start-buttons:num <- add left, 4/space-for-sandbox-index - buttons-space:num <- subtract right, start-buttons - button-width:num <- divide-with-remainder buttons-space, 3 # integer division - buttons-wide-enough?:bool <- greater-or-equal button-width, 8 + start-buttons:num <- add left, 4/space-for-sandbox-index + buttons-space:num <- subtract right, start-buttons + button-width:num <- divide-with-remainder buttons-space, 3 # integer division + buttons-wide-enough?:bool <- greater-or-equal button-width, 8 assert buttons-wide-enough?, [sandbox must be at least 30 or so characters wide] - edit-button-left:num <- copy start-buttons - copy-button-left:num <- add start-buttons, button-width - edit-button-right:num <- subtract copy-button-left, 1 - delete-button-left:num <- subtract right, button-width - copy-button-right:num <- subtract delete-button-left, 1 + edit-button-left:num <- copy start-buttons + copy-button-left:num <- add start-buttons, button-width + edit-button-right:num <- subtract copy-button-left, 1 + delete-button-left:num <- subtract right, button-width + copy-button-right:num <- subtract delete-button-left, 1 ] # print a text 's' to 'editor' in 'color' starting at 'row' @@ -393,58 +393,58 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients return-unless s - column:num <- copy left - screen <- move-cursor screen, row, column - screen-height:num <- screen-height screen - i:num <- copy 0 - len:num <- length *s + column:num <- copy left + screen <- move-cursor screen, row, column + screen-height:num <- screen-height screen + i:num <- copy 0 + len:num <- length *s { +next-character - done?:bool <- greater-or-equal i, len + done?:bool <- greater-or-equal i, len break-if done? - done? <- greater-or-equal row, screen-height + done? <- greater-or-equal row, screen-height break-if done? - c:char <- index *s, i + c:char <- index *s, i { # at right? wrap. - at-right?:bool <- equal column, right + at-right?:bool <- equal column, right break-unless at-right? # print wrap icon - wrap-icon:char <- copy 8617/loop-back-to-left + wrap-icon:char <- copy 8617/loop-back-to-left print screen, wrap-icon, 245/grey - column <- copy left - row <- add row, 1 - screen <- move-cursor screen, row, column + column <- copy left + row <- add row, 1 + screen <- move-cursor screen, row, column loop +next-character # retry i } - i <- add i, 1 + i <- add i, 1 { # newline? move to left rather than 0 - newline?:bool <- equal c, 10/newline + newline?:bool <- equal c, 10/newline break-unless newline? # clear rest of line in this window { - done?:bool <- greater-than column, right + done?:bool <- greater-than column, right break-if done? - space:char <- copy 32/space + space:char <- copy 32/space print screen, space - column <- add column, 1 + column <- add column, 1 loop } - row <- add row, 1 - column <- copy left - screen <- move-cursor screen, row, column + row <- add row, 1 + column <- copy left + screen <- move-cursor screen, row, column loop +next-character } print screen, c, color - column <- add column, 1 + column <- add column, 1 loop } - was-at-left?:bool <- equal column, left + was-at-left?:bool <- equal column, left clear-line-until screen, right { break-if was-at-left? - row <- add row, 1 + row <- add row, 1 } move-cursor screen, row, left ] @@ -454,32 +454,32 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # read all scenarios, pushing them to end of a list of scenarios - idx:num <- copy 0 - curr:&:sandbox <- copy 0 - prev:&:sandbox <- copy 0 + idx:num <- copy 0 + curr:&:sandbox <- copy 0 + prev:&:sandbox <- copy 0 { - filename:text <- to-text idx - contents:text <- restore filename + filename:text <- to-text idx + contents:text <- restore filename break-unless contents # stop at first error; assuming file didn't exist # todo: handle empty sandbox # create new sandbox for file - curr <- new sandbox:type - *curr <- put *curr, data:offset, contents + curr <- new sandbox:type + *curr <- put *curr, data:offset, contents <end-restore-sandbox> { break-if idx - *env <- put *env, sandbox:offset, curr + *env <- put *env, sandbox:offset, curr } { break-unless idx - *prev <- put *prev, next-sandbox:offset, curr + *prev <- put *prev, next-sandbox:offset, curr } - idx <- add idx, 1 - prev <- copy curr + idx <- add idx, 1 + prev <- copy curr loop } # update sandbox count - *env <- put *env, number-of-sandboxes:offset, idx + *env <- put *env, number-of-sandboxes:offset, idx ] # print the fake sandbox screen to 'screen' with appropriate delimiters @@ -489,62 +489,62 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color load-ingredients return-unless sandbox-screen # print 'screen:' - row <- render-text screen, [screen:], left, right, 245/grey, row - screen <- move-cursor screen, row, left + row <- render-text screen, [screen:], left, right, 245/grey, row + screen <- move-cursor screen, row, left # start printing sandbox-screen - column:num <- copy left - s-width:num <- screen-width sandbox-screen - s-height:num <- screen-height sandbox-screen - buf:&:@:screen-cell <- get *sandbox-screen, data:offset - stop-printing:num <- add left, s-width, 3 - max-column:num <- min stop-printing, right - i:num <- copy 0 - len:num <- length *buf - screen-height:num <- screen-height screen + column:num <- copy left + s-width:num <- screen-width sandbox-screen + s-height:num <- screen-height sandbox-screen + buf:&:@:screen-cell <- get *sandbox-screen, data:offset + stop-printing:num <- add left, s-width, 3 + max-column:num <- min stop-printing, right + i:num <- copy 0 + len:num <- length *buf + screen-height:num <- screen-height screen { - done?:bool <- greater-or-equal i, len + done?:bool <- greater-or-equal i, len break-if done? - done? <- greater-or-equal row, screen-height + done? <- greater-or-equal row, screen-height break-if done? - column <- copy left - screen <- move-cursor screen, row, column + column <- copy left + screen <- move-cursor screen, row, column # initial leader for each row: two spaces and a '.' - space:char <- copy 32/space + space:char <- copy 32/space print screen, space, 245/grey print screen, space, 245/grey - full-stop:char <- copy 46/period + full-stop:char <- copy 46/period print screen, full-stop, 245/grey - column <- add left, 3 + column <- add left, 3 { # print row - row-done?:bool <- greater-or-equal column, max-column + row-done?:bool <- greater-or-equal column, max-column break-if row-done? - curr:screen-cell <- index *buf, i - c:char <- get curr, contents:offset - color:num <- get curr, color:offset + curr:screen-cell <- index *buf, i + c:char <- get curr, contents:offset + color:num <- get curr, color:offset { # damp whites down to grey - white?:bool <- equal color, 7/white + white?:bool <- equal color, 7/white break-unless white? - color <- copy 245/grey + color <- copy 245/grey } print screen, c, color - column <- add column, 1 - i <- add i, 1 + column <- add column, 1 + i <- add i, 1 loop } # print final '.' print screen, full-stop, 245/grey - column <- add column, 1 + column <- add column, 1 { # clear rest of current line - line-done?:bool <- greater-than column, right + line-done?:bool <- greater-than column, right break-if line-done? print screen, space - column <- add column, 1 + column <- add column, 1 loop } - row <- add row, 1 + row <- add row, 1 loop } ] @@ -554,14 +554,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) - recipes:text <- new [ + recipes:text <- new [ recipe foo [ local-scope z:num <- add 2, 2 reply z ]] # sandbox editor contains an instruction without storing outputs - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run the code in the editors assume-console [ press F4 @@ -580,7 +580,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # make a change (incrementing one of the args to 'add'), then rerun assume-console [ - left-click 4, 28 # one past the value of the second arg + left-click 4, 28 # one past the value of the second arg press backspace type [3] press F4 @@ -608,7 +608,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 100/width, 20/height # left editor is empty # right editor contains an instruction - env:&:environment <- new-programming-environment screen, [], [print-integer screen, 4] + env:&:environment <- new-programming-environment screen, [], [print-integer screen, 4] # run the code in the editor assume-console [ press F4 @@ -637,37 +637,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def editor-contents editor:&:editor -> result:text [ local-scope load-ingredients - buf:&:buffer <- new-buffer 80 - curr:&:duplex-list:char <- get *editor, data:offset + buf:&:buffer <- new-buffer 80 + curr:&:duplex-list:char <- get *editor, data:offset # skip § sentinel assert curr, [editor without data is illegal; must have at least a sentinel] - curr <- next curr - return-unless curr, 0 + curr <- next curr + return-unless curr, 0 { break-unless curr - c:char <- get *curr, value:offset - buf <- append buf, c - curr <- next curr + c:char <- get *curr, value:offset + buf <- append buf, c + curr <- next curr loop } - result <- buffer-to-array buf + result <- buffer-to-array buf ] scenario editor-provides-edited-contents [ local-scope assume-screen 10/width, 5/height - e:&:editor <- new-editor [abc], screen, 0/left, 10/right + e:&:editor <- new-editor [abc], screen, 0/left, 10/right assume-console [ - left-click 1, 2 + left-click 1, 2 type [def] ] run [ editor-event-loop screen, console, e - s:text <- editor-contents e - 1:@:char/raw <- copy *s + s:text <- editor-contents e + 1:@:char/raw <- copy *s ] memory-should-contain [ - 1:array:character <- [abdefc] + 1:array:character <- [abdefc] ] ] @@ -677,7 +677,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render assume-console [ press enter @@ -698,7 +698,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render assume-console [ press enter @@ -706,7 +706,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press down-arrow # while cursor isn't at bottom ] event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor # cursor moves back to bottom screen-should-contain [ @@ -726,28 +726,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <render-recipe-components-end> [ - *env <- put *env, recipe-bottom:offset, row + *env <- put *env, recipe-bottom:offset, row ] after <global-keypress> [ { break-if sandbox-in-focus? - down-arrow?:bool <- equal k, 65516/down-arrow + down-arrow?:bool <- equal k, 65516/down-arrow break-unless down-arrow? - recipe-editor:&:editor <- get *env, recipes:offset - recipe-cursor-row:num <- get *recipe-editor, cursor-row:offset - recipe-editor-bottom:num <- get *recipe-editor, bottom:offset - at-bottom-of-editor?:bool <- greater-or-equal recipe-cursor-row, recipe-editor-bottom + recipe-editor:&:editor <- get *env, recipes:offset + recipe-cursor-row:num <- get *recipe-editor, cursor-row:offset + recipe-editor-bottom:num <- get *recipe-editor, bottom:offset + at-bottom-of-editor?:bool <- greater-or-equal recipe-cursor-row, recipe-editor-bottom break-unless at-bottom-of-editor? - more-to-scroll?:bool <- more-to-scroll? env, screen + more-to-scroll?:bool <- more-to-scroll? env, screen break-if more-to-scroll? loop +next-event } { break-if sandbox-in-focus? - page-down?:bool <- equal k, 65518/page-down + page-down?:bool <- equal k, 65518/page-down break-unless page-down? - more-to-scroll?:bool <- more-to-scroll? env, screen + more-to-scroll?:bool <- more-to-scroll? env, screen break-if more-to-scroll? loop +next-event } @@ -756,9 +756,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-type> [ { break-if sandbox-in-focus? - page-down?:bool <- equal k, 6/ctrl-f + page-down?:bool <- equal k, 6/ctrl-f break-unless page-down? - more-to-scroll?:bool <- more-to-scroll? env, screen + more-to-scroll?:bool <- more-to-scroll? env, screen break-if more-to-scroll? loop +next-event } @@ -767,16 +767,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def more-to-scroll? env:&:environment, screen:&:screen -> result:bool [ local-scope load-ingredients - recipe-bottom:num <- get *env, recipe-bottom:offset - height:num <- screen-height screen - result <- greater-or-equal recipe-bottom, height + recipe-bottom:num <- get *env, recipe-bottom:offset + height:num <- screen-height screen + result <- greater-or-equal recipe-bottom, height ] scenario scrolling-down-past-bottom-of-recipe-editor-2 [ local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render assume-console [ # add a line @@ -801,7 +801,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [ab + env:&:environment <- new-programming-environment screen, [], [ab cd] render-all screen, env, render assume-console [ @@ -813,7 +813,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press down-arrow ] event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor # no scroll on recipe side, cursor moves on sandbox side screen-should-contain [ @@ -832,7 +832,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize sandbox side - env:&:environment <- new-programming-environment screen, [], [add 2, 2] + env:&:environment <- new-programming-environment screen, [], [add 2, 2] render-all screen, env, render assume-console [ # create a sandbox @@ -853,7 +853,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # sandbox editor hidden; first sandbox displayed @@ -871,7 +871,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # sandbox editor displays again, cursor is in editor @@ -888,22 +888,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-keypress> [ { break-unless sandbox-in-focus? - page-down?:bool <- equal k, 65518/page-down + page-down?:bool <- equal k, 65518/page-down break-unless page-down? - sandbox:&:sandbox <- get *env, sandbox:offset + sandbox:&:sandbox <- get *env, sandbox:offset break-unless sandbox # slide down if possible { - render-from:num <- get *env, render-from:offset - number-of-sandboxes:num <- get *env, number-of-sandboxes:offset - max:num <- subtract number-of-sandboxes, 1 - at-end?:bool <- greater-or-equal render-from, max + render-from:num <- get *env, render-from:offset + number-of-sandboxes:num <- get *env, number-of-sandboxes:offset + max:num <- subtract number-of-sandboxes, 1 + at-end?:bool <- greater-or-equal render-from, max jump-if at-end?, +finish-event # render nothing - render-from <- add render-from, 1 - *env <- put *env, render-from:offset, render-from + render-from <- add render-from, 1 + *env <- put *env, render-from:offset, render-from } hide-screen screen - screen <- render-sandbox-side screen, env, render + screen <- render-sandbox-side screen, env, render show-screen screen jump +finish-event } @@ -913,11 +913,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <update-cursor-special-cases> [ { break-unless sandbox-in-focus? - render-from:num <- get *env, render-from:offset - scrolling?:bool <- greater-or-equal render-from, 0 + render-from:num <- get *env, render-from:offset + scrolling?:bool <- greater-or-equal render-from, 0 break-unless scrolling? - cursor-column:num <- get *current-sandbox, left:offset - screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 + cursor-column:num <- get *current-sandbox, left:offset + screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 return } ] @@ -926,15 +926,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-keypress> [ { break-unless sandbox-in-focus? - page-up?:bool <- equal k, 65519/page-up + page-up?:bool <- equal k, 65519/page-up break-unless page-up? - render-from:num <- get *env, render-from:offset - at-beginning?:bool <- equal render-from, -1 + render-from:num <- get *env, render-from:offset + at-beginning?:bool <- equal render-from, -1 break-if at-beginning? - render-from <- subtract render-from, 1 - *env <- put *env, render-from:offset, render-from + render-from <- subtract render-from, 1 + *env <- put *env, render-from:offset, render-from hide-screen screen - screen <- render-sandbox-side screen, env, render + screen <- render-sandbox-side screen, env, render show-screen screen jump +finish-event } @@ -945,15 +945,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ local-scope load-ingredients - curr:&:sandbox <- get *env, sandbox:offset + curr:&:sandbox <- get *env, sandbox:offset return-unless curr, 0/nil - next:&:sandbox <- get *curr, next-sandbox:offset + next:&:sandbox <- get *curr, next-sandbox:offset { return-unless next, 0/nil - found?:bool <- equal next, in + found?:bool <- equal next, in break-if found? - curr <- copy next - next <- get *curr, next-sandbox:offset + curr <- copy next + next <- get *curr, next-sandbox:offset loop } return curr @@ -964,10 +964,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize sandbox side and create a sandbox - recipes:text <- new [ + recipes:text <- new [ ] # create a sandbox - env:&:environment <- new-programming-environment screen, recipes:text, [add 2, 2] + env:&:environment <- new-programming-environment screen, recipes:text, [add 2, 2] render-all screen, env, render assume-console [ press F4 @@ -979,7 +979,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # cursor moves down on recipe side @@ -997,7 +997,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes assume-console [ @@ -1008,7 +1008,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color press F4 ] event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor screen-should-contain [ . run (F4) . @@ -1028,7 +1028,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # sandbox editor hidden; first sandbox displayed @@ -1103,7 +1103,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # back to displaying both sandboxes as well as editor @@ -1125,7 +1125,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # no change @@ -1148,7 +1148,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create a sandbox assume-console [ diff --git a/html/edit/006-sandbox-copy.mu.html b/html/edit/006-sandbox-copy.mu.html index 8f96e319..0ae24c18 100644 --- a/html/edit/006-sandbox-copy.mu.html +++ b/html/edit/006-sandbox-copy.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click at left edge of 'copy' button assume-console [ - left-click 3, 69 + left-click 3, 69 ] run [ event-loop screen, console, env @@ -102,11 +102,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -124,7 +124,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click at right edge of 'copy' button (just before 'delete') assume-console [ - left-click 3, 84 + left-click 3, 84 ] run [ event-loop screen, console, env @@ -162,13 +162,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-touch> [ # support 'copy' button { - copy?:bool <- should-attempt-copy? click-row, click-column, env + copy?:bool <- should-attempt-copy? click-row, click-column, env break-unless copy? - copy?, env <- try-copy-sandbox click-row, env + copy?, env <- try-copy-sandbox click-row, env break-unless copy? hide-screen screen - screen <- render-sandbox-side screen, env, render - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- render-sandbox-side screen, env, render + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen loop +next-event } @@ -179,47 +179,47 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # are we below the sandbox editor? - click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env reply-unless click-sandbox-area?, 0/false # narrower, is the click in the columns spanning the 'copy' button? - first-sandbox:&:editor <- get *env, current-sandbox:offset + first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] - sandbox-left-margin:num <- get *first-sandbox, left:offset - sandbox-right-margin:num <- get *first-sandbox, right:offset - _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right + sandbox-left-margin:num <- get *first-sandbox, left:offset + sandbox-right-margin:num <- get *first-sandbox, right:offset + _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right reply-unless copy-button-vertical-area?, 0/false # finally, is sandbox editor empty? - current-sandbox:&:editor <- get *env, current-sandbox:offset - result <- empty-editor? current-sandbox + current-sandbox:&:editor <- get *env, current-sandbox:offset + result <- empty-editor? current-sandbox ] def try-copy-sandbox click-row:num, env:&:environment -> clicked-on-copy-button?:bool, env:&:environment [ local-scope load-ingredients # identify the sandbox to copy, if the click was actually on the 'copy' button - sandbox:&:sandbox <- find-sandbox env, click-row + sandbox:&:sandbox <- find-sandbox env, click-row return-unless sandbox, 0/false - clicked-on-copy-button? <- copy 1/true - text:text <- get *sandbox, data:offset - current-sandbox:&:editor <- get *env, current-sandbox:offset - current-sandbox <- insert-text current-sandbox, text + clicked-on-copy-button? <- copy 1/true + text:text <- get *sandbox, data:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset + current-sandbox <- insert-text current-sandbox, text # reset scroll - *env <- put *env, render-from:offset, -1 + *env <- put *env, render-from:offset, -1 # position cursor in sandbox editor - *env <- put *env, sandbox-in-focus?:offset, 1/true + *env <- put *env, sandbox-in-focus?:offset, 1/true ] def find-sandbox env:&:environment, click-row:num -> result:&:sandbox [ local-scope load-ingredients - curr-sandbox:&:sandbox <- get *env, sandbox:offset + curr-sandbox:&:sandbox <- get *env, sandbox:offset { break-unless curr-sandbox - start:num <- get *curr-sandbox, starting-row-on-screen:offset - found?:bool <- equal click-row, start + start:num <- get *curr-sandbox, starting-row-on-screen:offset + found?:bool <- equal click-row, start return-if found?, curr-sandbox - curr-sandbox <- get *curr-sandbox, next-sandbox:offset + curr-sandbox <- get *curr-sandbox, next-sandbox:offset loop } return 0/not-found @@ -228,30 +228,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def click-on-sandbox-area? click-row:num, click-column:num, env:&:environment -> result:bool [ local-scope load-ingredients - current-sandbox:&:editor <- get *env, current-sandbox:offset - sandbox-left-margin:num <- get *current-sandbox, left:offset - on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin + current-sandbox:&:editor <- get *env, current-sandbox:offset + sandbox-left-margin:num <- get *current-sandbox, left:offset + on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin return-unless on-sandbox-side?, 0/false - first-sandbox:&:sandbox <- get *env, sandbox:offset + first-sandbox:&:sandbox <- get *env, sandbox:offset return-unless first-sandbox, 0/false - first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset - result <- greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset + result <- greater-or-equal click-row, first-sandbox-begins ] def empty-editor? editor:&:editor -> result:bool [ local-scope load-ingredients - head:&:duplex-list:char <- get *editor, data:offset - first:&:duplex-list:char <- next head - result <- not first + head:&:duplex-list:char <- get *editor, data:offset + first:&:duplex-list:char <- next head + result <- not first ] def within-range? x:num, low:num, high:num -> result:bool [ local-scope load-ingredients - not-too-far-left?:bool <- greater-or-equal x, low - not-too-far-right?:bool <- lesser-or-equal x, high - result <- and not-too-far-left? not-too-far-right? + not-too-far-left?:bool <- greater-or-equal x, low + not-too-far-right?:bool <- lesser-or-equal x, high + result <- and not-too-far-left? not-too-far-right? ] scenario copy-fails-if-sandbox-editor-not-empty [ @@ -259,11 +259,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -281,9 +281,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # type something into the sandbox editor, then click on the 'copy' button assume-console [ - left-click 2, 70 # put cursor in sandbox editor + left-click 2, 70 # put cursor in sandbox editor type [0] # type something - left-click 3, 70 # click 'copy' button + left-click 3, 70 # click 'copy' button ] run [ event-loop screen, console, env diff --git a/html/edit/007-sandbox-delete.mu.html b/html/edit/007-sandbox-delete.mu.html index ffae21e3..5fbf7441 100644 --- a/html/edit/007-sandbox-delete.mu.html +++ b/html/edit/007-sandbox-delete.mu.html @@ -38,10 +38,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] # run a few commands assume-console [ - left-click 1, 80 + left-click 1, 80 type [divide-with-remainder 11, 3] press F4 type [add 2, 2] @@ -65,7 +65,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete second sandbox by clicking on left edge of 'delete' button assume-console [ - left-click 7, 85 + left-click 7, 85 ] run [ event-loop screen, console, env @@ -83,7 +83,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete first sandbox by clicking at right edge of 'delete' button assume-console [ - left-click 3, 99 + left-click 3, 99 ] run [ event-loop screen, console, env @@ -100,13 +100,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-touch> [ # support 'delete' button { - delete?:bool <- should-attempt-delete? click-row, click-column, env + delete?:bool <- should-attempt-delete? click-row, click-column, env break-unless delete? - delete?, env <- try-delete-sandbox click-row, env + delete?, env <- try-delete-sandbox click-row, env break-unless delete? hide-screen screen - screen <- render-sandbox-side screen, env, render - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- render-sandbox-side screen, env, render + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen loop +next-event } @@ -117,66 +117,66 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # are we below the sandbox editor? - click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env reply-unless click-sandbox-area?, 0/false # narrower, is the click in the columns spanning the 'copy' button? - first-sandbox:&:editor <- get *env, current-sandbox:offset + first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] - sandbox-left-margin:num <- get *first-sandbox, left:offset - sandbox-right-margin:num <- get *first-sandbox, right:offset - _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - result <- within-range? click-column, delete-button-left, sandbox-right-margin + sandbox-left-margin:num <- get *first-sandbox, left:offset + sandbox-right-margin:num <- get *first-sandbox, right:offset + _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + result <- within-range? click-column, delete-button-left, sandbox-right-margin ] def try-delete-sandbox click-row:num, env:&:environment -> clicked-on-delete-button?:bool, env:&:environment [ local-scope load-ingredients # identify the sandbox to delete, if the click was actually on the 'delete' button - sandbox:&:sandbox <- find-sandbox env, click-row + sandbox:&:sandbox <- find-sandbox env, click-row return-unless sandbox, 0/false - clicked-on-delete-button? <- copy 1/true - env <- delete-sandbox env, sandbox + clicked-on-delete-button? <- copy 1/true + env <- delete-sandbox env, sandbox ] def delete-sandbox env:&:environment, sandbox:&:sandbox -> env:&:environment [ local-scope load-ingredients - curr-sandbox:&:sandbox <- get *env, sandbox:offset - first-sandbox?:bool <- equal curr-sandbox, sandbox + curr-sandbox:&:sandbox <- get *env, sandbox:offset + first-sandbox?:bool <- equal curr-sandbox, sandbox { # first sandbox? pop break-unless first-sandbox? - next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset - *env <- put *env, sandbox:offset, next-sandbox + next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset + *env <- put *env, sandbox:offset, next-sandbox } { # not first sandbox? break-if first-sandbox? - prev-sandbox:&:sandbox <- copy curr-sandbox - curr-sandbox <- get *curr-sandbox, next-sandbox:offset + prev-sandbox:&:sandbox <- copy curr-sandbox + curr-sandbox <- get *curr-sandbox, next-sandbox:offset { assert curr-sandbox, [sandbox not found! something is wrong.] - found?:bool <- equal curr-sandbox, sandbox + found?:bool <- equal curr-sandbox, sandbox break-if found? - prev-sandbox <- copy curr-sandbox - curr-sandbox <- get *curr-sandbox, next-sandbox:offset + prev-sandbox <- copy curr-sandbox + curr-sandbox <- get *curr-sandbox, next-sandbox:offset loop } # snip sandbox out of its list - next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset - *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox + next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset + *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox } # update sandbox count - sandbox-count:num <- get *env, number-of-sandboxes:offset - sandbox-count <- subtract sandbox-count, 1 - *env <- put *env, number-of-sandboxes:offset, sandbox-count + sandbox-count:num <- get *env, number-of-sandboxes:offset + sandbox-count <- subtract sandbox-count, 1 + *env <- put *env, number-of-sandboxes:offset, sandbox-count # reset scroll if deleted sandbox was last { break-if next-sandbox - render-from:num <- get *env, render-from:offset - reset-scroll?:bool <- equal render-from, sandbox-count + render-from:num <- get *env, render-from:offset + reset-scroll?:bool <- equal render-from, sandbox-count break-unless reset-scroll? - *env <- put *env, render-from:offset, -1 + *env <- put *env, render-from:offset, -1 } ] @@ -185,7 +185,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes and scroll to second assume-console [ @@ -208,7 +208,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete the second sandbox assume-console [ - left-click 6, 99 + left-click 6, 99 ] run [ event-loop screen, console, env @@ -230,7 +230,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes and scroll to second assume-console [ @@ -253,7 +253,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete the second sandbox assume-console [ - left-click 2, 99 + left-click 2, 99 ] run [ event-loop screen, console, env @@ -275,7 +275,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes and scroll to second assume-console [ @@ -299,7 +299,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete the second sandbox assume-console [ - left-click 2, 99 + left-click 2, 99 ] run [ event-loop screen, console, env @@ -322,7 +322,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes assume-console [ @@ -347,7 +347,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # delete the second sandbox, then try to scroll down twice assume-console [ - left-click 3, 99 + left-click 3, 99 press page-down press page-down ] diff --git a/html/edit/008-sandbox-edit.mu.html b/html/edit/008-sandbox-edit.mu.html index 6b8599b5..43481161 100644 --- a/html/edit/008-sandbox-edit.mu.html +++ b/html/edit/008-sandbox-edit.mu.html @@ -39,11 +39,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -61,7 +61,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click at left edge of 'edit' button assume-console [ - left-click 3, 55 + left-click 3, 55 ] run [ event-loop screen, console, env @@ -99,11 +99,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -121,7 +121,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click at right edge of 'edit' button (just before 'copy') assume-console [ - left-click 3, 68 + left-click 3, 68 ] run [ event-loop screen, console, env @@ -157,13 +157,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-touch> [ # support 'edit' button { - edit?:bool <- should-attempt-edit? click-row, click-column, env + edit?:bool <- should-attempt-edit? click-row, click-column, env break-unless edit? - edit?, env <- try-edit-sandbox click-row, env + edit?, env <- try-edit-sandbox click-row, env break-unless edit? hide-screen screen - screen <- render-sandbox-side screen, env, render - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- render-sandbox-side screen, env, render + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env show-screen screen loop +next-event } @@ -174,37 +174,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # are we below the sandbox editor? - click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env + click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env reply-unless click-sandbox-area?, 0/false # narrower, is the click in the columns spanning the 'edit' button? - first-sandbox:&:editor <- get *env, current-sandbox:offset + first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] - sandbox-left-margin:num <- get *first-sandbox, left:offset - sandbox-right-margin:num <- get *first-sandbox, right:offset - edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin - edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right + sandbox-left-margin:num <- get *first-sandbox, left:offset + sandbox-right-margin:num <- get *first-sandbox, right:offset + edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin + edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right reply-unless edit-button-vertical-area?, 0/false # finally, is sandbox editor empty? - current-sandbox:&:editor <- get *env, current-sandbox:offset - result <- empty-editor? current-sandbox + current-sandbox:&:editor <- get *env, current-sandbox:offset + result <- empty-editor? current-sandbox ] def try-edit-sandbox click-row:num, env:&:environment -> clicked-on-edit-button?:bool, env:&:environment [ local-scope load-ingredients # identify the sandbox to edit, if the click was actually on the 'edit' button - sandbox:&:sandbox <- find-sandbox env, click-row + sandbox:&:sandbox <- find-sandbox env, click-row return-unless sandbox, 0/false - clicked-on-edit-button? <- copy 1/true + clicked-on-edit-button? <- copy 1/true # 'edit' button = 'copy' button + 'delete' button - text:text <- get *sandbox, data:offset - current-sandbox:&:editor <- get *env, current-sandbox:offset - current-sandbox <- insert-text current-sandbox, text - env <- delete-sandbox env, sandbox + text:text <- get *sandbox, data:offset + current-sandbox:&:editor <- get *env, current-sandbox:offset + current-sandbox <- insert-text current-sandbox, text + env <- delete-sandbox env, sandbox # reset scroll - *env <- put *env, render-from:offset, -1 + *env <- put *env, render-from:offset, -1 # position cursor in sandbox editor - *env <- put *env, sandbox-in-focus?:offset, 1/true + *env <- put *env, sandbox-in-focus?:offset, 1/true ] scenario sandbox-with-print-can-be-edited [ @@ -213,7 +213,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color assume-screen 100/width, 20/height # left editor is empty # right editor contains an instruction - env:&:environment <- new-programming-environment screen, [], [print-integer screen, 4] + env:&:environment <- new-programming-environment screen, [], [print-integer screen, 4] # run the sandbox assume-console [ press F4 @@ -236,7 +236,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # edit the sandbox assume-console [ - left-click 3, 65 + left-click 3, 65 ] run [ event-loop screen, console, env @@ -255,7 +255,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes and scroll to second assume-console [ @@ -279,7 +279,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # edit the second sandbox assume-console [ - left-click 2, 55 + left-click 2, 55 ] run [ event-loop screen, console, env @@ -302,7 +302,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] render-all screen, env, render # create 2 sandboxes assume-console [ @@ -327,7 +327,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # edit the second sandbox, then resave assume-console [ - left-click 3, 60 + left-click 3, 60 press F4 ] run [ diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index 1c350a57..30c731ea 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes:text, [foo] + env:&:environment <- new-programming-environment screen, recipes:text, [foo] # run it assume-console [ press F4 @@ -62,7 +62,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click on the '4' in the result assume-console [ - left-click 5, 51 + left-click 5, 51 ] run [ event-loop screen, console, env @@ -80,7 +80,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # cursor should remain unmoved run [ - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] screen-should-contain [ @@ -98,7 +98,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # now change the result # then rerun assume-console [ - left-click 3, 11 # cursor to end of line + left-click 3, 11 # cursor to end of line press backspace type [3] press F4 @@ -128,19 +128,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # include expected response when saving or restoring a sandbox before <end-save-sandbox> [ { - expected-response:text <- get *curr, expected-response:offset + expected-response:text <- get *curr, expected-response:offset break-unless expected-response - filename <- append filename, [.out] + filename <- append filename, [.out] save filename, expected-response } ] before <end-restore-sandbox> [ { - filename <- append filename, [.out] - contents <- restore filename + filename <- append filename, [.out] + contents <- restore filename break-unless contents - *curr <- put *curr, expected-response:offset, contents + *curr <- put *curr, expected-response:offset, contents } ] @@ -148,25 +148,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <global-touch> [ # check if it's inside the output of any sandbox { - sandbox-left-margin:num <- get *current-sandbox, left:offset - click-column:num <- get t, column:offset - on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin + sandbox-left-margin:num <- get *current-sandbox, left:offset + click-column:num <- get t, column:offset + on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:&:sandbox <- get *env, sandbox:offset + first-sandbox:&:sandbox <- get *env, sandbox:offset break-unless first-sandbox - first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset - click-row:num <- get t, row:offset - below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset + click-row:num <- get t, row:offset + below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose output is being clicked on - sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row + sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row break-unless sandbox # toggle its expected-response, and save session - sandbox <- toggle-expected-response sandbox + sandbox <- toggle-expected-response sandbox save-sandboxes env hide-screen screen - screen <- render-sandbox-side screen, env, render - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- render-sandbox-side screen, env, render + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env # no change in cursor show-screen screen loop +next-event @@ -177,24 +177,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen - sandbox:&:sandbox <- get *env, sandbox:offset - start:num <- get *sandbox, starting-row-on-screen:offset - clicked-on-sandboxes?:bool <- greater-or-equal click-row, start + sandbox:&:sandbox <- get *env, sandbox:offset + start:num <- get *sandbox, starting-row-on-screen:offset + clicked-on-sandboxes?:bool <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset + next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset break-unless next-sandbox - next-start:num <- get *next-sandbox, starting-row-on-screen:offset - found?:bool <- lesser-than click-row, next-start + next-start:num <- get *next-sandbox, starting-row-on-screen:offset + found?:bool <- lesser-than click-row, next-start break-if found? - sandbox <- copy next-sandbox + sandbox <- copy next-sandbox loop } # return sandbox if click is in its output region - response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset + response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset return-unless response-starting-row, 0/no-click-in-sandbox-output - click-in-response?:bool <- greater-or-equal click-row, response-starting-row + click-in-response?:bool <- greater-or-equal click-row, response-starting-row return-unless click-in-response?, 0/no-click-in-sandbox-output return sandbox ] @@ -202,17 +202,17 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ local-scope load-ingredients - expected-response:text <- get *sandbox, expected-response:offset + expected-response:text <- get *sandbox, expected-response:offset { # if expected-response is set, reset break-unless expected-response - *sandbox <- put *sandbox, expected-response:offset, 0 + *sandbox <- put *sandbox, expected-response:offset, 0 } { # if not, set expected response to the current response break-if expected-response - response:text <- get *sandbox, response:offset - *sandbox <- put *sandbox, expected-response:offset, response + response:text <- get *sandbox, response:offset + *sandbox <- put *sandbox, expected-response:offset, response } ] @@ -220,24 +220,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <render-sandbox-response> [ { break-unless sandbox-response - *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row - expected-response:text <- get *sandbox, expected-response:offset + *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row + expected-response:text <- get *sandbox, expected-response:offset break-unless expected-response # fall-through to print in grey - response-is-expected?:bool <- equal expected-response, sandbox-response + response-is-expected?:bool <- equal expected-response, sandbox-response { break-if response-is-expected?:bool - row, screen <- render-text screen, sandbox-response, left, right, 1/red, row + row, screen <- render-text screen, sandbox-response, left, right, 1/red, row } { break-unless response-is-expected?:bool - row, screen <- render-text screen, sandbox-response, left, right, 2/green, row + row, screen <- render-text screen, sandbox-response, left, right, 2/green, row } jump +render-sandbox-end } ] before <end-render-sandbox-reset-hidden> [ - *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 + *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 ] diff --git a/html/edit/010-sandbox-trace.mu.html b/html/edit/010-sandbox-trace.mu.html index ece61dee..66943462 100644 --- a/html/edit/010-sandbox-trace.mu.html +++ b/html/edit/010-sandbox-trace.mu.html @@ -40,11 +40,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ stash [abc] ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -61,11 +61,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click on the code in the sandbox assume-console [ - left-click 4, 51 + left-click 4, 51 ] run [ event-loop screen, console, env - cursor:char <- copy 9251/␣ + cursor:char <- copy 9251/␣ print screen, cursor ] # trace now printed and cursor shouldn't have budged @@ -87,7 +87,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click again on the same region assume-console [ - left-click 4, 55 + left-click 4, 55 ] run [ event-loop screen, console, env @@ -110,12 +110,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # basic recipe - recipes:text <- new [ + recipes:text <- new [ recipe foo [ stash [abc] - reply 4 + reply 4 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run it assume-console [ press F4 @@ -133,7 +133,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click on the code in the sandbox assume-console [ - left-click 4, 51 + left-click 4, 51 ] run [ event-loop screen, console, env @@ -157,11 +157,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [stash 123456789] + env:&:environment <- new-programming-environment screen, [], [stash 123456789] # create and expand the trace assume-console [ press F4 - left-click 4, 51 + left-click 4, 51 ] event-loop screen, console, env screen-should-contain [ @@ -174,7 +174,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # click on the stash under the edit-button region (or any of the other buttons, really) assume-console [ - left-click 5, 57 + left-click 5, 57 ] run [ event-loop screen, console, env @@ -199,37 +199,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def! update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [ local-scope load-ingredients - data:text <- get *sandbox, data:offset - response:text, _, fake-screen:&:screen, trace:text <- run-sandboxed data - *sandbox <- put *sandbox, response:offset, response - *sandbox <- put *sandbox, screen:offset, fake-screen - *sandbox <- put *sandbox, trace:offset, trace + data:text <- get *sandbox, data:offset + response:text, _, fake-screen:&:screen, trace:text <- run-sandboxed data + *sandbox <- put *sandbox, response:offset, response + *sandbox <- put *sandbox, screen:offset, fake-screen + *sandbox <- put *sandbox, trace:offset, trace ] # clicks on sandbox code toggle its display-trace? flag after <global-touch> [ # check if it's inside the code of any sandbox { - sandbox-left-margin:num <- get *current-sandbox, left:offset - click-column:num <- get t, column:offset - on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin + sandbox-left-margin:num <- get *current-sandbox, left:offset + click-column:num <- get t, column:offset + on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? - first-sandbox:&:sandbox <- get *env, sandbox:offset + first-sandbox:&:sandbox <- get *env, sandbox:offset break-unless first-sandbox - first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset - click-row:num <- get t, row:offset - below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins + first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset + click-row:num <- get t, row:offset + below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose code is being clicked on - sandbox:&:sandbox <- find-click-in-sandbox-code env, click-row + sandbox:&:sandbox <- find-click-in-sandbox-code env, click-row break-unless sandbox # toggle its display-trace? property - x:bool <- get *sandbox, display-trace?:offset - x <- not x - *sandbox <- put *sandbox, display-trace?:offset, x + x:bool <- get *sandbox, display-trace?:offset + x <- not x + *sandbox <- put *sandbox, display-trace?:offset, x hide-screen screen - screen <- render-sandbox-side screen, env, render - screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env + screen <- render-sandbox-side screen, env, render + screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env # no change in cursor show-screen screen loop +next-event @@ -240,26 +240,26 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen - sandbox <- get *env, sandbox:offset - start:num <- get *sandbox, starting-row-on-screen:offset - clicked-on-sandboxes?:bool <- greater-or-equal click-row, start + sandbox <- get *env, sandbox:offset + start:num <- get *sandbox, starting-row-on-screen:offset + clicked-on-sandboxes?:bool <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { - next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset + next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset break-unless next-sandbox - next-start:num <- get *next-sandbox, starting-row-on-screen:offset - found?:bool <- lesser-than click-row, next-start + next-start:num <- get *next-sandbox, starting-row-on-screen:offset + found?:bool <- lesser-than click-row, next-start break-if found? - sandbox <- copy next-sandbox + sandbox <- copy next-sandbox loop } # return sandbox if click is in its code region - code-ending-row:num <- get *sandbox, code-ending-row-on-screen:offset - click-above-response?:bool <- lesser-than click-row, code-ending-row - start:num <- get *sandbox, starting-row-on-screen:offset - click-below-menu?:bool <- greater-than click-row, start - click-on-sandbox-code?:bool <- and click-above-response?, click-below-menu? + code-ending-row:num <- get *sandbox, code-ending-row-on-screen:offset + click-above-response?:bool <- lesser-than click-row, code-ending-row + start:num <- get *sandbox, starting-row-on-screen:offset + click-below-menu?:bool <- greater-than click-row, start + click-on-sandbox-code?:bool <- and click-above-response?, click-below-menu? { break-if click-on-sandbox-code? return 0/no-click-in-sandbox-output @@ -270,11 +270,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # when rendering a sandbox, dump its trace before response/warning if display-trace? property is set after <render-sandbox-results> [ { - display-trace?:bool <- get *sandbox, display-trace?:offset + display-trace?:bool <- get *sandbox, display-trace?:offset break-unless display-trace? - sandbox-trace:text <- get *sandbox, trace:offset + sandbox-trace:text <- get *sandbox, trace:offset break-unless sandbox-trace # nothing to print; move on - row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row + row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row } <render-sandbox-trace-done> ] diff --git a/html/edit/011-errors.mu.html b/html/edit/011-errors.mu.html index 146b2b15..2bdf811a 100644 --- a/html/edit/011-errors.mu.html +++ b/html/edit/011-errors.mu.html @@ -43,24 +43,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def! update-recipes env:&:environment, screen:&:screen -> errors-found?:bool, env:&:environment, screen:&:screen [ local-scope load-ingredients - recipes:&:editor <- get *env, recipes:offset - in:text <- editor-contents recipes + recipes:&:editor <- get *env, recipes:offset + in:text <- editor-contents recipes save [recipes.mu], in - recipe-errors:text <- reload in - *env <- put *env, recipe-errors:offset, recipe-errors + recipe-errors:text <- reload in + *env <- put *env, recipe-errors:offset, recipe-errors # if recipe editor has errors, stop { break-unless recipe-errors update-status screen, [errors found ], 1/red - errors-found? <- copy 1/true + errors-found? <- copy 1/true return } - errors-found? <- copy 0/false + errors-found? <- copy 0/false ] before <render-components-end> [ - trace 11, [app], [render status] - recipe-errors:text <- get *env, recipe-errors:offset + trace 11, [app], [render status] + recipe-errors:text <- get *env, recipe-errors:offset { break-unless recipe-errors update-status screen, [errors found ], 1/red @@ -69,9 +69,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color before <render-recipe-components-end> [ { - recipe-errors:text <- get *env, recipe-errors:offset + recipe-errors:text <- get *env, recipe-errors:offset break-unless recipe-errors - row, screen <- render-text screen, recipe-errors, left, right, 1/red, row + row, screen <- render-text screen, recipe-errors, left, right, 1/red, row } ] @@ -80,30 +80,30 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <programming-environment-initialization> [ - *result <- put *result, error-index:offset, -1 + *result <- put *result, error-index:offset, -1 ] after <run-sandboxes-begin> [ - *env <- put *env, error-index:offset, -1 + *env <- put *env, error-index:offset, -1 ] before <run-sandboxes-end> [ { - error-index:num <- get *env, error-index:offset - sandboxes-completed-successfully?:bool <- equal error-index, -1 + error-index:num <- get *env, error-index:offset + sandboxes-completed-successfully?:bool <- equal error-index, -1 break-if sandboxes-completed-successfully? - errors-found? <- copy 1/true + errors-found? <- copy 1/true } ] before <render-components-end> [ { break-if recipe-errors - error-index:num <- get *env, error-index:offset - sandboxes-completed-successfully?:bool <- equal error-index, -1 + error-index:num <- get *env, error-index:offset + sandboxes-completed-successfully?:bool <- equal error-index, -1 break-if sandboxes-completed-successfully? - error-index-text:text <- to-text error-index - status:text <- interpolate [errors found (_) ], error-index-text + error-index-text:text <- to-text error-index + status:text <- interpolate [errors found (_) ], error-index-text update-status screen, status, 1/red } ] @@ -115,35 +115,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def! update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [ local-scope load-ingredients - data:text <- get *sandbox, data:offset - response:text, errors:text, fake-screen:&:screen, trace:text, completed?:bool <- run-sandboxed data - *sandbox <- put *sandbox, response:offset, response - *sandbox <- put *sandbox, errors:offset, errors - *sandbox <- put *sandbox, screen:offset, fake-screen - *sandbox <- put *sandbox, trace:offset, trace + data:text <- get *sandbox, data:offset + response:text, errors:text, fake-screen:&:screen, trace:text, completed?:bool <- run-sandboxed data + *sandbox <- put *sandbox, response:offset, response + *sandbox <- put *sandbox, errors:offset, errors + *sandbox <- put *sandbox, screen:offset, fake-screen + *sandbox <- put *sandbox, trace:offset, trace { break-if errors break-if completed?:bool - errors <- new [took too long! + errors <- new [took too long! ] - *sandbox <- put *sandbox, errors:offset, errors + *sandbox <- put *sandbox, errors:offset, errors } { break-unless errors - error-index:num <- get *env, error-index:offset - error-not-set?:bool <- equal error-index, -1 + error-index:num <- get *env, error-index:offset + error-not-set?:bool <- equal error-index, -1 break-unless error-not-set? - *env <- put *env, error-index:offset, idx + *env <- put *env, error-index:offset, idx } ] # make sure we render any trace after <render-sandbox-trace-done> [ { - sandbox-errors:text <- get *sandbox, errors:offset + sandbox-errors:text <- get *sandbox, errors:offset break-unless sandbox-errors - *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 # no response - row, screen <- render-text screen, sandbox-errors, left, right, 1/red, row + *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 # no response + row, screen <- render-text screen, sandbox-errors, left, right, 1/red, row # don't try to print anything more for this sandbox jump +render-sandbox-end } @@ -153,11 +153,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - recipes:text <- new [ + recipes:text <- new [ recipe foo [ get 123:num, foo:offset ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -193,9 +193,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] assume-console [ - left-click 3, 80 + left-click 3, 80 # create invalid sandbox 1 type [get foo, x:offset] press F4 @@ -216,9 +216,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - env:&:environment <- new-programming-environment screen, [], [] + env:&:environment <- new-programming-environment screen, [], [] assume-console [ - left-click 3, 80 + left-click 3, 80 # create invalid sandbox 2 type [get foo, x:offset] press F4 @@ -242,7 +242,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - env:&:environment <- new-programming-environment screen, [], [get foo, x:offset] # invalid + env:&:environment <- new-programming-environment screen, [], [get foo, x:offset] # invalid assume-console [ press F4 # generate error ] @@ -250,7 +250,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color event-loop screen, console, env ] assume-console [ - left-click 3, 58 + left-click 3, 58 press ctrl-k type [add 2, 2] # valid code press F4 # update sandbox @@ -276,13 +276,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 15/height # define a shape-shifting recipe with an error - recipes:text <- new [recipe foo x:_elem -> z:_elem [ + recipes:text <- new [recipe foo x:_elem -> z:_elem [ local-scope load-ingredients y:&:num <- copy 0 z <- add x, y ]] - env:&:environment <- new-programming-environment screen, recipes, [foo 2] + env:&:environment <- new-programming-environment screen, recipes, [foo 2] assume-console [ press F4 ] @@ -324,12 +324,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 15/height # overload a well-known shape-shifting recipe - recipes:text <- new [recipe length l:&:list:_elem -> n:num [ + recipes:text <- new [recipe length l:&:list:_elem -> n:num [ ]] # call code that uses other variants of it, but not it itself - sandbox:text <- new [x:&:list:num <- copy 0 + sandbox:text <- new [x:&:list:num <- copy 0 to-text x] - env:&:environment <- new-programming-environment screen, recipes, sandbox + env:&:environment <- new-programming-environment screen, recipes, sandbox # run it once assume-console [ press F4 @@ -384,11 +384,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - recipes:text <- new [ + recipes:text <- new [ recipe foo [ x <- copy 0 ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -410,11 +410,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 15/height # recipe is incomplete (unbalanced '[') - recipes:text <- new [ + recipes:text <- new [ recipe foo \\[ x <- copy 0 ] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -437,13 +437,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - recipes:text <- new [ + recipes:text <- new [ recipe foo [ local-scope x:&:point <- new point:type get x:&:point, 1:offset ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -469,14 +469,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope trace-until 100/app # trace too long assume-screen 100/width, 15/height - recipes:text <- new [ + recipes:text <- new [ recipe foo [ local-scope x:num <- copy 0 y:&:point <- new point:type get *y:&:point, x:num ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -504,12 +504,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long # try to run a file with an error assume-screen 100/width, 15/height - recipes:text <- new [ + recipes:text <- new [ recipe foo [ local-scope x:num <- copy y:num ]] - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] assume-console [ press F4 ] @@ -550,8 +550,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # right editor contains an illegal instruction - sandbox:text <- new [get 1234:num, foo:offset] - env:&:environment <- new-programming-environment screen, [], sandbox + sandbox:text <- new [get 1234:num, foo:offset] + env:&:environment <- new-programming-environment screen, [], sandbox # run the code in the editors assume-console [ press F4 @@ -612,8 +612,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # right editor contains an illegal instruction - sandbox:text <- new [get 1234:num, foo:offset] - env:&:environment <- new-programming-environment screen, [], sandbox + sandbox:text <- new [get 1234:num, foo:offset] + env:&:environment <- new-programming-environment screen, [], sandbox # run the code in the editors multiple times assume-console [ press F4 @@ -642,13 +642,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 20/height # left editor is empty - recipes:text <- new [recipe foo [ + recipes:text <- new [recipe foo [ { loop } ]] # right editor contains an instruction - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment screen, recipes, [foo] # run the sandbox assume-console [ press F4 @@ -673,15 +673,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color trace-until 100/app # trace too long assume-screen 100/width, 10/height # generate a stash and a error - recipes:text <- new [recipe foo [ + recipes:text <- new [recipe foo [ local-scope a:num <- next-ingredient b:num <- next-ingredient stash [dividing by], b -_, c:num <- divide-with-remainder a, b +_, c:num <- divide-with-remainder a, b reply b ]] - env:&:environment <- new-programming-environment screen, recipes, [foo 4, 0] + env:&:environment <- new-programming-environment screen, recipes, [foo 4, 0] # run assume-console [ press F4 @@ -701,7 +701,7 @@ _, c:num <- divide-with-remainder a, b ] # click on the call in the sandbox assume-console [ - left-click 4, 55 + left-click 4, 55 ] run [ event-loop screen, console, env diff --git a/html/edit/012-editor-undo.mu.html b/html/edit/012-editor-undo.mu.html index 0953fed1..56b85dbf 100644 --- a/html/edit/012-editor-undo.mu.html +++ b/html/edit/012-editor-undo.mu.html @@ -98,36 +98,36 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # ctrl-z - undo operation after <handle-special-character> [ { - undo?:bool <- equal c, 26/ctrl-z + undo?:bool <- equal c, 26/ctrl-z break-unless undo? - undo:&:list:&:operation <- get *editor, undo:offset + undo:&:list:&:operation <- get *editor, undo:offset break-unless undo - op:&:operation <- first undo - undo <- rest undo - *editor <- put *editor, undo:offset, undo - redo:&:list:&:operation <- get *editor, redo:offset - redo <- push op, redo - *editor <- put *editor, redo:offset, redo + op:&:operation <- first undo + undo <- rest undo + *editor <- put *editor, undo:offset, undo + redo:&:list:&:operation <- get *editor, redo:offset + redo <- push op, redo + *editor <- put *editor, redo:offset, redo <handle-undo> - return screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render + return screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render } ] # ctrl-y - redo operation after <handle-special-character> [ { - redo?:bool <- equal c, 25/ctrl-y + redo?:bool <- equal c, 25/ctrl-y break-unless redo? - redo:&:list:&:operation <- get *editor, redo:offset + redo:&:list:&:operation <- get *editor, redo:offset break-unless redo - op:&:operation <- first redo - redo <- rest redo - *editor <- put *editor, redo:offset, redo - undo:&:list:&:operation <- get *editor, undo:offset - undo <- push op, undo - *editor <- put *editor, undo:offset, undo + op:&:operation <- first redo + redo <- rest redo + *editor <- put *editor, redo:offset, redo + undo:&:list:&:operation <- get *editor, undo:offset + undo <- push op, undo + *editor <- put *editor, undo:offset, undo <handle-redo> - return screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render + return screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render } ] @@ -137,7 +137,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor and type a character assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e assume-console [ type [0] @@ -174,58 +174,58 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # save operation to undo after <insert-character-begin> [ - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-before:&:duplex-list:char <- get *editor, before-cursor:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-before:&:duplex-list:char <- get *editor, before-cursor:offset ] before <insert-character-end> [ - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - undo:&:list:&:operation <- get *editor, undo:offset + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + undo:&:list:&:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:&:operation <- first undo - typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant + op:&:operation <- first undo + typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant break-unless is-insert? - previous-coalesce-tag:num <- get typing, tag:offset + previous-coalesce-tag:num <- get typing, tag:offset break-unless previous-coalesce-tag - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - insert-until:&:duplex-list:char <- next before-cursor - typing <- put typing, insert-until:offset, insert-until - typing <- put typing, after-row:offset, cursor-row - typing <- put typing, after-column:offset, cursor-column - typing <- put typing, after-top-of-screen:offset, top-after - *op <- merge 0/insert-operation, typing + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + insert-until:&:duplex-list:char <- next before-cursor + typing <- put typing, insert-until:offset, insert-until + typing <- put typing, after-row:offset, cursor-row + typing <- put typing, after-column:offset, cursor-column + typing <- put typing, after-top-of-screen:offset, top-after + *op <- merge 0/insert-operation, typing break +done-adding-insert-operation } # if not, create a new operation - insert-from:&:duplex-list:char <- next cursor-before - insert-to:&:duplex-list:char <- next insert-from - op:&:operation <- new operation:type - *op <- merge 0/insert-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 1/coalesce - editor <- add-operation editor, op + insert-from:&:duplex-list:char <- next cursor-before + insert-to:&:duplex-list:char <- next insert-from + op:&:operation <- new operation:type + *op <- merge 0/insert-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 1/coalesce + editor <- add-operation editor, op +done-adding-insert-operation ] # enter operations never coalesce with typing before or after after <insert-enter-begin> [ - cursor-row-before:num <- copy cursor-row - cursor-column-before:num <- copy cursor-column - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-before:&:duplex-list:char <- get *editor, before-cursor:offset + cursor-row-before:num <- copy cursor-row + cursor-column-before:num <- copy cursor-column + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-before:&:duplex-list:char <- get *editor, before-cursor:offset ] before <insert-enter-end> [ - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-row:offset + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-row:offset # never coalesce - insert-from:&:duplex-list:char <- next cursor-before - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - insert-to:&:duplex-list:char <- next before-cursor - op:&:operation <- new operation:type - *op <- merge 0/insert-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 0/never-coalesce - editor <- add-operation editor, op + insert-from:&:duplex-list:char <- next cursor-before + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + insert-to:&:duplex-list:char <- next before-cursor + op:&:operation <- new operation:type + *op <- merge 0/insert-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, insert-from, insert-to, 0/never-coalesce + editor <- add-operation editor, op ] # Everytime you add a new operation to the undo stack, be sure to clear the @@ -235,31 +235,31 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def add-operation editor:&:editor, op:&:operation -> editor:&:editor [ local-scope load-ingredients - undo:&:list:&:operation <- get *editor, undo:offset - undo <- push op undo - *editor <- put *editor, undo:offset, undo - redo:&:list:&:operation <- get *editor, redo:offset - redo <- copy 0 - *editor <- put *editor, redo:offset, redo - return editor/same-as-ingredient:0 + undo:&:list:&:operation <- get *editor, undo:offset + undo <- push op undo + *editor <- put *editor, undo:offset, undo + redo:&:list:&:operation <- get *editor, redo:offset + redo <- copy 0 + *editor <- put *editor, redo:offset, redo + return editor/same-as-ingredient:0 ] after <handle-undo> [ { - typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant + typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant break-unless is-insert? - start:&:duplex-list:char <- get typing, insert-from:offset - end:&:duplex-list:char <- get typing, insert-until:offset + start:&:duplex-list:char <- get typing, insert-from:offset + end:&:duplex-list:char <- get typing, insert-until:offset # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - before-cursor:&:duplex-list:char <- prev start - *editor <- put *editor, before-cursor:offset, before-cursor + before-cursor:&:duplex-list:char <- prev start + *editor <- put *editor, before-cursor:offset, before-cursor remove-between before-cursor, end - cursor-row <- get typing, before-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get typing, before-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get typing, before-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + cursor-row <- get typing, before-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get typing, before-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get typing, before-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] @@ -267,7 +267,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor and type multiple characters assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e assume-console [ type [012] @@ -293,7 +293,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - e:&:editor <- new-editor [a], screen, 0/left, 10/right + e:&:editor <- new-editor [a], screen, 0/left, 10/right editor-render screen, e # type some characters assume-console [ @@ -339,11 +339,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - e:&:editor <- new-editor [ abc], screen, 0/left, 10/right + e:&:editor <- new-editor [ abc], screen, 0/left, 10/right editor-render screen, e # new line assume-console [ - left-click 1, 8 + left-click 1, 8 press enter ] editor-event-loop screen, console, e @@ -355,11 +355,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] # line is indented - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 2 + 3 <- 2 + 4 <- 2 ] # undo assume-console [ @@ -368,11 +368,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 5 + 3 <- 1 + 4 <- 5 ] # back to original text screen-should-contain [ @@ -402,7 +402,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor, type something, undo assume-screen 10/width, 5/height - e:&:editor <- new-editor [a], screen, 0/left, 10/right + e:&:editor <- new-editor [a], screen, 0/left, 10/right editor-render screen, e assume-console [ type [012] @@ -446,19 +446,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-redo> [ { - typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant + typing:insert-operation, is-insert?:bool <- maybe-convert *op, typing:variant break-unless is-insert? - before-cursor <- get *editor, before-cursor:offset - insert-from:&:duplex-list:char <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away + before-cursor <- get *editor, before-cursor:offset + insert-from:&:duplex-list:char <- get typing, insert-from:offset # ignore insert-to because it's already been spliced away # assert insert-to matches next(before-cursor) insert-range before-cursor, insert-from # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - cursor-row <- get typing, after-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get typing, after-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get typing, after-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + cursor-row <- get typing, after-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get typing, after-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get typing, after-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] @@ -466,7 +466,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor, type something, undo assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e assume-console [ type [012] @@ -512,10 +512,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text, do some work, undo assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e assume-console [ type [1] @@ -555,7 +555,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e # insert some text and tabs, hit enter, some more text and tabs assume-console [ @@ -575,11 +575,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 7 + 3 <- 2 + 4 <- 7 ] # undo assume-console [ @@ -589,11 +589,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # typing in second line deleted, but not indent - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 2 + 3 <- 2 + 4 <- 2 ] screen-should-contain [ . . @@ -610,11 +610,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # indent and newline deleted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 8 + 3 <- 1 + 4 <- 8 ] screen-should-contain [ . . @@ -630,11 +630,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # empty screen - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] screen-should-contain [ . . @@ -650,11 +650,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # first line inserted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 8 + 3 <- 1 + 4 <- 8 ] screen-should-contain [ . . @@ -670,11 +670,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # newline and indent inserted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 2 + 3 <- 2 + 4 <- 2 ] screen-should-contain [ . . @@ -691,11 +691,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # indent and newline deleted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 7 + 3 <- 2 + 4 <- 7 ] screen-should-contain [ . . @@ -712,14 +712,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor assume-console [ - left-click 3, 1 + left-click 3, 1 ] editor-event-loop screen, console, e # undo @@ -730,11 +730,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # click undone - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] # cursor should be in the right place assume-console [ @@ -753,49 +753,49 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <move-cursor-begin> [ - cursor-row-before:num <- get *editor, cursor-row:offset - cursor-column-before:num <- get *editor, cursor-column:offset - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row-before:num <- get *editor, cursor-row:offset + cursor-column-before:num <- get *editor, cursor-column:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset ] before <move-cursor-end> [ - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset { break-unless undo-coalesce-tag # if previous operation was also a move, and also had the same coalesce # tag, coalesce with it - undo:&:list:&:operation <- get *editor, undo:offset + undo:&:list:&:operation <- get *editor, undo:offset break-unless undo - op:&:operation <- first undo - move:move-operation, is-move?:bool <- maybe-convert *op, move:variant + op:&:operation <- first undo + move:move-operation, is-move?:bool <- maybe-convert *op, move:variant break-unless is-move? - previous-coalesce-tag:num <- get move, tag:offset - coalesce?:bool <- equal undo-coalesce-tag, previous-coalesce-tag + previous-coalesce-tag:num <- get move, tag:offset + coalesce?:bool <- equal undo-coalesce-tag, previous-coalesce-tag break-unless coalesce? - move <- put move, after-row:offset, cursor-row - move <- put move, after-column:offset, cursor-column - move <- put move, after-top-of-screen:offset, top-after - *op <- merge 1/move-operation, move + move <- put move, after-row:offset, cursor-row + move <- put move, after-column:offset, cursor-column + move <- put move, after-top-of-screen:offset, top-after + *op <- merge 1/move-operation, move break +done-adding-move-operation } - op:&:operation <- new operation:type - *op <- merge 1/move-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag - editor <- add-operation editor, op + op:&:operation <- new operation:type + *op <- merge 1/move-operation, cursor-row-before, cursor-column-before, top-before, cursor-row/after, cursor-column/after, top-after, undo-coalesce-tag + editor <- add-operation editor, op +done-adding-move-operation ] after <handle-undo> [ { - move:move-operation, is-move?:bool <- maybe-convert *op, move:variant + move:move-operation, is-move?:bool <- maybe-convert *op, move:variant break-unless is-move? # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - cursor-row <- get move, before-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get move, before-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get move, before-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + cursor-row <- get move, before-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get move, before-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get move, before-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] @@ -804,18 +804,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # screen has 1 line for menu + 3 lines assume-screen 5/width, 4/height # editor contains a wrapped line - contents:text <- new [a + contents:text <- new [a b cdefgh] - e:&:editor <- new-editor contents, screen, 0/left, 5/right + e:&:editor <- new-editor contents, screen, 0/left, 5/right # position cursor at end of screen and try to move right assume-console [ - left-click 3, 3 + left-click 3, 3 press right-arrow ] editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset # screen scrolls screen-should-contain [ . . @@ -824,8 +824,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .gh . ] memory-should-contain [ - 3 <- 3 - 4 <- 0 + 3 <- 3 + 4 <- 0 ] # undo assume-console [ @@ -835,11 +835,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moved back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 3 - 4 <- 3 + 3 <- 3 + 4 <- 3 ] # scroll undone screen-should-contain [ @@ -867,14 +867,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor assume-console [ - left-click 3, 1 + left-click 3, 1 press left-arrow ] editor-event-loop screen, console, e @@ -886,11 +886,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 3 - 4 <- 1 + 3 <- 3 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -912,22 +912,22 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor assume-console [ - left-click 3, 1 + left-click 3, 1 press up-arrow ] editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # undo assume-console [ @@ -937,11 +937,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 3 - 4 <- 1 + 3 <- 3 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -963,14 +963,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor assume-console [ - left-click 2, 1 + left-click 2, 1 press down-arrow ] editor-event-loop screen, console, e @@ -982,11 +982,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1008,13 +1008,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with multiple pages of text assume-screen 10/width, 5/height - contents:text <- new [a + contents:text <- new [a b c d e f] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # scroll the page assume-console [ @@ -1042,13 +1042,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with multiple pages of text assume-screen 10/width, 5/height - contents:text <- new [a + contents:text <- new [a b c d e f] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # scroll the page assume-console [ @@ -1076,13 +1076,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with multiple pages of text assume-screen 10/width, 5/height - contents:text <- new [a + contents:text <- new [a b c d e f] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # scroll the page down and up assume-console [ @@ -1111,13 +1111,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with multiple pages of text assume-screen 10/width, 5/height - contents:text <- new [a + contents:text <- new [a b c d e f] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # scroll the page down and up assume-console [ @@ -1146,14 +1146,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor, then to start of line assume-console [ - left-click 2, 1 + left-click 2, 1 press ctrl-a ] editor-event-loop screen, console, e @@ -1165,11 +1165,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1191,14 +1191,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor, then to start of line assume-console [ - left-click 2, 1 + left-click 2, 1 press home ] editor-event-loop screen, console, e @@ -1210,11 +1210,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1236,14 +1236,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor, then to start of line assume-console [ - left-click 2, 1 + left-click 2, 1 press ctrl-e ] editor-event-loop screen, console, e @@ -1255,11 +1255,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1281,14 +1281,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor, then to start of line assume-console [ - left-click 2, 1 + left-click 2, 1 press end ] editor-event-loop screen, console, e @@ -1300,11 +1300,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves back - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1326,24 +1326,24 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # move the cursor assume-console [ - left-click 2, 1 + left-click 2, 1 press right-arrow press right-arrow press up-arrow ] editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] # undo assume-console [ @@ -1353,11 +1353,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # up-arrow is undone - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 3 + 3 <- 2 + 4 <- 3 ] # undo again assume-console [ @@ -1367,11 +1367,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # both right-arrows are undone - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 2 - 4 <- 1 + 3 <- 2 + 4 <- 1 ] ] @@ -1381,13 +1381,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor with some text, click on a character, undo assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def ghi] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e assume-console [ - left-click 3, 1 + left-click 3, 1 press ctrl-z ] editor-event-loop screen, console, e @@ -1399,11 +1399,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # cursor moves to left-click - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 3 - 4 <- 1 + 3 <- 3 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -1423,15 +1423,15 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color after <handle-redo> [ { - move:move-operation, is-move?:bool <- maybe-convert *op, move:variant + move:move-operation, is-move?:bool <- maybe-convert *op, move:variant break-unless is-move? # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - cursor-row <- get move, after-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get move, after-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get move, after-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + cursor-row <- get move, after-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get move, after-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get move, after-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] @@ -1439,16 +1439,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor, type some text, move the cursor, type some more text assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e assume-console [ type [abc] - left-click 1, 1 + left-click 1, 1 type [d] ] editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset screen-should-contain [ . . .adbc . @@ -1456,8 +1456,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] # undo assume-console [ @@ -1465,8 +1465,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # last letter typed is deleted screen-should-contain [ @@ -1476,8 +1476,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # undo again assume-console [ @@ -1485,8 +1485,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # no change to screen; cursor moves screen-should-contain [ @@ -1496,8 +1496,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] # undo again assume-console [ @@ -1505,8 +1505,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # screen empty screen-should-contain [ @@ -1516,8 +1516,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] # redo assume-console [ @@ -1525,8 +1525,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # first insert screen-should-contain [ @@ -1536,8 +1536,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] # redo again assume-console [ @@ -1545,8 +1545,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # cursor moves screen-should-contain [ @@ -1557,8 +1557,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] # cursor moves memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # redo again assume-console [ @@ -1566,8 +1566,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] run [ editor-event-loop screen, console, e - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset ] # second insert screen-should-contain [ @@ -1577,8 +1577,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color . . ] memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] ] @@ -1588,7 +1588,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e # insert some text and hit backspace assume-console [ @@ -1603,11 +1603,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # undo assume-console [ @@ -1616,11 +1616,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 3 + 3 <- 1 + 4 <- 3 ] screen-should-contain [ . . @@ -1635,11 +1635,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] screen-should-contain [ . . @@ -1651,79 +1651,79 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color # save operation to undo after <backspace-character-begin> [ - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset ] before <backspace-character-end> [ { break-unless backspaced-cell # backspace failed; don't add an undo operation - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-row:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - undo:&:list:&:operation <- get *editor, undo:offset + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-row:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + undo:&:list:&:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:&:operation <- first undo - deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant + op:&:operation <- first undo + deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant break-unless is-delete? - previous-coalesce-tag:num <- get deletion, tag:offset - coalesce?:bool <- equal previous-coalesce-tag, 1/coalesce-backspace + previous-coalesce-tag:num <- get deletion, tag:offset + coalesce?:bool <- equal previous-coalesce-tag, 1/coalesce-backspace break-unless coalesce? - deletion <- put deletion, delete-from:offset, before-cursor - backspaced-so-far:&:duplex-list:char <- get deletion, deleted-text:offset + deletion <- put deletion, delete-from:offset, before-cursor + backspaced-so-far:&:duplex-list:char <- get deletion, deleted-text:offset insert-range backspaced-cell, backspaced-so-far - deletion <- put deletion, deleted-text:offset, backspaced-cell - deletion <- put deletion, after-row:offset, cursor-row - deletion <- put deletion, after-column:offset, cursor-column - deletion <- put deletion, after-top-of-screen:offset, top-after - *op <- merge 2/delete-operation, deletion + deletion <- put deletion, deleted-text:offset, backspaced-cell + deletion <- put deletion, after-row:offset, cursor-row + deletion <- put deletion, after-column:offset, cursor-column + deletion <- put deletion, after-top-of-screen:offset, top-after + *op <- merge 2/delete-operation, deletion break +done-adding-backspace-operation } # if not, create a new operation - op:&:operation <- new operation:type - deleted-until:&:duplex-list:char <- next before-cursor - *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, 1/coalesce-backspace - editor <- add-operation editor, op + op:&:operation <- new operation:type + deleted-until:&:duplex-list:char <- next before-cursor + *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, backspaced-cell/deleted, before-cursor/delete-from, deleted-until, 1/coalesce-backspace + editor <- add-operation editor, op +done-adding-backspace-operation } ] after <handle-undo> [ { - deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant + deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant break-unless is-delete? - anchor:&:duplex-list:char <- get deletion, delete-from:offset + anchor:&:duplex-list:char <- get deletion, delete-from:offset break-unless anchor - deleted:&:duplex-list:char <- get deletion, deleted-text:offset - old-cursor:&:duplex-list:char <- last deleted + deleted:&:duplex-list:char <- get deletion, deleted-text:offset + old-cursor:&:duplex-list:char <- last deleted insert-range anchor, deleted # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - before-cursor <- copy old-cursor - cursor-row <- get deletion, before-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get deletion, before-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get deletion, before-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + before-cursor <- copy old-cursor + cursor-row <- get deletion, before-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get deletion, before-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get deletion, before-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] after <handle-redo> [ { - deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant + deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant break-unless is-delete? - start:&:duplex-list:char <- get deletion, delete-from:offset - end:&:duplex-list:char <- get deletion, delete-until:offset - data:&:duplex-list:char <- get *editor, data:offset + start:&:duplex-list:char <- get deletion, delete-from:offset + end:&:duplex-list:char <- get deletion, delete-until:offset + data:&:duplex-list:char <- get *editor, data:offset remove-between start, end # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen - cursor-row <- get deletion, after-row:offset - *editor <- put *editor, cursor-row:offset, cursor-row - cursor-column <- get deletion, after-column:offset - *editor <- put *editor, cursor-column:offset, cursor-column - top:&:duplex-list:char <- get deletion, before-top-of-screen:offset - *editor <- put *editor, top-of-screen:offset, top + cursor-row <- get deletion, after-row:offset + *editor <- put *editor, cursor-row:offset, cursor-row + cursor-column <- get deletion, after-column:offset + *editor <- put *editor, cursor-column:offset, cursor-column + top:&:duplex-list:char <- get deletion, before-top-of-screen:offset + *editor <- put *editor, top-of-screen:offset, top } ] @@ -1733,12 +1733,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e # insert some text and hit delete and backspace a few times assume-console [ type [abcdef] - left-click 1, 2 + left-click 1, 2 press delete press backspace press delete @@ -1751,11 +1751,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # undo deletes assume-console [ @@ -1764,11 +1764,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] screen-should-contain [ . . @@ -1783,11 +1783,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] screen-should-contain [ . . @@ -1802,11 +1802,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color run [ editor-event-loop screen, console, e ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] screen-should-contain [ . . @@ -1822,11 +1822,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # first line inserted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] screen-should-contain [ . . @@ -1842,11 +1842,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # first line inserted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] screen-should-contain [ . . @@ -1862,11 +1862,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color editor-event-loop screen, console, e ] # first line inserted - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] screen-should-contain [ . . @@ -1877,41 +1877,41 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <delete-character-begin> [ - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset ] before <delete-character-end> [ { break-unless deleted-cell # delete failed; don't add an undo operation - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - undo:&:list:&:operation <- get *editor, undo:offset + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + undo:&:list:&:operation <- get *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless undo - op:&:operation <- first undo - deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant + op:&:operation <- first undo + deletion:delete-operation, is-delete?:bool <- maybe-convert *op, delete:variant break-unless is-delete? - previous-coalesce-tag:num <- get deletion, tag:offset - coalesce?:bool <- equal previous-coalesce-tag, 2/coalesce-delete + previous-coalesce-tag:num <- get deletion, tag:offset + coalesce?:bool <- equal previous-coalesce-tag, 2/coalesce-delete break-unless coalesce? - delete-until:&:duplex-list:char <- next before-cursor - deletion <- put deletion, delete-until:offset, delete-until - deleted-so-far:&:duplex-list:char <- get deletion, deleted-text:offset - deleted-so-far <- append deleted-so-far, deleted-cell - deletion <- put deletion, deleted-text:offset, deleted-so-far - deletion <- put deletion, after-row:offset, cursor-row - deletion <- put deletion, after-column:offset, cursor-column - deletion <- put deletion, after-top-of-screen:offset, top-after - *op <- merge 2/delete-operation, deletion + delete-until:&:duplex-list:char <- next before-cursor + deletion <- put deletion, delete-until:offset, delete-until + deleted-so-far:&:duplex-list:char <- get deletion, deleted-text:offset + deleted-so-far <- append deleted-so-far, deleted-cell + deletion <- put deletion, deleted-text:offset, deleted-so-far + deletion <- put deletion, after-row:offset, cursor-row + deletion <- put deletion, after-column:offset, cursor-column + deletion <- put deletion, after-top-of-screen:offset, top-after + *op <- merge 2/delete-operation, deletion break +done-adding-delete-operation } # if not, create a new operation - op:&:operation <- new operation:type - deleted-until:&:duplex-list:char <- next before-cursor - *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, 2/coalesce-delete - editor <- add-operation editor, op + op:&:operation <- new operation:type + deleted-until:&:duplex-list:char <- next before-cursor + *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cell/deleted, before-cursor/delete-from, deleted-until, 2/coalesce-delete + editor <- add-operation editor, op +done-adding-delete-operation } ] @@ -1922,13 +1922,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # insert some text and hit delete and backspace a few times assume-console [ - left-click 1, 1 + left-click 1, 1 press ctrl-k ] editor-event-loop screen, console, e @@ -1939,11 +1939,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # undo assume-console [ @@ -1959,11 +1959,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # redo assume-console [ @@ -1980,11 +1980,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 1 + 3 <- 1 + 4 <- 1 ] # cursor should be in the right place assume-console [ @@ -2003,18 +2003,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <delete-to-end-of-line-begin> [ - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset ] before <delete-to-end-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - deleted-until:&:duplex-list:char <- next before-cursor - op:&:operation <- new operation:type - *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce - editor <- add-operation editor, op + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + deleted-until:&:duplex-list:char <- next before-cursor + op:&:operation <- new operation:type + *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce + editor <- add-operation editor, op +done-adding-delete-operation } ] @@ -2025,13 +2025,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - contents:text <- new [abc + contents:text <- new [abc def] - e:&:editor <- new-editor contents, screen, 0/left, 10/right + e:&:editor <- new-editor contents, screen, 0/left, 10/right editor-render screen, e # insert some text and hit delete and backspace a few times assume-console [ - left-click 1, 2 + left-click 1, 2 press ctrl-u ] editor-event-loop screen, console, e @@ -2042,11 +2042,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] # undo assume-console [ @@ -2062,11 +2062,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 2 + 3 <- 1 + 4 <- 2 ] # redo assume-console [ @@ -2083,11 +2083,11 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .╌╌╌╌╌╌╌╌╌╌. . . ] - 3:num/raw <- get *e, cursor-row:offset - 4:num/raw <- get *e, cursor-column:offset + 3:num/raw <- get *e, cursor-row:offset + 4:num/raw <- get *e, cursor-column:offset memory-should-contain [ - 3 <- 1 - 4 <- 0 + 3 <- 1 + 4 <- 0 ] # cursor should be in the right place assume-console [ @@ -2106,19 +2106,19 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] after <delete-to-start-of-line-begin> [ - top-before:&:duplex-list:char <- get *editor, top-of-screen:offset + top-before:&:duplex-list:char <- get *editor, top-of-screen:offset ] before <delete-to-start-of-line-end> [ { break-unless deleted-cells # delete failed; don't add an undo operation - top-after:&:duplex-list:char <- get *editor, top-of-screen:offset - op:&:operation <- new operation:type - before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset - deleted-until:&:duplex-list:char <- next before-cursor - cursor-row:num <- get *editor, cursor-row:offset - cursor-column:num <- get *editor, cursor-column:offset - *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce - editor <- add-operation editor, op + top-after:&:duplex-list:char <- get *editor, top-of-screen:offset + op:&:operation <- new operation:type + before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset + deleted-until:&:duplex-list:char <- next before-cursor + cursor-row:num <- get *editor, cursor-row:offset + cursor-column:num <- get *editor, cursor-column:offset + *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, cursor-row/after, cursor-column/after, top-after, deleted-cells/deleted, before-cursor/delete-from, deleted-until, 0/never-coalesce + editor <- add-operation editor, op +done-adding-delete-operation } ] @@ -2127,7 +2127,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color local-scope # create an editor assume-screen 10/width, 5/height - e:&:editor <- new-editor [], screen, 0/left, 10/right + e:&:editor <- new-editor [], screen, 0/left, 10/right editor-render screen, e # insert some text and hit delete and backspace a few times assume-console [ -- cgit 1.4.1-2-gfad0