scenario clicking-on-a-sandbox-moves-it-to-editor [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
recipes:text <- new [
recipe foo [
reply 4
]]
env:&:environment <- new-programming-environment screen:&:screen, recipes, [foo]
assume-console [
press F4
]
event-loop screen:&:screen, console:&:console, env
screen-should-contain [
. run (F4) .
. ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊0 edit copy delete .
.] ┊foo .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
left-click 3, 55
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊foo .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊ .
.] ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
assume-console [
type [0]
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊0foo .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊ .
.] ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
scenario clicking-on-a-sandbox-moves-it-to-editor-2 [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
recipes:text <- new [
recipe foo [
reply 4
]]
env:&:environment <- new-programming-environment screen:&:screen, recipes, [foo]
assume-console [
press F4
]
event-loop screen:&:screen, console:&:console, env
screen-should-contain [
. run (F4) .
. ┊ .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊0 edit copy delete .
.] ┊foo .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
left-click 3, 68
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊foo .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊ .
.] ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
assume-console [
type [0]
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊0foo .
.recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. reply 4 ┊ .
.] ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ .
. ┊ .
]
]
after <global-touch> [
{
edit?:bool <- should-attempt-edit? click-row, click-column, env
break-unless edit?
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
show-screen screen
loop +next-event:label
}
]
def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> result:bool [
local-scope
load-ingredients
click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env
reply-unless click-sandbox-area?, 0/false
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
reply-unless edit-button-vertical-area?, 0/false
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
sandbox:&:sandbox <- find-sandbox env, click-row
return-unless sandbox, 0/false
clicked-on-edit-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
env <- delete-sandbox env, sandbox
*env <- put *env, render-from:offset, -1
*env <- put *env, sandbox-in-focus?:offset, 1/true
]
scenario sandbox-with-print-can-be-edited [
local-scope
trace-until 100/app
assume-screen 100/width, 20/height
env:&:environment <- new-programming-environment screen:&:screen, [], [print-integer screen, 4]
assume-console [
press F4
]
event-loop screen:&:screen, console:&:console, env
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊print-integer screen, 4 .
. ┊screen: .
. ┊ .4 . .
. ┊ . . .
. ┊ . . .
. ┊ . . .
. ┊ . . .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
left-click 3, 65
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊print-integer screen, 4 .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
. ┊ .
]
]
scenario editing-sandbox-after-scrolling-resets-scroll [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:&:environment <- new-programming-environment screen:&:screen, [], []
render-all screen, env, render
assume-console [
press ctrl-n
type [add 2, 2]
press F4
type [add 1, 1]
press F4
press page-down
press page-down
]
event-loop screen:&:screen, console:&:console, env
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
assume-console [
left-click 2, 55
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊add 2, 2 .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]
scenario editing-sandbox-updates-sandbox-count [
local-scope
trace-until 100/app
assume-screen 100/width, 10/height
env:&:environment <- new-programming-environment screen:&:screen, [], []
render-all screen, env, render
assume-console [
press ctrl-n
type [add 2, 2]
press F4
type [add 1, 1]
press F4
]
event-loop screen:&:screen, console:&:console, env
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
left-click 3, 60
press F4
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊ .
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊0 edit copy delete .
. ┊add 1, 1 .
. ┊2 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
]
assume-console [
press page-down
press page-down
press page-down
]
run [
event-loop screen:&:screen, console:&:console, env
]
screen-should-contain [
. run (F4) .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
.┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊1 edit copy delete .
. ┊add 2, 2 .
. ┊4 .
. ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
. ┊ .
]
]