about summary refs log tree commit diff stats
path: root/edit.mu
diff options
context:
space:
mode:
Diffstat (limited to 'edit.mu')
-rw-r--r--edit.mu65
1 files changed, 49 insertions, 16 deletions
diff --git a/edit.mu b/edit.mu
index c210f4a1..a9c87114 100644
--- a/edit.mu
+++ b/edit.mu
@@ -2671,13 +2671,20 @@ recipe move-to-next-line [
   last-line:number <- subtract screen-height, 1
   already-at-bottom?:boolean <- greater-or-equal *cursor-row, last-line
   {
-    # if cursor not at top, move it
+    # if cursor not at bottom, move it
     break-if already-at-bottom?
     # scan to start of next line, then to right column or until end of line
     max:number <- subtract right, left
     next-line:address:duplex-list <- before-start-of-next-line *before-cursor, max
-    no-motion?:boolean <- equal next-line, *before-cursor
-    reply-if no-motion?, editor/same-as-ingredient:0, 0/no-more-render
+    {
+      # already at end of buffer? try to scroll up (so we can see more
+      # warnings or sandboxes below)
+      no-motion?:boolean <- equal next-line, *before-cursor
+      break-unless no-motion?
+      scroll?:boolean <- greater-than *cursor-row, 1
+      break-if scroll?, +try-to-scroll:label
+      reply editor/same-as-ingredient:0, 0/no-more-render
+    }
     *cursor-row <- add *cursor-row, 1
     *before-cursor <- copy next-line
     target-column:number <- copy *cursor-column
@@ -2697,12 +2704,9 @@ recipe move-to-next-line [
     }
     reply editor/same-as-ingredient:0, 0/no-more-render
   }
-  {
-    # if cursor already at top, scroll up
-    break-unless already-at-bottom?
-    +scroll-down
-    reply editor/same-as-ingredient:0, 1/go-render
-  }
+  +try-to-scroll
+  +scroll-down
+  reply editor/same-as-ingredient:0, 1/go-render
 ]
 
 scenario editor-adjusts-column-at-next-line [
@@ -2741,13 +2745,14 @@ de]
   ]
 ]
 
-scenario editor-stops-at-end-on-down-arrow [
+scenario editor-scrolls-at-end-on-down-arrow [
   assume-screen 10/width, 5/height
   1:address:array:character <- new [abc
 de]
   2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right
   editor-render screen, 2:address:editor-data
   $clear-trace
+  # try to move down past end of text
   assume-console [
     left-click 2, 0
     press down-arrow
@@ -2757,11 +2762,11 @@ de]
     3:number <- get *2:address:editor-data, cursor-row:offset
     4:number <- get *2:address:editor-data, cursor-column:offset
   ]
+  # screen should scroll, moving cursor to end of text
   memory-should-contain [
-    3 <- 2
-    4 <- 0
+    3 <- 1
+    4 <- 2
   ]
-  check-trace-count-for-label 0, [print-character]
   assume-console [
     type [0]
   ]
@@ -2770,8 +2775,36 @@ de]
   ]
   screen-should-contain [
     .          .
-    .abc       .
-    .0de       .
+    .de0       .
+    .┈┈┈┈┈┈┈┈┈┈.
+    .          .
+  ]
+  # try to move down again
+  $clear-trace
+  assume-console [
+    left-click 2, 0
+    press down-arrow
+  ]
+  run [
+    editor-event-loop screen:address, console:address, 2:address:editor-data
+    3:number <- get *2:address:editor-data, cursor-row:offset
+    4:number <- get *2:address:editor-data, cursor-column:offset
+  ]
+  # screen stops scrolling because cursor is already at top
+  memory-should-contain [
+    3 <- 1
+    4 <- 3
+  ]
+  check-trace-count-for-label 0, [print-character]
+  assume-console [
+    type [1]
+  ]
+  run [
+    editor-event-loop screen:address, console:address, 2:address:editor-data
+  ]
+  screen-should-contain [
+    .          .
+    .de01      .
     .┈┈┈┈┈┈┈┈┈┈.
     .          .
   ]
@@ -3440,7 +3473,7 @@ after +scroll-down [
   *top-of-screen <- before-start-of-next-line *top-of-screen, max
   no-movement?:boolean <- equal old-top, *top-of-screen
   # Hack: this reply doesn't match one of the locations of +scroll-down, directly
-  # within insert-at-cursor. however, I'm unable to trigger the error..
+  # within insert-at-cursor. However, I'm unable to trigger the error..
   # If necessary create a duplicate copy of +scroll-down with the right
   # 'reply-if'.
   reply-if no-movement?, editor/same-as-ingredient:0, 0/no-more-render
nti/profani-tty/commit/tests/test_cmd_statuses.c?id=79e9ab83b02ca8bd1c4ad77b59eb536fa7f081a8'>79e9ab83 ^
79e9ab83 ^
79e9ab83 ^





79e9ab83 ^




79e9ab83 ^




79e9ab83 ^
79e9ab83 ^





79e9ab83 ^




79e9ab83 ^




79e9ab83 ^
79e9ab83 ^





79e9ab83 ^




79e9ab83 ^




79e9ab83 ^
79e9ab83 ^





79e9ab83 ^


2af418fd ^
79e9ab83 ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
79e9ab83 ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^

79e9ab83 ^


2af418fd ^
79e9ab83 ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
79e9ab83 ^
79e9ab83 ^
2af418fd ^









2af418fd ^









79e9ab83 ^

79e9ab83 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223