about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-10 11:29:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-10 11:29:01 -0700
commitfcacb6e63d1aefd7aedc858e6efa39d8102eb6ba (patch)
tree804074d13f166aca1fa6b4163074e50613a008c7 /text.lua
parent31418976d4da1c72ddb17f24dde22db154962554 (diff)
downloadtext.love-fcacb6e63d1aefd7aedc858e6efa39d8102eb6ba.tar.gz
extract scrolling logic out of insert_at_cursor
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua18
1 files changed, 12 insertions, 6 deletions
diff --git a/text.lua b/text.lua
index e7fe598..464e26c 100644
--- a/text.lua
+++ b/text.lua
@@ -144,12 +144,17 @@ function Text.textinput(t)
     Text.delete_selection()
   end
   local before = snapshot(Cursor1.line)
+--?   print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
   Text.insert_at_cursor(t)
+  if Cursor_y >= App.screen.height - Line_height then
+    Text.populate_screen_line_starting_pos(Cursor1.line)
+    Text.snap_cursor_to_bottom_of_screen()
+--?     print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
+  end
   record_undo_event({before=before, after=snapshot(Cursor1.line)})
 end
 
 function Text.insert_at_cursor(t)
---?   print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
   local byte_offset
   if Cursor1.pos > 1 then
     byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)
@@ -164,11 +169,6 @@ function Text.insert_at_cursor(t)
   Lines[Cursor1.line].fragments = nil
   Lines[Cursor1.line].screen_line_starting_pos = nil
   Cursor1.pos = Cursor1.pos+1
-  if Cursor_y >= App.screen.height - Line_height then
-    Text.populate_screen_line_starting_pos(Cursor1.line)
-    Text.snap_cursor_to_bottom_of_screen()
---?     print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
-  end
 end
 
 -- Don't handle any keys here that would trigger love.textinput above.
@@ -186,7 +186,13 @@ function Text.keychord_pressed(chord)
     record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)})
   elseif chord == 'tab' then
     local before = snapshot(Cursor1.line)
+--?     print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
     Text.insert_at_cursor('\t')
+    if Cursor_y >= App.screen.height - Line_height then
+      Text.populate_screen_line_starting_pos(Cursor1.line)
+      Text.snap_cursor_to_bottom_of_screen()
+--?       print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
+    end
     save_to_disk(Lines, Filename)
     record_undo_event({before=before, after=snapshot(Cursor1.line)})
   elseif chord == 'backspace' then
c60995cc0ae'>^
e1c5a42 ^

72791d9 ^
da3f6c6 ^
e1c5a42 ^

cfdd563 ^
faee5f9 ^
e1c5a42 ^

faee5f9 ^
712dc95 ^
e1c5a42 ^







e1c5a42 ^

5ab541f ^
e1c5a42 ^






73fefa7 ^
e1c5a42 ^



5ab541f ^

712dc95 ^
da3f6c6 ^

e1c5a42 ^







da3f6c6 ^
e1c5a42 ^
0e0f36f ^


da3f6c6 ^
51eb86c ^
e1c5a42 ^
0719fde ^




e1c5a42 ^






4c0095e ^

e1c5a42 ^







0e0f36f ^
33ea91f ^

f421e1d ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^


e1c5a42 ^



0e0f36f ^
e1c5a42 ^







8f06b74 ^

f421e1d ^
e1c5a42 ^






51eb86c ^

f421e1d ^
0e0f36f ^
a5f725a ^
0e0f36f ^
fe8e4fd ^
a5f725a ^
e1c5a42 ^







eaa3820 ^

2b3e09c ^
e1c5a42 ^
0e0f36f ^
e1c5a42 ^


























2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^

94b6d04 ^


f421e1d ^
e1c5a42 ^
0e0f36f ^
94b6d04 ^

e1c5a42 ^

2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^


bb9e23a ^

f351ee2 ^
e1c5a42 ^
0e0f36f ^
94b6d04 ^

e1c5a42 ^

f351ee2 ^
e1c5a42 ^
f351ee2 ^
e1c5a42 ^


ccf7ecc ^

e1c5a42 ^


7ef551b ^
e1c5a42 ^
7ef551b ^
e1c5a42 ^






2b3e09c ^
e1c5a42 ^
2b3e09c ^
e1c5a42 ^

94b6d04 ^
4aa2003 ^
ce31b74 ^
99faf61 ^









e1c5a42 ^















ce31b74 ^
ce31b74 ^
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280