From 5405a972e44259d65c374a3c9e583e026ad7cd8e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 25 Jun 2017 01:48:56 -0700 Subject: 3954 As a blanket rule, down-arrow now stops scrolling once the bottom margin comes on screen. Now that we have page-wise scrolling with ctrl-f/b and line-wise scrolling with ctrl-s/x, we don't need to conflate scroll positioning with the arrow keys. And as a result, early students no longer have to struggle with accidentally scrolling part of the sandbox off the screen when there's tons of empty space available. `move-to-next-line` is still super messy and will need further rethinking, but this commit simplifies the codebase as a whole by eliminating a couple of historical accidents: a) We only introduced scrolling past the bottom of the screen to allow more sandboxes to come into view before we had scrolling for the sandbox side. b) We undid scrolling past the bottom in just the recipe side to allow errors to come into view. Since these historical details are now irrelevant, we no longer need separate logic for the recipe and sandbox sides, and we don't need to keep track of the recipe-bottom separate from the bottom margin of arbitrary editors. --- edit/003-shortcuts.mu | 85 +++++++++++++++++++++++---------------------------- edit/005-sandbox.mu | 54 -------------------------------- edit/011-errors.mu | 10 +----- 3 files changed, 39 insertions(+), 110 deletions(-) (limited to 'edit') diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu index 7089a26b..ae9609a7 100644 --- a/edit/003-shortcuts.mu +++ b/edit/003-shortcuts.mu @@ -1360,9 +1360,31 @@ def move-to-next-line editor:&:editor, screen-height:num -> go-render?:bool, edi left:num <- get *editor, left:offset right:num <- get *editor, right:offset last-line:num <- subtract screen-height, 1 - break-unless before-cursor, +try-to-scroll + bottom:num <- get *editor, bottom:offset + at-bottom-of-screen?:bool <- greater-or-equal bottom, last-line + { + break-if before-cursor + { + break-if at-bottom-of-screen? + return 0/don't-render + } + { + break-unless at-bottom-of-screen? + jump +try-to-scroll + } + } next:&:duplex-list:char <- next before-cursor - break-unless next, +try-to-scroll + { + break-if next + { + break-if at-bottom-of-screen? + return 0/don't-render + } + { + break-unless at-bottom-of-screen? + jump +try-to-scroll + } + } already-at-bottom?:bool <- greater-or-equal cursor-row, last-line { # if cursor not at bottom, move it @@ -1381,7 +1403,17 @@ def move-to-next-line editor:&:editor, screen-height:num -> go-render?:bool, edi break-if at-newline? loop } - break-unless next # at bottom of editor; scroll + { + break-if next + { + break-if at-bottom-of-screen? + return 0/don't-render + } + { + break-unless at-bottom-of-screen? + jump +try-to-scroll + } + } cursor-row <- add cursor-row, 1 cursor-column <- copy left { @@ -3012,51 +3044,10 @@ de] 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 + # no change memory-should-contain [ - 3 <- 1 - 4 <- 2 - ] - assume-console [ - type [0] - ] - run [ - editor-event-loop screen, console, e - ] - screen-should-contain [ - . . - .de0 . - .┈┈┈┈┈┈┈┈┈┈. - . . - ] - # try to move down again - $clear-trace - assume-console [ - 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 - ] - # screen stops scrolling because cursor is already at top - memory-should-contain [ - 3 <- 1 - 4 <- 3 - ] - check-trace-count-for-label 0, [print-character] - assume-console [ - type [1] - ] - run [ - editor-event-loop screen, console, e - ] - screen-should-contain [ - . . - .de01 . - .┈┈┈┈┈┈┈┈┈┈. - . . + 3 <- 2 + 4 <- 0 ] ] diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index e154b69c..d8058d18 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -754,60 +754,6 @@ scenario cursor-down-in-recipe-editor [ ] ] -# we'll not use the recipe-editor's 'bottom' element directly, because later -# layers will add other stuff to the left side below the editor (error messages) - -container environment [ - recipe-bottom:num -] - -after [ - *env <- put *env, recipe-bottom:offset, row -] - -after [ - { - break-if sandbox-in-focus? - 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 - break-unless at-bottom-of-editor? - 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 - break-unless page-down? - more-to-scroll?:bool <- more-to-scroll? env, screen - break-if more-to-scroll? - loop +next-event - } -] - -after [ - { - break-if sandbox-in-focus? - page-down?:bool <- equal k, 6/ctrl-f - break-unless page-down? - more-to-scroll?:bool <- more-to-scroll? env, screen - break-if more-to-scroll? - loop +next-event - } -] - -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 -] - scenario scrolling-down-past-bottom-of-recipe-editor-2 [ local-scope trace-until 100/app diff --git a/edit/011-errors.mu b/edit/011-errors.mu index 049a0853..b12286ed 100644 --- a/edit/011-errors.mu +++ b/edit/011-errors.mu @@ -30,7 +30,7 @@ after [ recipes:&:editor <- get *env, recipes:offset left:num <- get *recipes, left:offset right:num <- get *recipes, right:offset - row:num <- get *env, recipe-bottom:offset + row:num <- get *recipes, bottom:offset row, screen <- render-text screen, recipe-errors, left, right, 1/red, row # draw dotted line after recipes draw-horizontal screen, row, left, right, 9480/horizontal-dotted @@ -146,7 +146,6 @@ scenario run-shows-errors-in-get [ .recipe foo [ ┊foo . . get 123:num, foo:offset ┊─────────────────────────────────────────────────. .] ┊ . - . ┊ . .foo: unknown element 'foo' in container 'number' ┊ . .foo: first ingredient of 'get' should be a contai↩┊ . .ner, but got '123:num' ┊ . @@ -158,7 +157,6 @@ scenario run-shows-errors-in-get [ . . . . . . - . . .foo: unknown element 'foo' in container 'number' . .foo: first ingredient of 'get' should be a contai . .ner, but got '123:num' . @@ -400,7 +398,6 @@ scenario run-shows-missing-type-errors [ .recipe foo [ ┊foo . . x <- copy 0 ┊─────────────────────────────────────────────────. .] ┊ . - . ┊ . .foo: missing type for 'x' in 'x <- copy 0' ┊ . .foo: can't copy '0' to 'x'; types don't match ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . @@ -431,7 +428,6 @@ scenario run-shows-unbalanced-bracket-errors [ . errors found run (F4) . .recipe foo \\[ ┊foo . . x <- copy 0 ┊─────────────────────────────────────────────────. - . ┊ . .9: unbalanced '\\[' for recipe ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . ┊ . @@ -466,7 +462,6 @@ scenario run-shows-get-on-non-container-errors [ . x:&:point <- new point:type ┊ . . get x:&:point, 1:offset ┊ . .] ┊ . - . ┊ . .foo: first ingredient of 'get' should be a contai↩┊ . .ner, but got 'x:&:point' ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . @@ -504,7 +499,6 @@ scenario run-shows-non-literal-get-argument-errors [ . y:&:point <- new point:type ┊ . . get *y:&:point, x:num ┊ . .] ┊ . - . ┊ . .foo: second ingredient of 'get' should have type ↩┊ . .'offset', but got 'x:num' ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . @@ -537,7 +531,6 @@ scenario run-shows-errors-everytime [ . local-scope ┊─────────────────────────────────────────────────. . x:num <- copy y:num ┊ . .] ┊ . - . ┊ . .foo: tried to read ingredient 'y' in 'x:num <- co↩┊ . .py y:num' but it hasn't been written to yet ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . @@ -556,7 +549,6 @@ scenario run-shows-errors-everytime [ . local-scope ┊─────────────────────────────────────────────────. . x:num <- copy y:num ┊ . .] ┊ . - . ┊ . .foo: tried to read ingredient 'y' in 'x:num <- co↩┊ . .py y:num' but it hasn't been written to yet ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . -- cgit 1.4.1-2-gfad0