stop handling nil screen_line_starting_pos everywhere
Things seem to be working..
This commit is contained in:
parent
e7787b979f
commit
391d764e13
1
main.lua
1
main.lua
|
@ -441,7 +441,6 @@ function App.keychord_pressed(chord)
|
||||||
end
|
end
|
||||||
App.draw()
|
App.draw()
|
||||||
if Cursor_y >= App.screen.height - Line_height then
|
if Cursor_y >= App.screen.height - Line_height then
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
end
|
end
|
||||||
save_to_disk(Lines, Filename)
|
save_to_disk(Lines, Filename)
|
||||||
|
|
29
text.lua
29
text.lua
|
@ -22,9 +22,7 @@ function Text.draw(line, line_width, line_index)
|
||||||
if line.fragments == nil then
|
if line.fragments == nil then
|
||||||
Text.compute_fragments(line, line_width)
|
Text.compute_fragments(line, line_width)
|
||||||
end
|
end
|
||||||
if line.screen_line_starting_pos == nil then
|
Text.populate_screen_line_starting_pos(line_index)
|
||||||
Text.populate_screen_line_starting_pos(line_index)
|
|
||||||
end
|
|
||||||
--? print('--')
|
--? print('--')
|
||||||
for _, f in ipairs(line.fragments) do
|
for _, f in ipairs(line.fragments) do
|
||||||
local frag, frag_text = f.data, f.text
|
local frag, frag_text = f.data, f.text
|
||||||
|
@ -450,10 +448,6 @@ function Text.up()
|
||||||
--? print('found previous text line')
|
--? print('found previous text line')
|
||||||
Cursor1.line = new_cursor_line
|
Cursor1.line = new_cursor_line
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Cursor1.line)
|
||||||
if Lines[Cursor1.line].screen_line_starting_pos == nil then
|
|
||||||
Cursor1.pos = Text.nearest_cursor_pos(Lines[Cursor1.line].data, Cursor_x)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- previous text line found, pick its final screen line
|
-- previous text line found, pick its final screen line
|
||||||
--? print('has multiple screen lines')
|
--? print('has multiple screen lines')
|
||||||
local screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos
|
local screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos
|
||||||
|
@ -598,9 +592,7 @@ function Text.right()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.pos_at_start_of_cursor_screen_line()
|
function Text.pos_at_start_of_cursor_screen_line()
|
||||||
if Lines[Cursor1.line].screen_line_starting_pos == nil then
|
Text.populate_screen_line_starting_pos(Cursor1.line)
|
||||||
return 1,1
|
|
||||||
end
|
|
||||||
for i=#Lines[Cursor1.line].screen_line_starting_pos,1,-1 do
|
for i=#Lines[Cursor1.line].screen_line_starting_pos,1,-1 do
|
||||||
local spos = Lines[Cursor1.line].screen_line_starting_pos[i]
|
local spos = Lines[Cursor1.line].screen_line_starting_pos[i]
|
||||||
if spos <= Cursor1.pos then
|
if spos <= Cursor1.pos then
|
||||||
|
@ -611,9 +603,7 @@ function Text.pos_at_start_of_cursor_screen_line()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.cursor_at_final_screen_line()
|
function Text.cursor_at_final_screen_line()
|
||||||
if Lines[Cursor1.line].screen_line_starting_pos == nil then
|
Text.populate_screen_line_starting_pos(Cursor1.line)
|
||||||
return true
|
|
||||||
end
|
|
||||||
local screen_lines = Lines[Cursor1.line].screen_line_starting_pos
|
local screen_lines = Lines[Cursor1.line].screen_line_starting_pos
|
||||||
--? print(screen_lines[#screen_lines], Cursor1.pos)
|
--? print(screen_lines[#screen_lines], Cursor1.pos)
|
||||||
return screen_lines[#screen_lines] <= Cursor1.pos
|
return screen_lines[#screen_lines] <= Cursor1.pos
|
||||||
|
@ -680,15 +670,12 @@ function Text.in_line(line, x,y)
|
||||||
if line.y == nil then return false end -- outside current page
|
if line.y == nil then return false end -- outside current page
|
||||||
if x < 25 then return false end
|
if x < 25 then return false end
|
||||||
if y < line.y then return false end
|
if y < line.y then return false end
|
||||||
if line.screen_line_starting_pos == nil then return y < line.y + Line_height end
|
Text.populate_screen_line_starting_pos(Cursor1.line)
|
||||||
return y < line.y + #line.screen_line_starting_pos * Line_height
|
return y < line.y + #line.screen_line_starting_pos * Line_height
|
||||||
end
|
end
|
||||||
|
|
||||||
-- convert mx,my in pixels to schema-1 coordinates
|
-- convert mx,my in pixels to schema-1 coordinates
|
||||||
function Text.to_pos_on_line(line, mx, my)
|
function Text.to_pos_on_line(line, mx, my)
|
||||||
if line.screen_line_starting_pos == nil then
|
|
||||||
return Text.nearest_cursor_pos(line.data, mx)
|
|
||||||
end
|
|
||||||
if line.fragments == nil then
|
if line.fragments == nil then
|
||||||
Text.compute_fragments(line, Line_width)
|
Text.compute_fragments(line, Line_width)
|
||||||
end
|
end
|
||||||
|
@ -809,9 +796,7 @@ function Text.to2(pos1)
|
||||||
return {line=pos1.line, screen_line=1, screen_pos=1}
|
return {line=pos1.line, screen_line=1, screen_pos=1}
|
||||||
end
|
end
|
||||||
local result = {line=pos1.line, screen_line=1}
|
local result = {line=pos1.line, screen_line=1}
|
||||||
if Lines[pos1.line].screen_line_starting_pos == nil then
|
Text.populate_screen_line_starting_pos(pos1.line)
|
||||||
Text.populate_screen_line_starting_pos(pos1.line)
|
|
||||||
end
|
|
||||||
for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do
|
for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do
|
||||||
local spos = Lines[pos1.line].screen_line_starting_pos[i]
|
local spos = Lines[pos1.line].screen_line_starting_pos[i]
|
||||||
if spos <= pos1.pos then
|
if spos <= pos1.pos then
|
||||||
|
@ -865,9 +850,7 @@ function Text.previous_screen_line(pos2)
|
||||||
return {line=pos2.line-1, screen_line=1, screen_pos=1}
|
return {line=pos2.line-1, screen_line=1, screen_pos=1}
|
||||||
else
|
else
|
||||||
local l = Lines[pos2.line-1]
|
local l = Lines[pos2.line-1]
|
||||||
if l.screen_line_starting_pos == nil then
|
Text.populate_screen_line_starting_pos(pos2.line-1)
|
||||||
Text.populate_screen_line_starting_pos(pos2.line-1)
|
|
||||||
end
|
|
||||||
return {line=pos2.line-1, screen_line=#Lines[pos2.line-1].screen_line_starting_pos, screen_pos=1}
|
return {line=pos2.line-1, screen_line=#Lines[pos2.line-1].screen_line_starting_pos, screen_pos=1}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue