about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-18 10:22:48 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-18 10:32:03 -0700
commit1d3c9f47085ee5d9cfa37d988d53f2dfead0195a (patch)
tree2b95e57cdd9ea18ec748fea7dc9458723fcec3b1
parentcf8d9774eac577b4cd4fdb77cbb27b6b46004756 (diff)
downloadview.love-1d3c9f47085ee5d9cfa37d988d53f2dfead0195a.tar.gz
generalize a function
-rw-r--r--search.lua4
-rw-r--r--select.lua2
-rw-r--r--text.lua19
3 files changed, 13 insertions, 12 deletions
diff --git a/search.lua b/search.lua
index 01a832b..bd28d58 100644
--- a/search.lua
+++ b/search.lua
@@ -62,7 +62,7 @@ function Text.search_next(State)
   end
   if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
     State.screen_top1.line = State.cursor1.line
-    local pos = Text.pos_at_start_of_cursor_screen_line(State)
+    local pos = Text.pos_at_start_of_screen_line(State, State.cursor1)
     State.screen_top1.pos = pos
   end
 end
@@ -110,7 +110,7 @@ function Text.search_previous(State)
   end
   if Text.lt1(State.cursor1, State.screen_top1) or Text.lt1(State.screen_bottom1, State.cursor1) then
     State.screen_top1.line = State.cursor1.line
-    local pos = Text.pos_at_start_of_cursor_screen_line(State)
+    local pos = Text.pos_at_start_of_screen_line(State, State.cursor1)
     State.screen_top1.pos = pos
   end
 end
diff --git a/select.lua b/select.lua
index c5794e1..bae9504 100644
--- a/select.lua
+++ b/select.lua
@@ -130,7 +130,7 @@ function Text.delete_selection_without_undo(State)
   State.cursor1.pos = minp
   if Text.lt1(State.cursor1, State.screen_top1) then
     State.screen_top1.line = State.cursor1.line
-    State.screen_top1.pos = Text.pos_at_start_of_cursor_screen_line(State)
+    State.screen_top1.pos = Text.pos_at_start_of_screen_line(State, State.cursor1)
   end
   State.selection1 = {}
   -- delete everything between min (inclusive) and max (exclusive)
diff --git a/text.lua b/text.lua
index ff98140..9c4a009 100644
--- a/text.lua
+++ b/text.lua
@@ -426,7 +426,7 @@ end
 function Text.up(State)
   assert(State.lines[State.cursor1.line].mode == 'text')
 --?   print('up', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
-  local screen_line_starting_pos, screen_line_index = Text.pos_at_start_of_cursor_screen_line(State)
+  local screen_line_starting_pos, screen_line_index = Text.pos_at_start_of_screen_line(State, State.cursor1)
   if screen_line_starting_pos == 1 then
 --?     print('cursor is at first screen line of its line')
     -- line is done; skip to previous text line
@@ -500,7 +500,7 @@ function Text.down(State)
     -- move down one screen line in current line
     local scroll_down = Text.le1(State.screen_bottom1, State.cursor1)
 --?     print('cursor is NOT at final screen line of its line')
-    local screen_line_starting_pos, screen_line_index = Text.pos_at_start_of_cursor_screen_line(State)
+    local screen_line_starting_pos, screen_line_index = Text.pos_at_start_of_screen_line(State, State.cursor1)
     new_screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos[screen_line_index+1]
 --?     print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
     local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)
@@ -525,7 +525,7 @@ end
 
 function Text.end_of_line(State)
   State.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1
-  local botpos = Text.pos_at_start_of_cursor_screen_line(State)
+  local botpos = Text.pos_at_start_of_screen_line(State, State.cursor1)
   local botline1 = {line=State.cursor1.line, pos=botpos}
   if Text.cursor_out_of_screen(State) then
     Text.snap_cursor_to_bottom_of_screen(State)
@@ -636,11 +636,12 @@ function Text.right_without_scroll(State)
   end
 end
 
-function Text.pos_at_start_of_cursor_screen_line(State)
-  Text.populate_screen_line_starting_pos(State, State.cursor1.line)
-  for i=#State.line_cache[State.cursor1.line].screen_line_starting_pos,1,-1 do
-    local spos = State.line_cache[State.cursor1.line].screen_line_starting_pos[i]
-    if spos <= State.cursor1.pos then
+function Text.pos_at_start_of_screen_line(State, loc1)
+  Text.populate_screen_line_starting_pos(State, loc1.line)
+  local line_cache = State.line_cache[loc1.line]
+  for i=#line_cache.screen_line_starting_pos,1,-1 do
+    local spos = line_cache.screen_line_starting_pos[i]
+    if spos <= loc1.pos then
       return spos,i
     end
   end
@@ -984,7 +985,7 @@ function Text.cursor_out_of_screen(State)
   return State.cursor_y == nil
   -- this approach is cheaper and almost works, except on the final screen
   -- where file ends above bottom of screen
---?   local botpos = Text.pos_at_start_of_cursor_screen_line(State)
+--?   local botpos = Text.pos_at_start_of_screen_line(State, State.cursor1)
 --?   local botline1 = {line=State.cursor1.line, pos=botpos}
 --?   return Text.lt1(State.screen_bottom1, botline1)
 end
file: added `make test' back in.' href='/akspecs/ranger/commit/Makefile?id=5fca2a0b63bb565ab4faba135dc1d201c3b05725'>5fca2a0b ^
b0a216f5 ^
2c5ea01d ^
b0a216f5 ^



3a1e1f28 ^
b0a216f5 ^
e7758eba ^
b0a216f5 ^

a0077554 ^













88b4d374 ^

a0077554 ^

2c5ea01d ^
582f3519 ^
b06433bc ^
a65a2695 ^

582f3519 ^
94c5d83e ^
dee6cfa6 ^
e9e4b4ff ^
b0a216f5 ^
76612b05 ^
ececd03e ^
b0a216f5 ^
e9e4b4ff ^





612b8b8b ^
e9e4b4ff ^
52403c53 ^
ad51cca4 ^
08e43b29 ^


ad51cca4 ^






b3d031a9 ^
c5f776ed ^
9ed36720 ^
b3d031a9 ^
bc2c5619 ^
c5f776ed ^

9ed36720 ^
b3d031a9 ^
9c69b4ae ^
c5f776ed ^

9ed36720 ^
9d82571b ^

5fca2a0b ^
9cf43c17 ^
5fca2a0b ^
9c69b4ae ^
c5f776ed ^

9ed36720 ^
c5f776ed ^
9c69b4ae ^
c5f776ed ^
88b4d374 ^
9ed36720 ^
9c69b4ae ^
88b4d374 ^
e91ae587 ^
9ed36720 ^
46c378fd ^

9c69b4ae ^
e91ae587 ^
f2c8a7ff ^
9ed36720 ^
f2c8a7ff ^
9c69b4ae ^
f2c8a7ff ^
e416bfe7 ^
9ed36720 ^
5fca2a0b ^
164c44c5 ^
0ca79709 ^




164c44c5 ^
0ca79709 ^





c7720fff ^
8d21b83c ^


e9e4b4ff ^
ececd03e ^
e9e4b4ff ^
0c2c782d ^
636d9393 ^
b0a216f5 ^
c6afc196 ^

c0d63e78 ^


ececd03e ^
f2c8a7ff ^

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