<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit/003-shortcuts.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muScenario { color: #00af00; }
.Special { color: #ff6060; }
.muRecipe { color: #ff8700; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.SalientComment { color: #00ffff; }
.Delimiter { color: #a04060; }
.muControl { color: #c0a020; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="SalientComment">## special shortcuts for manipulating the editor</span>
<span class="Comment"># Some keys on the keyboard generate unicode characters, others generate</span>
<span class="Comment"># terminfo key codes. We need to modify different places in the two cases.</span>
<span class="Comment"># tab - insert two spaces</span>
<span class="muScenario">scenario</span> editor-inserts-two-spaces-on-tab [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># just one character in final line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span>
<span class="Constant">cd]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
assume-console [
press tab
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . ab .</span>
<span class="Constant"> .cd .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
tab?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">9/tab</span>
<span class="muControl">break-unless</span> tab?
<span class="Constant"> <insert-character-begin></span>
editor, screen, go-render?:boolean<span class="Special"> <- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen
editor, screen, go-render?:boolean<span class="Special"> <- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen
<span class="Constant"> <insert-character-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="Comment"># backspace - delete character before cursor</span>
<span class="muScenario">scenario</span> editor-handles-backspace-key [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">1</span>
press backspace
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .bc .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
delete-previous-character?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">8/backspace</span>
<span class="muControl">break-unless</span> delete-previous-character?
<span class="Constant"> <backspace-character-begin></span>
editor, screen, go-render?:boolean, backspaced-cell:address:duplex-list<span class="Special"> <- </span>delete-before-cursor editor, screen
<span class="Constant"> <backspace-character-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="Comment"># editor, screen, go-render?:boolean, backspaced-cell:address:duplex-list <- delete-before-cursor editor:address:editor-data, screen</span>
<span class="Comment"># return values:</span>
<span class="Comment"># go-render? - whether caller needs to update the screen</span>
<span class="Comment"># backspaced-cell - value deleted (or 0 if nothing was deleted) so we can save it for undo, etc.</span>
<span class="muRecipe">recipe</span> delete-before-cursor [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
<span class="Comment"># if at start of text (before-cursor at § sentinel), return</span>
prev:address:duplex-list<span class="Special"> <- </span>prev-duplex *before-cursor
<span class="muControl">reply-unless</span> prev, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span>
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[delete-before-cursor]</span>
original-row:number<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span>
editor, scroll?:boolean<span class="Special"> <- </span>move-cursor-coordinates-left editor
backspaced-cell:address:duplex-list<span class="Special"> <- </span>copy *before-cursor
remove-duplex *before-cursor <span class="Comment"># will also neatly trim next/prev pointers in backspaced-cell/*before-cursor</span>
*before-cursor<span class="Special"> <- </span>copy prev
<span class="muControl">reply-if</span> scroll?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/go-render</span>, backspaced-cell
screen-width:number<span class="Special"> <- </span>screen-width screen
cursor-row:number<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:number<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span>
<span class="Comment"># did we just backspace over a newline?</span>
same-row?:boolean<span class="Special"> <- </span>equal cursor-row, original-row
<span class="muControl">reply-unless</span> same-row?, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>, backspaced-cell
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
curr:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column
curr-column:number<span class="Special"> <- </span>copy cursor-column
<span class="Delimiter">{</span>
<span class="Comment"># hit right margin? give up and let caller render</span>
at-right?:boolean<span class="Special"> <- </span>greater-or-equal curr-column, screen-width
<span class="muControl">reply-if</span> at-right?, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>, backspaced-cell
<span class="muControl">break-unless</span> curr
<span class="Comment"># newline? done.</span>
currc:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
screen<span class="Special"> <- </span>print-character screen, currc
curr-column<span class="Special"> <- </span>add curr-column, <span class="Constant">1</span>
curr<span class="Special"> <- </span>next-duplex curr
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="Comment"># we're guaranteed not to be at the right margin</span>
screen<span class="Special"> <- </span>print-character screen, <span class="Constant">32/space</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>, backspaced-cell
]
<span class="muRecipe">recipe</span> move-cursor-coordinates-left [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
before-cursor:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span>
cursor-row:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
<span class="Comment"># if not at left margin, move one character left</span>
<span class="Delimiter">{</span>
at-left-margin?:boolean<span class="Special"> <- </span>equal *cursor-column, left
<span class="muControl">break-if</span> at-left-margin?
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[decrementing cursor column]</span>
*cursor-column<span class="Special"> <- </span>subtract *cursor-column, <span class="Constant">1</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
<span class="Comment"># if at left margin, we must move to previous row:</span>
top-of-screen?:boolean<span class="Special"> <- </span>equal *cursor-row, <span class="Constant">1</span> <span class="Comment"># exclude menu bar</span>
go-render?:boolean<span class="Special"> <- </span>copy <span class="Constant">0/false</span>
<span class="Delimiter">{</span>
<span class="muControl">break-if</span> top-of-screen?
*cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span>
<span class="Delimiter">}</span>
<span class="Delimiter">{</span>
<span class="muControl">break-unless</span> top-of-screen?
<span class="Constant"> <scroll-up></span>
go-render?<span class="Special"> <- </span>copy <span class="Constant">1/true</span>
<span class="Delimiter">}</span>
<span class="Delimiter">{</span>
<span class="Comment"># case 1: if previous character was newline, figure out how long the previous line is</span>
previous-character:character<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span>
previous-character-is-newline?:boolean<span class="Special"> <- </span>equal previous-character, <span class="Constant">10/newline</span>
<span class="muControl">break-unless</span> previous-character-is-newline?
<span class="Comment"># compute length of previous line</span>
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[switching to previous line]</span>
d:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span>
end-of-line:number<span class="Special"> <- </span>previous-line-length before-cursor, d
*cursor-column<span class="Special"> <- </span>add left, end-of-line
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, go-render?
<span class="Delimiter">}</span>
<span class="Comment"># case 2: if previous-character was not newline, we're just at a wrapped line</span>
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[wrapping to previous line]</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
*cursor-column<span class="Special"> <- </span>subtract right, <span class="Constant">1</span> <span class="Comment"># leave room for wrap icon</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, go-render?
]
<span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span>
<span class="Comment"># the length of the previous line before the 'curr' pointer.</span>
<span class="muRecipe">recipe</span> previous-line-length [
<span class="Constant">local-scope</span>
curr:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
start:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
result:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
<span class="muControl">reply-unless</span> curr, result
at-start?:boolean<span class="Special"> <- </span>equal curr, start
<span class="muControl">reply-if</span> at-start?, result
<span class="Delimiter">{</span>
curr<span class="Special"> <- </span>prev-duplex curr
<span class="muControl">break-unless</span> curr
at-start?:boolean<span class="Special"> <- </span>equal curr, start
<span class="muControl">break-if</span> at-start?
c:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
result<span class="Special"> <- </span>add result, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply</span> result
]
<span class="muScenario">scenario</span> editor-clears-last-line-on-backspace [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># just one character in final line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span>
<span class="Constant">cd]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">0</span> <span class="Comment"># cursor at only character in final line</span>
press backspace
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">2</span>
]
]
<span class="Comment"># delete - delete character at cursor</span>
<span class="muScenario">scenario</span> editor-handles-delete-key [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
press delete
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .bc .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of original line to overwrite</span>
<span class="Constant"> $clear-trace</span>
assume-console [
press delete
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length to overwrite</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
delete-next-character?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65522/delete</span>
<span class="muControl">break-unless</span> delete-next-character?
<span class="Constant"> <delete-character-begin></span>
editor, screen, go-render?:boolean, deleted-cell:address:duplex-list<span class="Special"> <- </span>delete-at-cursor editor, screen
<span class="Constant"> <delete-character-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> delete-at-cursor [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
screen:address<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
candidate:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="muControl">reply-unless</span> candidate, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>, <span class="Constant">0/nothing-deleted</span>
currc:character<span class="Special"> <- </span>get *candidate, <span class="Constant">value:offset</span>
remove-duplex candidate
deleted-newline?:boolean<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span>
<span class="muControl">reply-if</span> deleted-newline?, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>, candidate/deleted-cell
<span class="Comment"># wasn't a newline? render rest of line</span>
curr:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor <span class="Comment"># refresh after remove-duplex above</span>
cursor-row:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
screen<span class="Special"> <- </span>move-cursor screen, *cursor-row, *cursor-column
curr-column:number<span class="Special"> <- </span>copy *cursor-column
screen-width:number<span class="Special"> <- </span>screen-width screen
<span class="Delimiter">{</span>
<span class="Comment"># hit right margin? give up and let caller render</span>
at-right?:boolean<span class="Special"> <- </span>greater-or-equal curr-column, screen-width
<span class="muControl">reply-if</span> at-right?, editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>, candidate/deleted-cell
<span class="muControl">break-unless</span> curr
<span class="Comment"># newline? done.</span>
currc:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
screen<span class="Special"> <- </span>print-character screen, currc
curr-column<span class="Special"> <- </span>add curr-column, <span class="Constant">1</span>
curr<span class="Special"> <- </span>next-duplex curr
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="Comment"># we're guaranteed not to be at the right margin</span>
screen<span class="Special"> <- </span>print-character screen, <span class="Constant">32/space</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, screen/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>, candidate/deleted-cell
]
<span class="Comment"># right arrow</span>
<span class="muScenario">scenario</span> editor-moves-cursor-right-with-key [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
press right-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a0bc .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span> <span class="Comment"># 0 and following characters</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-next-character?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65514/right-arrow</span>
<span class="muControl">break-unless</span> move-to-next-character?
<span class="Comment"># if not at end of text</span>
next-cursor:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="muControl">break-unless</span> next-cursor
<span class="Comment"># scan to next character</span>
<span class="Constant"> <move-cursor-begin></span>
*before-cursor<span class="Special"> <- </span>copy next-cursor
editor, go-render?:boolean<span class="Special"> <- </span>move-cursor-coordinates-right editor, screen-height
screen<span class="Special"> <- </span>move-cursor screen, *cursor-row, *cursor-column
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">2/right-arrow</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> move-cursor-coordinates-right [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
screen-height:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
before-cursor:address:duplex-list<span class="Special"> <- </span>get *editor <span class="Constant">before-cursor:offset</span>
cursor-row:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
<span class="Comment"># if crossed a newline, move cursor to start of next row</span>
<span class="Delimiter">{</span>
old-cursor-character:character<span class="Special"> <- </span>get *before-cursor, <span class="Constant">value:offset</span>
was-at-newline?:boolean<span class="Special"> <- </span>equal old-cursor-character, <span class="Constant">10/newline</span>
<span class="muControl">break-unless</span> was-at-newline?
*cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span>
*cursor-column<span class="Special"> <- </span>copy left
below-screen?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-row, screen-height <span class="Comment"># must be equal</span>
<span class="muControl">reply-unless</span> below-screen?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Constant"> <scroll-down></span>
*cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
<span class="Comment"># if the line wraps, move cursor to start of next row</span>
<span class="Delimiter">{</span>
<span class="Comment"># if we're at the column just before the wrap indicator</span>
wrap-column:number<span class="Special"> <- </span>subtract right, <span class="Constant">1</span>
at-wrap?:boolean<span class="Special"> <- </span>equal *cursor-column, wrap-column
<span class="muControl">break-unless</span> at-wrap?
<span class="Comment"># and if next character isn't newline</span>
next:address:duplex-list<span class="Special"> <- </span>next-duplex before-cursor
<span class="muControl">break-unless</span> next
next-character:character<span class="Special"> <- </span>get *next, <span class="Constant">value:offset</span>
newline?:boolean<span class="Special"> <- </span>equal next-character, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> newline?
*cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span>
*cursor-column<span class="Special"> <- </span>copy left
below-screen?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-row, screen-height <span class="Comment"># must be equal</span>
<span class="muControl">reply-unless</span> below-screen?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Constant"> <scroll-down></span>
*cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span> <span class="Comment"># bring back into screen range</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
<span class="Comment"># otherwise move cursor one character right</span>
*cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># type right-arrow a few times to get to start of second line</span>
assume-console [
press right-arrow
press right-arrow
press right-arrow
press right-arrow <span class="Comment"># next line</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
<span class="Comment"># type something and ensure it goes where it should</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .0d .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span> <span class="Comment"># new length of second line</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
assume-console [
press right-arrow
press right-arrow
press right-arrow
press right-arrow <span class="Comment"># next line</span>
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . abc .</span>
<span class="Constant"> . 0d .</span>
<span class="Constant"> . ┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd↩ .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .┈┈┈┈┈ .</span>
<span class="Constant"> . .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># line just barely wrapping</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcde]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># position cursor at last character before wrap and hit right-arrow</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
<span class="Comment"># now hit right arrow again</span>
assume-console [
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">1/left</span>, <span class="Constant">6/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">4</span>
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . abcd↩ .</span>
<span class="Constant"> . ef .</span>
<span class="Constant"> . ┈┈┈┈┈ .</span>
<span class="Constant"> . .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># move to end of line, press right-arrow, type a character</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press right-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># new character should be in next line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .0d .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span>
]
<span class="Comment"># todo: ctrl-right: next word-end</span>
<span class="Comment"># left arrow</span>
<span class="muScenario">scenario</span> editor-moves-cursor-left-with-key [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">2</span>
press left-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a0bc .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-previous-character?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65515/left-arrow</span>
<span class="muControl">break-unless</span> move-to-previous-character?
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[left arrow]</span>
<span class="Comment"># if not at start of text (before-cursor at § sentinel)</span>
prev:address:duplex-list<span class="Special"> <- </span>prev-duplex *before-cursor
<span class="muControl">reply-unless</span> prev, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="Constant"> <move-cursor-begin></span>
editor, go-render?<span class="Special"> <- </span>move-cursor-coordinates-left editor
*before-cursor<span class="Special"> <- </span>copy prev
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">1/left-arrow</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># initialize editor with two lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># position cursor at start of second line (so there's no previous newline)</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">0</span>
press left-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># initialize editor with three lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">def</span>
<span class="Constant">g]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># position cursor further down (so there's a newline before the character at</span>
<span class="Comment"># the cursor)</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press left-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .def0 .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">def</span>
<span class="Constant">g]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># position cursor at start of text, press left-arrow, then type a character</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">0</span>
press left-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># left-arrow should have had no effect</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .0abc .</span>
<span class="Constant"> .def .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
check-trace-count-for-label <span class="Constant">4</span>, <span class="Constant">[print-character]</span> <span class="Comment"># length of first line</span>
]
<span class="muScenario">scenario</span> editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># initialize editor with text containing an empty line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
d]
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># position cursor right after empty line</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press left-arrow
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .0 .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span> <span class="Comment"># just the '0'</span>
]
<span class="muScenario">scenario</span> editor-moves-across-screen-lines-across-wrap-with-left-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># initialize editor with text containing an empty line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd↩ .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .┈┈┈┈┈ .</span>
<span class="Constant"> . .</span>
]
<span class="Comment"># position cursor right after empty line</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">0</span>
press left-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span> <span class="Comment"># previous row</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span> <span class="Comment"># end of wrapped line</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="Comment"># todo: ctrl-left: previous word-start</span>
<span class="Comment"># up arrow</span>
<span class="muScenario">scenario</span> editor-moves-to-previous-line-with-up-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">1</span>
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a0bc .</span>
<span class="Constant"> .def .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-previous-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65517/up-arrow</span>
<span class="muControl">break-unless</span> move-to-previous-line?
<span class="Constant"> <move-cursor-begin></span>
editor, go-render?<span class="Special"> <- </span>move-to-previous-line editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">3/up-arrow</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> move-to-previous-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
cursor-row:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
already-at-top?:boolean<span class="Special"> <- </span>lesser-or-equal *cursor-row, <span class="Constant">1/top</span>
<span class="Delimiter">{</span>
<span class="Comment"># if cursor not at top, move it</span>
<span class="muControl">break-if</span> already-at-top?
<span class="Comment"># if not at newline, move to start of line (previous newline)</span>
<span class="Comment"># then scan back another line</span>
<span class="Comment"># if either step fails, give up without modifying cursor or coordinates</span>
curr:address:duplex-list<span class="Special"> <- </span>copy *before-cursor
<span class="Delimiter">{</span>
old:address:duplex-list<span class="Special"> <- </span>copy curr
c2:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal c2, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
curr:address:duplex-list<span class="Special"> <- </span>before-previous-line curr, editor
no-motion?:boolean<span class="Special"> <- </span>equal curr, old
<span class="muControl">reply-if</span> no-motion?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
<span class="Delimiter">{</span>
old<span class="Special"> <- </span>copy curr
curr<span class="Special"> <- </span>before-previous-line curr, editor
no-motion?:boolean<span class="Special"> <- </span>equal curr, old
<span class="muControl">reply-if</span> no-motion?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
*before-cursor<span class="Special"> <- </span>copy curr
*cursor-row<span class="Special"> <- </span>subtract *cursor-row, <span class="Constant">1</span>
<span class="Comment"># scan ahead to right column or until end of line</span>
target-column:number<span class="Special"> <- </span>copy *cursor-column
*cursor-column<span class="Special"> <- </span>copy left
<span class="Delimiter">{</span>
done?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-column, target-column
<span class="muControl">break-if</span> done?
curr:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="muControl">break-unless</span> curr
currc:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
<span class="Comment">#</span>
*before-cursor<span class="Special"> <- </span>copy curr
*cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
<span class="Delimiter">{</span>
<span class="Comment"># if cursor already at top, scroll up</span>
<span class="muControl">break-unless</span> already-at-top?
<span class="Constant"> <scroll-up></span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muScenario">scenario</span> editor-adjusts-column-at-previous-line [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[ab</span>
<span class="Constant">def]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .ab0 .</span>
<span class="Constant"> .def .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-adjusts-column-at-empty-line [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new [
def]
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .0 .</span>
<span class="Constant"> .def .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-moves-to-previous-line-from-left-margin [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># start out with three lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">def</span>
<span class="Constant">ghi]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># click on the third line and hit up-arrow, so you end up just after a newline</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .0def .</span>
<span class="Constant"> .ghi .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
]
<span class="Comment"># down arrow</span>
<span class="muScenario">scenario</span> editor-moves-to-next-line-with-down-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># cursor starts out at (1, 0)</span>
assume-console [
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># ..and ends at (2, 0)</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .0def .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-next-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65516/down-arrow</span>
<span class="muControl">break-unless</span> move-to-next-line?
<span class="Constant"> <move-cursor-begin></span>
editor, go-render?<span class="Special"> <- </span>move-to-next-line editor, screen-height
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">4/down-arrow</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, go-render?
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> move-to-next-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
screen-height:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
cursor-row:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
last-line:number<span class="Special"> <- </span>subtract screen-height, <span class="Constant">1</span>
already-at-bottom?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-row, last-line
<span class="Delimiter">{</span>
<span class="Comment"># if cursor not at bottom, move it</span>
<span class="muControl">break-if</span> already-at-bottom?
<span class="Comment"># scan to start of next line, then to right column or until end of line</span>
max:number<span class="Special"> <- </span>subtract right, left
next-line:address:duplex-list<span class="Special"> <- </span>before-start-of-next-line *before-cursor, max
<span class="Delimiter">{</span>
<span class="Comment"># already at end of buffer? try to scroll up (so we can see more</span>
<span class="Comment"># warnings or sandboxes below)</span>
no-motion?:boolean<span class="Special"> <- </span>equal next-line, *before-cursor
<span class="muControl">break-unless</span> no-motion?
scroll?:boolean<span class="Special"> <- </span>greater-than *cursor-row, <span class="Constant">1</span>
<span class="muControl">break-if</span> scroll?, <span class="Constant">+try-to-scroll:label</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
*cursor-row<span class="Special"> <- </span>add *cursor-row, <span class="Constant">1</span>
*before-cursor<span class="Special"> <- </span>copy next-line
target-column:number<span class="Special"> <- </span>copy *cursor-column
*cursor-column<span class="Special"> <- </span>copy left
<span class="Delimiter">{</span>
done?:boolean<span class="Special"> <- </span>greater-or-equal *cursor-column, target-column
<span class="muControl">break-if</span> done?
curr:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="muControl">break-unless</span> curr
currc:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal currc, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
<span class="Comment">#</span>
*before-cursor<span class="Special"> <- </span>copy curr
*cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
<span class="Constant"> +try-to-scroll</span>
<span class="Constant"> <scroll-down></span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">1/go-render</span>
]
<span class="muScenario">scenario</span> editor-adjusts-column-at-next-line [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">de]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abc .</span>
<span class="Constant"> .de0 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-at-end-on-down-arrow [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abc</span>
<span class="Constant">de]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># try to move down past end of text</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen should scroll, moving cursor to end of text</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span>
]
assume-console [
type <span class="Constant">[0]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .de0 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
<span class="Comment"># try to move down again</span>
<span class="Constant"> $clear-trace</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen stops scrolling because cursor is already at top</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
assume-console [
type <span class="Constant">[1]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .de01 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="Comment"># ctrl-a/home - move cursor to start of line</span>
<span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on second line, press ctrl-a</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press ctrl-a
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to start of line</span>
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
move-to-start-of-line?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">1/ctrl-a</span>
<span class="muControl">break-unless</span> move-to-start-of-line?
<span class="Constant"> <move-cursor-begin></span>
move-to-start-of-line editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-start-of-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65521/home</span>
<span class="muControl">break-unless</span> move-to-start-of-line?
<span class="Constant"> <move-cursor-begin></span>
move-to-start-of-line editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> move-to-start-of-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
<span class="Comment"># update cursor column</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
*cursor-column<span class="Special"> <- </span>copy left
<span class="Comment"># update before-cursor</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
init:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span>
<span class="Comment"># while not at start of line, move </span>
<span class="Delimiter">{</span>
at-start-of-text?:boolean<span class="Special"> <- </span>equal *before-cursor, init
<span class="muControl">break-if</span> at-start-of-text?
prev:character<span class="Special"> <- </span>get **before-cursor, <span class="Constant">value:offset</span>
at-start-of-line?:boolean<span class="Special"> <- </span>equal prev, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-start-of-line?
*before-cursor<span class="Special"> <- </span>prev-duplex *before-cursor
assert *before-cursor, <span class="Constant">[move-to-start-of-line tried to move before start of text]</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
]
<span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-ctrl-a-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on first line (no newline before), press ctrl-a</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press ctrl-a
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to start of line</span>
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on second line, press 'home'</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press home
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to start of line</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-to-start-of-line-with-home-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on first line (no newline before), press 'home'</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press home
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to start of line</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="Comment"># ctrl-e/end - move cursor to end of line</span>
<span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-ctrl-e [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on first line, press ctrl-e</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">1</span>
press ctrl-e
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to end of line</span>
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
<span class="Comment"># editor inserts future characters at cursor</span>
assume-console [
type <span class="Constant">[z]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">4</span>
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123z .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
move-to-end-of-line?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">5/ctrl-e</span>
<span class="muControl">break-unless</span> move-to-end-of-line?
<span class="Constant"> <move-cursor-begin></span>
move-to-end-of-line editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
move-to-end-of-line?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65520/end</span>
<span class="muControl">break-unless</span> move-to-end-of-line?
<span class="Constant"> <move-cursor-begin></span>
move-to-end-of-line editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> move-to-end-of-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
<span class="Comment"># while not at start of line, move </span>
<span class="Delimiter">{</span>
next:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="muControl">break-unless</span> next <span class="Comment"># end of text</span>
nextc:character<span class="Special"> <- </span>get *next, <span class="Constant">value:offset</span>
at-end-of-line?:boolean<span class="Special"> <- </span>equal nextc, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-end-of-line?
*before-cursor<span class="Special"> <- </span>copy next
*cursor-column<span class="Special"> <- </span>add *cursor-column, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
]
<span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-ctrl-e-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on second line (no newline after), press ctrl-e</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">1</span>
press ctrl-e
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">5</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to end of line</span>
memory-should-contain [
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">5</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on first line, press 'end'</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">1</span>
press end
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to end of line</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="muScenario">scenario</span> editor-moves-to-end-of-line-with-end-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
<span class="Constant"> $clear-trace</span>
<span class="Comment"># start on second line (no newline after), press 'end'</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">1</span>
press end
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># cursor moves to end of line</span>
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">2</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">3</span>
]
check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]
<span class="Comment"># ctrl-u - delete text from start of line until (but not at) cursor</span>
<span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start on second line, press ctrl-u</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">2</span>
press ctrl-u
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to start of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> .6 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
delete-to-start-of-line?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">21/ctrl-u</span>
<span class="muControl">break-unless</span> delete-to-start-of-line?
<span class="Constant"> <delete-to-start-of-line-begin></span>
deleted-cells:address:duplex-list<span class="Special"> <- </span>delete-to-start-of-line editor
<span class="Constant"> <delete-to-start-of-line-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> delete-to-start-of-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
<span class="Comment"># compute range to delete</span>
init:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
start:address:duplex-list<span class="Special"> <- </span>copy *before-cursor
end:address:duplex-list<span class="Special"> <- </span>next-duplex *before-cursor
<span class="Delimiter">{</span>
at-start-of-text?:boolean<span class="Special"> <- </span>equal start, init
<span class="muControl">break-if</span> at-start-of-text?
curr:character<span class="Special"> <- </span>get *start, <span class="Constant">value:offset</span>
at-start-of-line?:boolean<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-start-of-line?
start<span class="Special"> <- </span>prev-duplex start
assert start, <span class="Constant">[delete-to-start-of-line tried to move before start of text]</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="Comment"># snip it out</span>
result:address:duplex-list<span class="Special"> <- </span>next-duplex start
remove-duplex-between start, end
<span class="Comment"># adjust cursor</span>
*before-cursor<span class="Special"> <- </span>prev-duplex end
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
cursor-column:address:number<span class="Special"> <- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
*cursor-column<span class="Special"> <- </span>copy left
<span class="muControl">reply</span> result
]
<span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start on first line (no newline before), press ctrl-u</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">2</span>
press ctrl-u
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to start of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .3 .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-start-of-line-with-ctrl-u-3 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start past end of line, press ctrl-u</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press ctrl-u
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to start of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-start-of-final-line-with-ctrl-u [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start past end of final line, press ctrl-u</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press ctrl-u
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to start of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="Comment"># ctrl-k - delete text from cursor to end of line (but not the newline)</span>
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start on first line, press ctrl-k</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">1</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to end of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .1 .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
delete-to-end-of-line?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">11/ctrl-k</span>
<span class="muControl">break-unless</span> delete-to-end-of-line?
<span class="Constant"> <delete-to-end-of-line-begin></span>
deleted-cells:address:duplex-list<span class="Special"> <- </span>delete-to-end-of-line editor
<span class="Constant"> <delete-to-end-of-line-end></span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> delete-to-end-of-line [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
<span class="Comment"># compute range to delete</span>
start:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span>
end:address:duplex-list<span class="Special"> <- </span>next-duplex start
<span class="Delimiter">{</span>
at-end-of-text?:boolean<span class="Special"> <- </span>equal end, <span class="Constant">0/null</span>
<span class="muControl">break-if</span> at-end-of-text?
curr:character<span class="Special"> <- </span>get *end, <span class="Constant">value:offset</span>
at-end-of-line?:boolean<span class="Special"> <- </span>equal curr, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-end-of-line?
end<span class="Special"> <- </span>next-duplex end
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="Comment"># snip it out</span>
result:address:duplex-list<span class="Special"> <- </span>next-duplex start
remove-duplex-between start, end
<span class="muControl">reply</span> result
]
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-2 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start on second line (no newline after), press ctrl-k</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">1</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes to end of line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> .4 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-3 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start at end of line</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">2</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes just last character</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .12 .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-4 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start past end of line</span>
assume-console [
left-click <span class="Constant">1</span>, <span class="Constant">3</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes nothing</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-5 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start at end of text</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">2</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes just the final character</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> .45 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="muScenario">scenario</span> editor-deletes-to-end-of-line-with-ctrl-k-6 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[123</span>
<span class="Constant">456]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Comment"># start past end of text</span>
assume-console [
left-click <span class="Constant">2</span>, <span class="Constant">3</span>
press ctrl-k
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># cursor deletes nothing</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .123 .</span>
<span class="Constant"> .456 .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
<span class="Constant"> . .</span>
]
]
<span class="Comment"># cursor-down can scroll if necessary</span>
<span class="muScenario">scenario</span> editor-can-scroll-down-using-arrow-keys [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with >3 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># position cursor at last line, then try to move further down</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen slides by one line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><scroll-down></span> [
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll down]</span>
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
max:number<span class="Special"> <- </span>subtract right, left
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
*top-of-screen<span class="Special"> <- </span>before-start-of-next-line *top-of-screen, max
no-movement?:boolean<span class="Special"> <- </span>equal old-top, *top-of-screen
<span class="Comment"># Hack: this reply doesn't match one of the locations of <scroll-down>,</span>
<span class="Comment"># directly within insert-at-cursor. However, I'm unable to trigger the</span>
<span class="Comment"># error.. If necessary create a duplicate copy of <scroll-down> with the</span>
<span class="Comment"># right 'reply-if'.</span>
<span class="muControl">reply-if</span> no-movement?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
]
<span class="Comment"># takes a pointer into the doubly-linked list, scans ahead at most 'max'</span>
<span class="Comment"># positions until the next newline</span>
<span class="Comment"># beware: never return null pointer.</span>
<span class="muRecipe">recipe</span> before-start-of-next-line [
<span class="Constant">local-scope</span>
original:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
max:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
count:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
curr:address:duplex-list<span class="Special"> <- </span>copy original
<span class="Comment"># skip the initial newline if it exists</span>
<span class="Delimiter">{</span>
c:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span>
<span class="muControl">break-unless</span> at-newline?
curr<span class="Special"> <- </span>next-duplex curr
count<span class="Special"> <- </span>add count, <span class="Constant">1</span>
<span class="Delimiter">}</span>
<span class="Delimiter">{</span>
<span class="muControl">reply-unless</span> curr, original
done?:boolean<span class="Special"> <- </span>greater-or-equal count, max
<span class="muControl">break-if</span> done?
c:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
at-newline?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">10/newline</span>
<span class="muControl">break-if</span> at-newline?
curr<span class="Special"> <- </span>next-duplex curr
count<span class="Special"> <- </span>add count, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply-unless</span> curr, original
<span class="muControl">reply</span> curr
]
<span class="muScenario">scenario</span> editor-scrolls-down-past-wrapped-line-using-arrow-keys [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span>
<span class="Comment"># other lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef</span>
<span class="Constant">g</span>
<span class="Constant">h</span>
<span class="Constant">i]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd↩ .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .g .</span>
]
<span class="Comment"># position cursor at last line, then try to move further down</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .h .</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-down-past-wrapped-line-using-arrow-keys-2 [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor starts with a long line wrapping twice</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdefghij</span>
<span class="Constant">k</span>
<span class="Constant">l</span>
<span class="Constant">m]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at last line, then try to move further down</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line containing a wrap icon</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .efgh↩ .</span>
<span class="Constant"> .ij .</span>
<span class="Constant"> .k .</span>
]
<span class="Comment"># scroll down again</span>
assume-console [
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .ij .</span>
<span class="Constant"> .k .</span>
<span class="Constant"> .l .</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-down-when-line-wraps [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains a long line in the third line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">cdef]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at end, type a character</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">4</span>
type <span class="Constant">[g]</span>
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen scrolls</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .cdef↩.</span>
<span class="Constant"> .g .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-down-on-newline [
assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># position cursor after last line and type newline</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">4</span>
type [
]
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen scrolls</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> . .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-down-on-right-arrow [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains a wrapped line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">cdefgh]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at end of screen and try to move right</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">3</span>
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen scrolls</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .cdef↩.</span>
<span class="Constant"> .gh .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-down-on-right-arrow-2 [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains more lines than can fit on screen</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at end of screen and try to move right</span>
assume-console [
left-click <span class="Constant">3</span>, <span class="Constant">3</span>
press right-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen scrolls</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">3</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">0</span>
]
]
<span class="muScenario">scenario</span> editor-combines-page-and-line-scroll [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with a few pages of lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d</span>
<span class="Constant">e</span>
<span class="Constant">f</span>
<span class="Constant">g]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># scroll down one page and one line</span>
assume-console [
press page-down
left-click <span class="Constant">3</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen scrolls down 3 lines</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .e .</span>
<span class="Constant"> .f .</span>
]
]
<span class="Comment"># cursor-up can scroll if necessary</span>
<span class="muScenario">scenario</span> editor-can-scroll-up-using-arrow-keys [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with >3 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># position cursor at top of second page, then try to move up</span>
assume-console [
press page-down
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen slides by one line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><scroll-up></span> [
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[scroll up]</span>
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
*top-of-screen<span class="Special"> <- </span>before-previous-line *top-of-screen, editor
no-movement?:boolean<span class="Special"> <- </span>equal old-top, *top-of-screen
<span class="muControl">reply-if</span> no-movement?, editor/same-as-ingredient:<span class="Constant">0</span>, <span class="Constant">0/no-more-render</span>
]
<span class="Comment"># takes a pointer into the doubly-linked list, scans back to before start of</span>
<span class="Comment"># previous *wrapped* line</span>
<span class="Comment"># beware: never return null pointer</span>
<span class="muRecipe">recipe</span> before-previous-line [
<span class="Constant">local-scope</span>
curr:address:duplex-list<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
c:character<span class="Special"> <- </span>get *curr, <span class="Constant">value:offset</span>
<span class="Comment"># compute max, number of characters to skip</span>
<span class="Comment"># 1 + len%(width-1)</span>
<span class="Comment"># except rotate second term to vary from 1 to width-1 rather than 0 to width-2</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
left:number<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:number<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
max-line-length:number<span class="Special"> <- </span>subtract right, left, <span class="Constant">-1/exclusive-right</span>, <span class="Constant">1/wrap-icon</span>
sentinel:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">data:offset</span>
len:number<span class="Special"> <- </span>previous-line-length curr, sentinel
<span class="Delimiter">{</span>
<span class="muControl">break-if</span> len
<span class="Comment"># empty line; just skip this newline</span>
prev:address:duplex-list<span class="Special"> <- </span>prev-duplex curr
<span class="muControl">reply-unless</span> prev, curr
<span class="muControl">reply</span> prev
<span class="Delimiter">}</span>
_, max:number<span class="Special"> <- </span>divide-with-remainder len, max-line-length
<span class="Comment"># remainder 0 => scan one width-worth</span>
<span class="Delimiter">{</span>
<span class="muControl">break-if</span> max
max<span class="Special"> <- </span>copy max-line-length
<span class="Delimiter">}</span>
max<span class="Special"> <- </span>add max, <span class="Constant">1</span>
count:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
<span class="Comment"># skip 'max' characters</span>
<span class="Delimiter">{</span>
done?:boolean<span class="Special"> <- </span>greater-or-equal count, max
<span class="muControl">break-if</span> done?
prev:address:duplex-list<span class="Special"> <- </span>prev-duplex curr
<span class="muControl">break-unless</span> prev
curr<span class="Special"> <- </span>copy prev
count<span class="Special"> <- </span>add count, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply</span> curr
]
<span class="muScenario">scenario</span> editor-scrolls-up-past-wrapped-line-using-arrow-keys [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span>
<span class="Comment"># other lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef</span>
<span class="Constant">g</span>
<span class="Constant">h</span>
<span class="Constant">i]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd↩ .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .g .</span>
]
<span class="Comment"># position cursor at top of second page, just below wrapped line</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .h .</span>
<span class="Constant"> .i .</span>
]
<span class="Comment"># now move up one line</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .ef .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .h .</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-up-past-wrapped-line-using-arrow-keys-2 [
<span class="Comment"># screen has 1 line for menu + 4 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
<span class="Comment"># editor starts with a long line wrapping twice, occupying 3 of the 4 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdefghij</span>
<span class="Constant">k</span>
<span class="Constant">l</span>
<span class="Constant">m]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at top of second page</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .k .</span>
<span class="Constant"> .l .</span>
<span class="Constant"> .m .</span>
<span class="Constant"> .┈┈┈┈┈ .</span>
]
<span class="Comment"># move up one line</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .ij .</span>
<span class="Constant"> .k .</span>
<span class="Constant"> .l .</span>
<span class="Constant"> .m .</span>
]
<span class="Comment"># move up a second line</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .efgh↩ .</span>
<span class="Constant"> .ij .</span>
<span class="Constant"> .k .</span>
<span class="Constant"> .l .</span>
]
<span class="Comment"># move up a third line</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcd↩ .</span>
<span class="Constant"> .efgh↩ .</span>
<span class="Constant"> .ij .</span>
<span class="Constant"> .k .</span>
]
]
<span class="Comment"># same as editor-scrolls-up-past-wrapped-line-using-arrow-keys but length</span>
<span class="Comment"># slightly off, just to prevent over-training</span>
<span class="muScenario">scenario</span> editor-scrolls-up-past-wrapped-line-using-arrow-keys-3 [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with a long, wrapped line and more than a screen of</span>
<span class="Comment"># other lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[abcdef</span>
<span class="Constant">g</span>
<span class="Constant">h</span>
<span class="Constant">i]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">6/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .abcde↩ .</span>
<span class="Constant"> .f .</span>
<span class="Constant"> .g .</span>
]
<span class="Comment"># position cursor at top of second page, just below wrapped line</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .h .</span>
<span class="Constant"> .i .</span>
]
<span class="Comment"># now move up one line</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows partial wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .f .</span>
<span class="Constant"> .g .</span>
<span class="Constant"> .h .</span>
]
]
<span class="Comment"># check empty lines</span>
<span class="muScenario">scenario</span> editor-scrolls-up-past-wrapped-line-using-arrow-keys-4 [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with some lines around an empty line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
c
d
e]
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">6/right</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .e .</span>
<span class="Constant"> .┈┈┈┈┈┈ .</span>
]
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
]
<span class="muScenario">scenario</span> editor-scrolls-up-on-left-arrow [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">5/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains >3 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d</span>
<span class="Constant">e]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
<span class="Comment"># position cursor at top of second page</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .e .</span>
]
<span class="Comment"># now try to move left</span>
assume-console [
press left-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
<span class="Constant">3</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-row:offset</span>
<span class="Constant">4</span>:number<span class="Special"> <- </span>get *<span class="Constant">2</span>:address:editor-data, <span class="Constant">cursor-column:offset</span>
]
<span class="Comment"># screen scrolls</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
]
memory-should-contain [
<span class="Constant">3</span><span class="Special"> <- </span><span class="Constant">1</span>
<span class="Constant">4</span><span class="Special"> <- </span><span class="Constant">1</span>
]
]
<span class="muScenario">scenario</span> editor-can-scroll-up-to-start-of-file [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with >3 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># position cursor at top of second page, then try to move up to start of</span>
<span class="Comment"># text</span>
assume-console [
press page-down
press up-arrow
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen slides by one line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># try to move up again</span>
assume-console [
press up-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen remains unchanged</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
]
<span class="Comment"># ctrl-f/page-down - render next page if it exists</span>
<span class="muScenario">scenario</span> editor-can-scroll [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows next page</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
page-down?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">6/ctrl-f</span>
<span class="muControl">break-unless</span> page-down?
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
<span class="Constant"> <move-cursor-begin></span>
page-down editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
no-movement?:boolean<span class="Special"> <- </span>equal *top-of-screen, old-top
<span class="muControl">reply-if</span> no-movement?, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
page-down?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65518/page-down</span>
<span class="muControl">break-unless</span> page-down?
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
<span class="Constant"> <move-cursor-begin></span>
page-down editor
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
no-movement?:boolean<span class="Special"> <- </span>equal *top-of-screen, old-top
<span class="muControl">reply-if</span> no-movement?, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="Comment"># page-down skips entire wrapped lines, so it can't scroll past lines</span>
<span class="Comment"># taking up the entire screen</span>
<span class="muRecipe">recipe</span> page-down [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
<span class="Comment"># if editor contents don't overflow screen, do nothing</span>
bottom-of-screen:address:duplex-list<span class="Special"> <- </span>get *editor, <span class="Constant">bottom-of-screen:offset</span>
<span class="muControl">reply-unless</span> bottom-of-screen, editor/same-as-ingredient:<span class="Constant">0</span>
<span class="Comment"># if not, position cursor at final character</span>
before-cursor:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
*before-cursor<span class="Special"> <- </span>prev-duplex bottom-of-screen
<span class="Comment"># keep one line in common with previous page</span>
<span class="Delimiter">{</span>
last:character<span class="Special"> <- </span>get **before-cursor, <span class="Constant">value:offset</span>
newline?:boolean<span class="Special"> <- </span>equal last, <span class="Constant">10/newline</span>
<span class="muControl">break-unless</span> newline?:boolean
*before-cursor<span class="Special"> <- </span>prev-duplex *before-cursor
<span class="Delimiter">}</span>
<span class="Comment"># move cursor and top-of-screen to start of that line</span>
move-to-start-of-line editor
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
*top-of-screen<span class="Special"> <- </span>copy *before-cursor
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>
]
<span class="muScenario">scenario</span> editor-does-not-scroll-past-end [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
editor-render screen, <span class="Constant">2</span>:address:editor-data
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen remains unmodified</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
]
<span class="muScenario">scenario</span> editor-starts-next-page-at-start-of-wrapped-line [
<span class="Comment"># screen has 1 line for menu + 3 lines for text</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains a long last line</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">cdefgh]</span>
<span class="Comment"># editor screen triggers wrap of last line</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
<span class="Comment"># some part of last line is not displayed</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .cde↩ .</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows entire wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .cde↩ .</span>
<span class="Constant"> .fgh .</span>
<span class="Constant"> .┈┈┈┈ .</span>
]
]
<span class="muScenario">scenario</span> editor-starts-next-page-at-start-of-wrapped-line-2 [
<span class="Comment"># screen has 1 line for menu + 3 lines for text</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains a very long line that occupies last two lines of screen</span>
<span class="Comment"># and still has something left over</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">bcdefgh]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
<span class="Comment"># some part of last line is not displayed</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .bcd↩ .</span>
<span class="Constant"> .efg↩ .</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows entire wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .bcd↩ .</span>
<span class="Constant"> .efg↩ .</span>
<span class="Constant"> .h .</span>
]
]
<span class="Comment"># ctrl-b/page-up - render previous page if it exists</span>
<span class="muScenario">scenario</span> editor-can-scroll-up [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows next page</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .┈┈┈┈┈┈┈┈┈┈.</span>
]
<span class="Comment"># scroll back up</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows original page again</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-character></span> [
<span class="Delimiter">{</span>
page-up?:boolean<span class="Special"> <- </span>equal *c, <span class="Constant">2/ctrl-b</span>
<span class="muControl">break-unless</span> page-up?
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
<span class="Constant"> <move-cursor-begin></span>
editor<span class="Special"> <- </span>page-up editor, screen-height
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
no-movement?:boolean<span class="Special"> <- </span>equal *top-of-screen, old-top
<span class="muControl">reply-if</span> no-movement?, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">after</span> <span class="Constant"><handle-special-key></span> [
<span class="Delimiter">{</span>
page-up?:boolean<span class="Special"> <- </span>equal *k, <span class="Constant">65519/page-up</span>
<span class="muControl">break-unless</span> page-up?
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
old-top:address:duplex-list<span class="Special"> <- </span>copy *top-of-screen
<span class="Constant"> <move-cursor-begin></span>
editor<span class="Special"> <- </span>page-up editor, screen-height
undo-coalesce-tag:number<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
no-movement?:boolean<span class="Special"> <- </span>equal *top-of-screen, old-top
<span class="Comment"># don't bother re-rendering if nothing changed. todo: test this</span>
<span class="muControl">reply-if</span> no-movement?, screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">0/no-more-render</span>
<span class="muControl">reply</span> screen/same-as-ingredient:<span class="Constant">0</span>, editor/same-as-ingredient:<span class="Constant">1</span>, <span class="Constant">1/go-render</span>
<span class="Delimiter">}</span>
]
<span class="muRecipe">recipe</span> page-up [
<span class="Constant">local-scope</span>
editor:address:editor-data<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
screen-height:number<span class="Special"> <- </span><span class="Constant">next-ingredient</span>
max:number<span class="Special"> <- </span>subtract screen-height, <span class="Constant">1/menu-bar</span>, <span class="Constant">1/overlapping-line</span>
count:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
top-of-screen:address:address:duplex-list<span class="Special"> <- </span>get-address *editor, <span class="Constant">top-of-screen:offset</span>
<span class="Delimiter">{</span>
done?:boolean<span class="Special"> <- </span>greater-or-equal count, max
<span class="muControl">break-if</span> done?
prev:address:duplex-list<span class="Special"> <- </span>before-previous-line *top-of-screen, editor
<span class="muControl">break-unless</span> prev
*top-of-screen<span class="Special"> <- </span>copy prev
count<span class="Special"> <- </span>add count, <span class="Constant">1</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
<span class="muControl">reply</span> editor/same-as-ingredient:<span class="Constant">0</span>
]
<span class="muScenario">scenario</span> editor-can-scroll-up-multiple-pages [
<span class="Comment"># screen has 1 line for menu + 3 lines</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># initialize editor with 8 lines</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">c</span>
<span class="Constant">d</span>
<span class="Constant">e</span>
<span class="Constant">f</span>
<span class="Constant">g</span>
<span class="Constant">h]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
<span class="Comment"># scroll down two pages</span>
assume-console [
press page-down
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows third page</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .e .</span>
<span class="Constant"> .f .</span>
<span class="Constant"> .g .</span>
]
<span class="Comment"># scroll up</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows second page</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .c .</span>
<span class="Constant"> .d .</span>
<span class="Constant"> .e .</span>
]
<span class="Comment"># scroll up again</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows original page again</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .c .</span>
]
]
<span class="muScenario">scenario</span> editor-can-scroll-up-wrapped-lines [
<span class="Comment"># screen has 1 line for menu + 5 lines for text</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">6/height</span>
<span class="Comment"># editor contains a long line in the first page</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">b</span>
<span class="Constant">cdefgh</span>
<span class="Constant">i</span>
<span class="Constant">j</span>
<span class="Constant">k</span>
<span class="Constant">l</span>
<span class="Constant">m</span>
<span class="Constant">n</span>
<span class="Constant">o]</span>
<span class="Comment"># editor screen triggers wrap of last line</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
<span class="Comment"># some part of last line is not displayed</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .cde↩ .</span>
<span class="Constant"> .fgh .</span>
<span class="Constant"> .i .</span>
]
<span class="Comment"># scroll down a page and a line</span>
assume-console [
press page-down
left-click <span class="Constant">5</span>, <span class="Constant">0</span>
press down-arrow
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows entire wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .j .</span>
<span class="Constant"> .k .</span>
<span class="Constant"> .l .</span>
<span class="Constant"> .m .</span>
<span class="Constant"> .n .</span>
]
<span class="Comment"># now scroll up one page</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen resets</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .b .</span>
<span class="Constant"> .cde↩ .</span>
<span class="Constant"> .fgh .</span>
<span class="Constant"> .i .</span>
<span class="Constant"> .j .</span>
]
]
<span class="muScenario">scenario</span> editor-can-scroll-up-wrapped-lines-2 [
<span class="Comment"># screen has 1 line for menu + 3 lines for text</span>
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># editor contains a very long line that occupies last two lines of screen</span>
<span class="Comment"># and still has something left over</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[a</span>
<span class="Constant">bcdefgh]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
<span class="Comment"># some part of last line is not displayed</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .bcd↩ .</span>
<span class="Constant"> .efg↩ .</span>
]
<span class="Comment"># scroll down</span>
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen shows entire wrapped line</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .bcd↩ .</span>
<span class="Constant"> .efg↩ .</span>
<span class="Constant"> .h .</span>
]
<span class="Comment"># scroll back up</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
<span class="Comment"># screen resets</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .a .</span>
<span class="Constant"> .bcd↩ .</span>
<span class="Constant"> .efg↩ .</span>
]
]
<span class="muScenario">scenario</span> editor-can-scroll-up-past-nonempty-lines [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># text with empty line in second screen</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[axx</span>
<span class="Constant">bxx</span>
<span class="Constant">cxx</span>
<span class="Constant">dxx</span>
<span class="Constant">exx</span>
<span class="Constant">fxx</span>
<span class="Constant">gxx</span>
<span class="Constant">hxx</span>
<span class="Constant">]</span>
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .axx .</span>
<span class="Constant"> .bxx .</span>
<span class="Constant"> .cxx .</span>
]
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .cxx .</span>
<span class="Constant"> .dxx .</span>
<span class="Constant"> .exx .</span>
]
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .exx .</span>
<span class="Constant"> .fxx .</span>
<span class="Constant"> .gxx .</span>
]
<span class="Comment"># scroll back up past empty line</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .cxx .</span>
<span class="Constant"> .dxx .</span>
<span class="Constant"> .exx .</span>
]
]
<span class="muScenario">scenario</span> editor-can-scroll-up-past-empty-lines [
assume-screen <span class="Constant">10/width</span>, <span class="Constant">4/height</span>
<span class="Comment"># text with empty line in second screen</span>
<span class="Constant">1</span>:address:array:character<span class="Special"> <- </span>new <span class="Constant">[axy</span>
<span class="Constant">bxy</span>
<span class="Constant">cxy</span>
dxy
exy
fxy
gxy
]
<span class="Constant">2</span>:address:editor-data<span class="Special"> <- </span>new-editor <span class="Constant">1</span>:address:array:character, screen:address, <span class="Constant">0/left</span>, <span class="Constant">4/right</span>
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .axy .</span>
<span class="Constant"> .bxy .</span>
<span class="Constant"> .cxy .</span>
]
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .cxy .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .dxy .</span>
]
assume-console [
press page-down
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .dxy .</span>
<span class="Constant"> .exy .</span>
<span class="Constant"> .fxy .</span>
]
<span class="Comment"># scroll back up past empty line</span>
assume-console [
press page-up
]
run [
editor-event-loop screen:address, console:address, <span class="Constant">2</span>:address:editor-data
]
screen-should-contain [
<span class="Constant"> . .</span>
<span class="Constant"> .cxy .</span>
<span class="Constant"> . .</span>
<span class="Constant"> .dxy .</span>
]
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->