Merge lines.love

This commit is contained in:
Kartik K. Agaram 2023-04-02 09:22:32 -07:00
commit 3547c18db6
18 changed files with 117 additions and 251 deletions

16
app.lua
View File

@ -137,7 +137,7 @@ function App.run_tests_and_initialize()
Test_errors = {} Test_errors = {}
App.run_tests() App.run_tests()
if #Test_errors > 0 then if #Test_errors > 0 then
error('There were test failures:\n\n'..table.concat(Test_errors)) error(('There were %d test failures:\n\n%s'):format(#Test_errors, table.concat(Test_errors)))
end end
App.disable_tests() App.disable_tests()
App.initialize_globals() App.initialize_globals()
@ -210,16 +210,8 @@ function App.wait_fake_time(t)
App.time = App.time + t App.time = App.time + t
end end
-- LÖVE's Text primitive retains no trace of the string it was created from,
-- so we'll wrap it for our tests.
--
-- This implies that we need to hook any operations we need on Text objects.
function App.newText(font, s)
return {type='text', data=s, text=love.graphics.newText(font, s)}
end
function App.width(text) function App.width(text)
return text.text:getWidth() return love.graphics.getFont():getWidth(text)
end end
function App.screen.draw(obj, x,y) function App.screen.draw(obj, x,y)
@ -381,7 +373,7 @@ end
-- prepend file/line/test -- prepend file/line/test
function prepend_debug_info_to_test_failure(test_name, err) function prepend_debug_info_to_test_failure(test_name, err)
local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '') local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
local stack_trace = debug.traceback('', --[[stack frame]]4) local stack_trace = debug.traceback('', --[[stack frame]]5)
local file_and_line_number = stack_trace:gsub('stack traceback:\n', ''):gsub(': .*', '') local file_and_line_number = stack_trace:gsub('stack traceback:\n', ''):gsub(': .*', '')
local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number
--? local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number..'\t\t'..stack_trace:gsub('\n', '\n\t\t') --? local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number..'\t\t'..stack_trace:gsub('\n', '\n\t\t')
@ -423,9 +415,7 @@ function App.disable_tests()
App.screen.move = love.window.setPosition App.screen.move = love.window.setPosition
App.screen.position = love.window.getPosition App.screen.position = love.window.getPosition
App.screen.print = love.graphics.print App.screen.print = love.graphics.print
App.newText = love.graphics.newText
App.screen.draw = love.graphics.draw App.screen.draw = love.graphics.draw
App.width = function(text) return text:getWidth() end
if Current_app == nil or Current_app == 'run' then if Current_app == nil or Current_app == 'run' then
App.open_for_reading = function(filename) return io.open(filename, 'r') end App.open_for_reading = function(filename) return io.open(filename, 'r') end
App.open_for_writing = function(filename) return io.open(filename, 'w') end App.open_for_writing = function(filename) return io.open(filename, 'w') end

View File

@ -43,21 +43,19 @@ function source.draw_menu_bar()
end end
function add_hotkey_to_menu(s) function add_hotkey_to_menu(s)
local s_text = to_text(s) local width = App.width(s)
local width = App.width(s_text)
if Menu_cursor > App.screen.width - 30 then if Menu_cursor > App.screen.width - 30 then
return return
end end
App.color(Menu_command_color) App.color(Menu_command_color)
App.screen.draw(s_text, Menu_cursor,5) App.screen.print(s, Menu_cursor,5)
Menu_cursor = Menu_cursor + width + 30 Menu_cursor = Menu_cursor + width + 30
end end
function source.draw_file_navigator() function source.draw_file_navigator()
App.color(Menu_command_color) App.color(Menu_command_color)
local filter_text = to_text(File_navigation.filter) App.screen.print(File_navigation.filter, 5, 5)
App.screen.draw(filter_text, 5, 5) draw_cursor(5 + App.width(File_navigation.filter), 5)
draw_cursor(5 + App.width(filter_text), 5)
if File_navigation.num_lines == nil then if File_navigation.num_lines == nil then
File_navigation.num_lines = source.num_lines_for_file_navigator(File_navigation.candidates) File_navigation.num_lines = source.num_lines_for_file_navigator(File_navigation.candidates)
end end
@ -97,7 +95,7 @@ function source.num_lines_for_file_navigator(candidates)
local result = 1 local result = 1
local x = 5 local x = 5
for i,filename in ipairs(candidates) do for i,filename in ipairs(candidates) do
local width = App.width(to_text(filename)) local width = App.width(filename)
if x + width > App.screen.width - 5 then if x + width > App.screen.width - 5 then
result = result+1 result = result+1
x = 5 + width x = 5 + width
@ -109,8 +107,7 @@ function source.num_lines_for_file_navigator(candidates)
end end
function add_file_to_menu(x,y, s, cursor_highlight) function add_file_to_menu(x,y, s, cursor_highlight)
local s_text = to_text(s) local width = App.width(s)
local width = App.width(s_text)
if x + width > App.screen.width - 5 then if x + width > App.screen.width - 5 then
y = y + Editor_state.line_height y = y + Editor_state.line_height
x = 5 x = 5
@ -125,7 +122,7 @@ function add_file_to_menu(x,y, s, cursor_highlight)
end end
}) })
App.color(Menu_command_color) App.color(Menu_command_color)
App.screen.draw(s_text, x,y) App.screen.print(s, x,y)
x = x + width + 30 x = x + width + 30
return x,y return x,y
end end
@ -189,8 +186,7 @@ function log_render.file_navigator_state(o, x,y, w)
local x2,y2 = 0,0 local x2,y2 = 0,0
local width = 0 local width = 0
for i,filename in ipairs(o.files) do for i,filename in ipairs(o.files) do
local filename_text = to_text(filename) width = App.width(filename)
width = App.width(filename_text)
if x2 + width > App.screen.width - 5 then if x2 + width > App.screen.width - 5 then
y2 = y2 + Editor_state.line_height y2 = y2 + Editor_state.line_height
x2 = 0 x2 = 0
@ -207,8 +203,7 @@ function log_render.file_navigator_state(o, x,y, w)
local x3,y3 = 0,y -- x3 is relative, y3 is absolute local x3,y3 = 0,y -- x3 is relative, y3 is absolute
local width = 0 local width = 0
for i,filename in ipairs(o.files) do for i,filename in ipairs(o.files) do
local filename_text = to_text(filename) width = App.width(filename)
width = App.width(filename_text)
if x3 + width > App.screen.width - 5 then if x3 + width > App.screen.width - 5 then
y3 = y3 + Editor_state.line_height y3 = y3 + Editor_state.line_height
x3 = 0 x3 = 0
@ -219,7 +214,7 @@ function log_render.file_navigator_state(o, x,y, w)
end end
if x3 >= menu_xmin and x3 + width < menu_xmax then if x3 >= menu_xmin and x3 + width < menu_xmax then
App.color(Menu_command_color) App.color(Menu_command_color)
App.screen.draw(filename_text, x + x3-menu_xmin, y3) App.screen.print(filename, x + x3-menu_xmin, y3)
end end
x3 = x3 + width + 30 x3 = x3 + width + 30
end end
@ -246,7 +241,7 @@ end
function file_coord(index) function file_coord(index)
local y,x = Menu_status_bar_height, 5 local y,x = Menu_status_bar_height, 5
for i,filename in ipairs(File_navigation.candidates) do for i,filename in ipairs(File_navigation.candidates) do
local width = App.width(to_text(filename)) local width = App.width(filename)
if x + width > App.screen.width - 5 then if x + width > App.screen.width - 5 then
y = y + Editor_state.line_height y = y + Editor_state.line_height
x = 5 x = 5
@ -264,7 +259,7 @@ function file_index(fy, fx, fwidth)
local y,x = Menu_status_bar_height, 5 local y,x = Menu_status_bar_height, 5
local best_guess, best_guess_x, best_guess_width local best_guess, best_guess_x, best_guess_width
for i,filename in ipairs(File_navigation.candidates) do for i,filename in ipairs(File_navigation.candidates) do
local width = App.width(to_text(filename)) local width = App.width(filename)
if x + width > App.screen.width - 5 then if x + width > App.screen.width - 5 then
y = y + Editor_state.line_height y = y + Editor_state.line_height
x = 5 x = 5

View File

@ -60,14 +60,13 @@ function Drawing.draw(State, line_index, y)
if State.current_drawing_mode == 'name' and i == line.pending.target_point then if State.current_drawing_mode == 'name' and i == line.pending.target_point then
-- create a faint red box for the name -- create a faint red box for the name
App.color(Current_name_background_color) App.color(Current_name_background_color)
local name_text local name_width
-- TODO: avoid computing name width on every repaint
if p.name == '' then if p.name == '' then
name_text = State.em name_width = App.width('m')
else else
name_text = App.newText(love.graphics.getFont(), p.name) name_width = App.width(p.name)
end end
love.graphics.rectangle('fill', x,y, App.width(name_text), State.line_height) love.graphics.rectangle('fill', x,y, name_width, State.line_height)
end end
end end
end end

View File

@ -21,7 +21,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
-- rendering wrapped text lines needs some additional short-lived data per line: -- rendering wrapped text lines needs some additional short-lived data per line:
-- startpos, the index of data the line starts rendering from, can only be >1 for topmost line on screen -- startpos, the index of data the line starts rendering from, can only be >1 for topmost line on screen
-- starty, the y coord in pixels the line starts rendering from -- starty, the y coord in pixels the line starts rendering from
-- fragments: snippets of rendered love.graphics.Text, guaranteed to not straddle screen lines -- fragments: snippets of the line guaranteed to not straddle screen lines
-- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line -- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line
line_cache = {}, line_cache = {},
@ -52,7 +52,6 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
font_height = font_height, font_height = font_height,
line_height = line_height, line_height = line_height,
em = App.newText(love.graphics.getFont(), 'm'), -- widest possible character width
top = top, top = top,
left = math.floor(left), left = math.floor(left),
@ -68,7 +67,6 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
-- search -- search
search_term = nil, search_term = nil,
search_text = nil,
search_backup = nil, -- stuff to restore when cancelling search search_backup = nil, -- stuff to restore when cancelling search
} }
return result return result
@ -220,7 +218,6 @@ function edit.text_input(State, t)
--? print('text input', t) --? print('text input', t)
if State.search_term then if State.search_term then
State.search_term = State.search_term..t State.search_term = State.search_term..t
State.search_text = nil
Text.search_next(State) Text.search_next(State)
else else
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
@ -241,20 +238,17 @@ function edit.keychord_press(State, chord, key)
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
if chord == 'escape' then if chord == 'escape' then
State.search_term = nil State.search_term = nil
State.search_text = nil
State.cursor1 = State.search_backup.cursor State.cursor1 = State.search_backup.cursor
State.screen_top1 = State.search_backup.screen_top State.screen_top1 = State.search_backup.screen_top
State.search_backup = nil State.search_backup = nil
Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks
elseif chord == 'return' then elseif chord == 'return' then
State.search_term = nil State.search_term = nil
State.search_text = nil
State.search_backup = nil State.search_backup = nil
elseif chord == 'backspace' then elseif chord == 'backspace' then
local len = utf8.len(State.search_term) local len = utf8.len(State.search_term)
local byte_offset = Text.offset(State.search_term, len) local byte_offset = Text.offset(State.search_term, len)
State.search_term = string.sub(State.search_term, 1, byte_offset-1) State.search_term = string.sub(State.search_term, 1, byte_offset-1)
State.search_text = nil
elseif chord == 'down' then elseif chord == 'down' then
State.cursor1.pos = State.cursor1.pos+1 State.cursor1.pos = State.cursor1.pos+1
Text.search_next(State) Text.search_next(State)
@ -268,7 +262,6 @@ function edit.keychord_press(State, chord, key)
cursor={line=State.cursor1.line, pos=State.cursor1.pos}, cursor={line=State.cursor1.line, pos=State.cursor1.pos},
screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos}, screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos},
} }
assert(State.search_text == nil)
-- zoom -- zoom
elseif chord == 'C-=' then elseif chord == 'C-=' then
edit.update_font_settings(State, State.font_height+2) edit.update_font_settings(State, State.font_height+2)
@ -359,7 +352,6 @@ function edit.update_font_settings(State, font_height)
State.font_height = font_height State.font_height = font_height
love.graphics.setFont(love.graphics.newFont(State.font_height)) love.graphics.setFont(love.graphics.newFont(State.font_height))
State.line_height = math.floor(font_height*1.3) State.line_height = math.floor(font_height*1.3)
State.em = App.newText(love.graphics.getFont(), 'm')
Text_cache = {} Text_cache = {}
end end

View File

@ -147,5 +147,5 @@ function current_shape(State, shape)
end end
function bullet_indent() function bullet_indent()
return App.width(to_text('* ')) return App.width('* ')
end end

View File

@ -98,21 +98,20 @@ function log_browser.draw(State)
local xright = render_stack_right_margin(State, line_index, line, y) local xright = render_stack_right_margin(State, line_index, line, y)
if line.section_name then if line.section_name then
App.color(Section_border_color) App.color(Section_border_color)
local section_text = to_text(line.section_name)
if line.section_begin then if line.section_begin then
local sectiony = y+Section_border_padding_vertical local sectiony = y+Section_border_padding_vertical
love.graphics.line(xleft,sectiony, xleft,y+State.line_height) love.graphics.line(xleft,sectiony, xleft,y+State.line_height)
love.graphics.line(xright,sectiony, xright,y+State.line_height) love.graphics.line(xright,sectiony, xright,y+State.line_height)
love.graphics.line(xleft,sectiony, xleft+50-2,sectiony) love.graphics.line(xleft,sectiony, xleft+50-2,sectiony)
love.graphics.draw(section_text, xleft+50,y) love.graphics.print(line.section_name, xleft+50,y)
love.graphics.line(xleft+50+App.width(section_text)+2,sectiony, xright,sectiony) love.graphics.line(xleft+50+App.width(line.section_name)+2,sectiony, xright,sectiony)
else assert(line.section_end) else assert(line.section_end)
local sectiony = y+State.line_height-Section_border_padding_vertical local sectiony = y+State.line_height-Section_border_padding_vertical
love.graphics.line(xleft,y, xleft,sectiony) love.graphics.line(xleft,y, xleft,sectiony)
love.graphics.line(xright,y, xright,sectiony) love.graphics.line(xright,y, xright,sectiony)
love.graphics.line(xleft,sectiony, xleft+50-2,sectiony) love.graphics.line(xleft,sectiony, xleft+50-2,sectiony)
love.graphics.draw(section_text, xleft+50,y) love.graphics.print(line.section_name, xleft+50,y)
love.graphics.line(xleft+50+App.width(section_text)+2,sectiony, xright,sectiony) love.graphics.line(xleft+50+App.width(line.section_name)+2,sectiony, xright,sectiony)
end end
else else
if type(line.data) == 'string' then if type(line.data) == 'string' then
@ -148,7 +147,7 @@ function render_stack_left_margin(State, line_index, line, y)
love.graphics.print(line.section_stack[i].name, x+State.font_height+5, y+5, --[[vertically]] math.pi/2) love.graphics.print(line.section_stack[i].name, x+State.font_height+5, y+5, --[[vertically]] math.pi/2)
end end
if y > App.screen.height-log_browser.height(State, line_index) then if y > App.screen.height-log_browser.height(State, line_index) then
love.graphics.print(line.section_stack[i].name, x+State.font_height+5, App.screen.height-App.width(to_text(line.section_stack[i].name))-5, --[[vertically]] math.pi/2) love.graphics.print(line.section_stack[i].name, x+State.font_height+5, App.screen.height-App.width(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
end end
end end
return log_browser.left_margin(State, line) return log_browser.left_margin(State, line)
@ -163,7 +162,7 @@ function render_stack_right_margin(State, line_index, line, y)
love.graphics.print(line.section_stack[i].name, x, y+5, --[[vertically]] math.pi/2) love.graphics.print(line.section_stack[i].name, x, y+5, --[[vertically]] math.pi/2)
end end
if y > App.screen.height-log_browser.height(State, line_index) then if y > App.screen.height-log_browser.height(State, line_index) then
love.graphics.print(line.section_stack[i].name, x, App.screen.height-App.width(to_text(line.section_stack[i].name))-5, --[[vertically]] math.pi/2) love.graphics.print(line.section_stack[i].name, x, App.screen.height-App.width(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
end end
end end
return log_browser.right_margin(State, line) return log_browser.right_margin(State, line)

12
run.lua
View File

@ -71,12 +71,10 @@ end
function run.initialize_default_settings() function run.initialize_default_settings()
local font_height = 20 local font_height = 20
love.graphics.setFont(love.graphics.newFont(font_height)) love.graphics.setFont(love.graphics.newFont(font_height))
local em = App.newText(love.graphics.getFont(), 'm') run.initialize_window_geometry(App.width('m'))
run.initialize_window_geometry(App.width(em))
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right) Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
Editor_state.font_height = font_height Editor_state.font_height = font_height
Editor_state.line_height = math.floor(font_height*1.3) Editor_state.line_height = math.floor(font_height*1.3)
Editor_state.em = em
Settings = run.settings() Settings = run.settings()
end end
@ -197,10 +195,6 @@ function run.key_release(key, scancode)
return edit.key_release(Editor_state, key, scancode) return edit.key_release(Editor_state, key, scancode)
end end
-- use this sparingly function width(s)
function to_text(s) return love.graphics.getFont():getWidth(s)
if Text_cache[s] == nil then
Text_cache[s] = App.newText(love.graphics.getFont(), s)
end
return Text_cache[s]
end end

View File

@ -13,10 +13,7 @@ function Text.draw_search_bar(State)
love.graphics.rectangle('line', 20, y-6, App.screen.width-40, h+2, 2,2) love.graphics.rectangle('line', 20, y-6, App.screen.width-40, h+2, 2,2)
App.color(Text_color) App.color(Text_color)
App.screen.print(State.search_term, 25,y-5) App.screen.print(State.search_term, 25,y-5)
if State.search_text == nil then Text.draw_cursor(State, 25+App.width(State.search_term),y-5)
State.search_text = App.newText(love.graphics.getFont(), State.search_term)
end
Text.draw_cursor(State, 25+App.width(State.search_text),y-5)
end end
function Text.search_next(State) function Text.search_next(State)

View File

@ -58,15 +58,12 @@ function Text.draw_highlight(State, line, x,y, pos, lo,hi)
lo_px = 0 lo_px = 0
else else
local before = line.data:sub(pos_offset, lo_offset-1) local before = line.data:sub(pos_offset, lo_offset-1)
local before_text = App.newText(love.graphics.getFont(), before) lo_px = App.width(before)
lo_px = App.width(before_text)
end end
--? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px) --? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px)
local s = line.data:sub(lo_offset, hi_offset-1) local s = line.data:sub(lo_offset, hi_offset-1)
local text = App.newText(love.graphics.getFont(), s)
local text_width = App.width(text)
App.color(Highlight_color) App.color(Highlight_color)
love.graphics.rectangle('fill', x+lo_px,y, text_width,State.line_height) love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height)
App.color(Text_color) App.color(Text_color)
return lo_px return lo_px
end end

View File

@ -162,13 +162,11 @@ end
function source.initialize_default_settings() function source.initialize_default_settings()
local font_height = 20 local font_height = 20
love.graphics.setFont(love.graphics.newFont(font_height)) love.graphics.setFont(love.graphics.newFont(font_height))
local em = App.newText(love.graphics.getFont(), 'm') source.initialize_window_geometry(App.width('m'))
source.initialize_window_geometry(App.width(em))
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right) Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
Editor_state.filename = 'run.lua' Editor_state.filename = 'run.lua'
Editor_state.font_height = font_height Editor_state.font_height = font_height
Editor_state.line_height = math.floor(font_height*1.3) Editor_state.line_height = math.floor(font_height*1.3)
Editor_state.em = em
end end
function source.initialize_window_geometry(em_width) function source.initialize_window_geometry(em_width)
@ -418,11 +416,3 @@ function source.key_release(key, scancode)
return log_browser.keychord_press(Log_browser_state, chordkey, scancode) return log_browser.keychord_press(Log_browser_state, chordkey, scancode)
end end
end end
-- use this sparingly
function to_text(s)
if Text_cache[s] == nil then
Text_cache[s] = App.newText(love.graphics.getFont(), s)
end
return Text_cache[s]
end

View File

@ -54,7 +54,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
-- rendering wrapped text lines needs some additional short-lived data per line: -- rendering wrapped text lines needs some additional short-lived data per line:
-- startpos, the index of data the line starts rendering from, can only be >1 for topmost line on screen -- startpos, the index of data the line starts rendering from, can only be >1 for topmost line on screen
-- starty, the y coord in pixels the line starts rendering from -- starty, the y coord in pixels the line starts rendering from
-- fragments: snippets of rendered love.graphics.Text, guaranteed to not straddle screen lines -- fragments: snippets of the line guaranteed to not straddle screen lines
-- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line -- screen_line_starting_pos: optional array of grapheme indices if it wraps over more than one screen line
line_cache = {}, line_cache = {},
@ -88,7 +88,6 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
font_height = font_height, font_height = font_height,
line_height = line_height, line_height = line_height,
em = App.newText(love.graphics.getFont(), 'm'), -- widest possible character width
top = top, top = top,
left = math.floor(left), left = math.floor(left),
@ -104,7 +103,6 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
-- search -- search
search_term = nil, search_term = nil,
search_text = nil,
search_backup = nil, -- stuff to restore when cancelling search search_backup = nil, -- stuff to restore when cancelling search
} }
return result return result
@ -325,7 +323,6 @@ function edit.text_input(State, t)
--? print('text input', t) --? print('text input', t)
if State.search_term then if State.search_term then
State.search_term = State.search_term..t State.search_term = State.search_term..t
State.search_text = nil
Text.search_next(State) Text.search_next(State)
elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then
local before = snapshot(State, State.lines.current_drawing_index) local before = snapshot(State, State.lines.current_drawing_index)
@ -356,20 +353,17 @@ function edit.keychord_press(State, chord, key)
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
if chord == 'escape' then if chord == 'escape' then
State.search_term = nil State.search_term = nil
State.search_text = nil
State.cursor1 = State.search_backup.cursor State.cursor1 = State.search_backup.cursor
State.screen_top1 = State.search_backup.screen_top State.screen_top1 = State.search_backup.screen_top
State.search_backup = nil State.search_backup = nil
Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks
elseif chord == 'return' then elseif chord == 'return' then
State.search_term = nil State.search_term = nil
State.search_text = nil
State.search_backup = nil State.search_backup = nil
elseif chord == 'backspace' then elseif chord == 'backspace' then
local len = utf8.len(State.search_term) local len = utf8.len(State.search_term)
local byte_offset = Text.offset(State.search_term, len) local byte_offset = Text.offset(State.search_term, len)
State.search_term = string.sub(State.search_term, 1, byte_offset-1) State.search_term = string.sub(State.search_term, 1, byte_offset-1)
State.search_text = nil
elseif chord == 'down' then elseif chord == 'down' then
State.cursor1.pos = State.cursor1.pos+1 State.cursor1.pos = State.cursor1.pos+1
Text.search_next(State) Text.search_next(State)
@ -383,7 +377,6 @@ function edit.keychord_press(State, chord, key)
cursor={line=State.cursor1.line, pos=State.cursor1.pos}, cursor={line=State.cursor1.line, pos=State.cursor1.pos},
screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos}, screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos},
} }
assert(State.search_text == nil)
-- zoom -- zoom
elseif chord == 'C-=' then elseif chord == 'C-=' then
edit.update_font_settings(State, State.font_height+2) edit.update_font_settings(State, State.font_height+2)
@ -515,7 +508,6 @@ function edit.update_font_settings(State, font_height)
State.font_height = font_height State.font_height = font_height
love.graphics.setFont(love.graphics.newFont(State.font_height)) love.graphics.setFont(love.graphics.newFont(State.font_height))
State.line_height = math.floor(font_height*1.3) State.line_height = math.floor(font_height*1.3)
State.em = App.newText(love.graphics.getFont(), 'm')
Text_cache = {} Text_cache = {}
end end

View File

@ -1,7 +1,5 @@
-- primitives for saving to file and loading from file -- primitives for saving to file and loading from file
Fold = '\x1e' -- ASCII RS (record separator)
function file_exists(filename) function file_exists(filename)
local infile = App.open_for_reading(filename) local infile = App.open_for_reading(filename)
if infile then if infile then
@ -28,13 +26,7 @@ function load_from_file(infile)
if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated
table.insert(result, load_drawing(infile_next_line)) table.insert(result, load_drawing(infile_next_line))
else else
local line_info = {mode='text'} table.insert(result, {mode='text', data=line})
if line:find(Fold) then
_, _, line_info.data, line_info.dataB = line:find('([^'..Fold..']*)'..Fold..'([^'..Fold..']*)')
else
line_info.data = line
end
table.insert(result, line_info)
end end
end end
end end
@ -54,10 +46,6 @@ function save_to_disk(State)
store_drawing(outfile, line) store_drawing(outfile, line)
else else
outfile:write(line.data) outfile:write(line.data)
if line.dataB and #line.dataB > 0 then
outfile:write(Fold)
outfile:write(line.dataB)
end
outfile:write('\n') outfile:write('\n')
end end
end end
@ -147,11 +135,7 @@ function load_array(a)
else else
--? print('inserting text') --? print('inserting text')
local line_info = {mode='text'} local line_info = {mode='text'}
if line:find(Fold) then line_info.data = line
_, _, line_info.data, line_info.dataB = line:find('([^'..Fold..']*)'..Fold..'([^'..Fold..']*)')
else
line_info.data = line
end
table.insert(result, line_info) table.insert(result, line_info)
end end
end end

View File

@ -60,15 +60,12 @@ function Text.draw_highlight(State, line, x,y, pos, lo,hi)
lo_px = 0 lo_px = 0
else else
local before = line.data:sub(pos_offset, lo_offset-1) local before = line.data:sub(pos_offset, lo_offset-1)
local before_text = App.newText(love.graphics.getFont(), before) lo_px = App.width(before)
lo_px = App.width(before_text)
end end
--? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px) --? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px)
local s = line.data:sub(lo_offset, hi_offset-1) local s = line.data:sub(lo_offset, hi_offset-1)
local text = App.newText(love.graphics.getFont(), s)
local text_width = App.width(text)
App.color(Highlight_color) App.color(Highlight_color)
love.graphics.rectangle('fill', x+lo_px,y, text_width,State.line_height) love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height)
App.color(Text_color) App.color(Text_color)
return lo_px return lo_px
end end

View File

@ -12,21 +12,20 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
local x = State.left local x = State.left
local pos = 1 local pos = 1
local screen_line_starting_pos = startpos local screen_line_starting_pos = startpos
Text.compute_fragments(State, line_index) Text.populate_screen_line_starting_pos(State, line_index)
local pos = 1 local pos = 1
initialize_color() initialize_color()
for _, f in ipairs(line_cache.fragments) do for _, f in ipairs(line_cache.fragments) do
App.color(Text_color) App.color(Text_color)
local frag, frag_text = f.data, f.text select_color(f)
select_color(frag) local frag_len = utf8.len(f)
local frag_len = utf8.len(frag) --? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
--? print('text.draw:', frag, 'at', line_index,pos, 'after', x,y)
if pos < startpos then if pos < startpos then
-- render nothing -- render nothing
--? print('skipping', frag) --? print('skipping', f)
else else
-- render fragment -- render fragment
local frag_width = App.width(frag_text) local frag_width = App.width(f)
if x + frag_width > State.right then if x + frag_width > State.right then
assert(x > State.left) -- no overfull lines assert(x > State.left) -- no overfull lines
y = y + State.line_height y = y + State.line_height
@ -41,12 +40,11 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
Text.draw_highlight(State, line, x,y, pos, lo,hi) Text.draw_highlight(State, line, x,y, pos, lo,hi)
end end
-- Make [[WikiWords]] (single word, all in one screen line) clickable. -- Make [[WikiWords]] (single word, all in one screen line) clickable.
local trimmed_word = rtrim(frag) -- compute_fragments puts whitespace at the end local trimmed_word = rtrim(f) -- compute_fragments puts whitespace at the end
if starts_with(trimmed_word, '[[') and ends_with(trimmed_word, ']]') then if starts_with(trimmed_word, '[[') and ends_with(trimmed_word, ']]') then
local filename = trimmed_word:gsub('^..(.*)..$', '%1') local filename = trimmed_word:gsub('^..(.*)..$', '%1')
if source.link_exists(State, filename) then if source.link_exists(State, filename) then
local filename_text = App.newText(love.graphics.getFont(), filename) button(State, 'link', {x=x+App.width('[['), y=y, w=App.width(filename), h=State.line_height, color={1,1,1},
button(State, 'link', {x=x+App.width(to_text('[[')), y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},
icon = icon.hyperlink_decoration, icon = icon.hyperlink_decoration,
onpress1 = function() onpress1 = function()
source.switch_to_file(filename) source.switch_to_file(filename)
@ -54,7 +52,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
}) })
end end
end end
App.screen.draw(frag_text, x,y) App.screen.print(f, x,y)
-- render cursor if necessary -- render cursor if necessary
if line_index == State.cursor1.line then if line_index == State.cursor1.line then
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then
@ -65,7 +63,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
love.graphics.print(State.search_term, x+lo_px,y) love.graphics.print(State.search_term, x+lo_px,y)
end end
elseif Focus == 'edit' then elseif Focus == 'edit' then
Text.draw_cursor(State, x+Text.x(frag, State.cursor1.pos-pos+1), y) Text.draw_cursor(State, x+Text.x(f, State.cursor1.pos-pos+1), y)
App.color(Text_color) App.color(Text_color)
end end
end end
@ -105,21 +103,18 @@ function Text.populate_screen_line_starting_pos(State, line_index)
local x = State.left local x = State.left
local pos = 1 local pos = 1
for _, f in ipairs(line_cache.fragments) do for _, f in ipairs(line_cache.fragments) do
local frag, frag_text = f.data, f.text
-- render fragment -- render fragment
local frag_width = App.width(frag_text) local frag_width = App.width(f)
if x + frag_width > State.right then if x + frag_width > State.right then
x = State.left x = State.left
table.insert(line_cache.screen_line_starting_pos, pos) table.insert(line_cache.screen_line_starting_pos, pos)
end end
x = x + frag_width x = x + frag_width
local frag_len = utf8.len(frag) pos = pos + utf8.len(f)
pos = pos + frag_len
end end
end end
function Text.compute_fragments(State, line_index) function Text.compute_fragments(State, line_index)
--? print('compute_fragments', line_index, 'between', State.left, State.right)
local line = State.lines[line_index] local line = State.lines[line_index]
if line.mode ~= 'text' then return end if line.mode ~= 'text' then return end
local line_cache = State.line_cache[line_index] local line_cache = State.line_cache[line_index]
@ -130,35 +125,25 @@ function Text.compute_fragments(State, line_index)
local x = State.left local x = State.left
-- try to wrap at word boundaries -- try to wrap at word boundaries
for frag in line.data:gmatch('%S*%s*') do for frag in line.data:gmatch('%S*%s*') do
local frag_text = App.newText(love.graphics.getFont(), frag) local frag_width = App.width(frag)
local frag_width = App.width(frag_text)
--? print('x: '..tostring(x)..'; frag_width: '..tostring(frag_width)..'; '..tostring(State.right-x)..'px to go')
while x + frag_width > State.right do while x + frag_width > State.right do
--? print(('checking whether to split fragment ^%s$ of width %d when rendering from %d'):format(frag, frag_width, x))
if (x-State.left) < 0.8 * (State.right-State.left) then if (x-State.left) < 0.8 * (State.right-State.left) then
--? print('splitting')
-- long word; chop it at some letter -- long word; chop it at some letter
-- We're not going to reimplement TeX here. -- We're not going to reimplement TeX here.
local bpos = Text.nearest_pos_less_than(frag, State.right - x) local bpos = Text.nearest_pos_less_than(frag, State.right - x)
--? print('bpos', bpos)
if bpos == 0 then break end -- avoid infinite loop when window is too narrow if bpos == 0 then break end -- avoid infinite loop when window is too narrow
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
--? print('space for '..tostring(bpos)..' graphemes, '..tostring(boffset-1)..' bytes')
local frag1 = string.sub(frag, 1, boffset-1) local frag1 = string.sub(frag, 1, boffset-1)
local frag1_text = App.newText(love.graphics.getFont(), frag1) local frag1_width = App.width(frag1)
local frag1_width = App.width(frag1_text)
--? print('extracting ^'..frag1..'$ of width '..tostring(frag1_width)..'px')
assert(x + frag1_width <= State.right) assert(x + frag1_width <= State.right)
table.insert(line_cache.fragments, {data=frag1, text=frag1_text}) table.insert(line_cache.fragments, frag1)
frag = string.sub(frag, boffset) frag = string.sub(frag, boffset)
frag_text = App.newText(love.graphics.getFont(), frag) frag_width = App.width(frag)
frag_width = App.width(frag_text)
end end
x = State.left -- new line x = State.left -- new line
end end
if #frag > 0 then if #frag > 0 then
--? print('inserting ^'..frag..'$ of width '..tostring(frag_width)..'px') table.insert(line_cache.fragments, frag)
table.insert(line_cache.fragments, {data=frag, text=frag_text})
end end
x = x + frag_width x = x + frag_width
end end
@ -776,8 +761,7 @@ function Text.screen_line_width(State, line_index, i)
else else
screen_line = string.sub(line.data, start_pos) screen_line = string.sub(line.data, start_pos)
end end
local screen_line_text = App.newText(love.graphics.getFont(), screen_line) return App.width(screen_line)
return App.width(screen_line_text)
end end
function Text.screen_line_index(screen_line_starting_pos, pos) function Text.screen_line_index(screen_line_starting_pos, pos)
@ -865,15 +849,13 @@ function Text.x_after(s, pos)
local offset = Text.offset(s, math.min(pos+1, #s+1)) local offset = Text.offset(s, math.min(pos+1, #s+1))
local s_before = s:sub(1, offset-1) local s_before = s:sub(1, offset-1)
--? print('^'..s_before..'$') --? print('^'..s_before..'$')
local text_before = App.newText(love.graphics.getFont(), s_before) return App.width(s_before)
return App.width(text_before)
end end
function Text.x(s, pos) function Text.x(s, pos)
local offset = Text.offset(s, pos) local offset = Text.offset(s, pos)
local s_before = s:sub(1, offset-1) local s_before = s:sub(1, offset-1)
local text_before = App.newText(love.graphics.getFont(), s_before) return App.width(s_before)
return App.width(text_before)
end end
function Text.to2(State, loc1) function Text.to2(State, loc1)

View File

@ -61,14 +61,9 @@ function snapshot(State, s,e)
for i=s,e do for i=s,e do
local line = State.lines[i] local line = State.lines[i]
if line.mode == 'text' then if line.mode == 'text' then
table.insert(event.lines, {mode='text', data=line.data, dataB=line.dataB}) table.insert(event.lines, {mode='text', data=line.data}) -- I've forgotten: should we deepcopy(line.data)?
elseif line.mode == 'drawing' then elseif line.mode == 'drawing' then
local points=deepcopy(line.points) table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})
--? print('copying', line.points, 'with', #line.points, 'points into', points)
local shapes=deepcopy(line.shapes)
--? print('copying', line.shapes, 'with', #line.shapes, 'shapes into', shapes)
table.insert(event.lines, {mode='drawing', h=line.h, points=points, shapes=shapes, pending={}})
--? table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})
else else
print(line.mode) print(line.mode)
assert(false) assert(false)

145
text.lua
View File

@ -4,64 +4,64 @@ Text = {}
-- draw a line starting from startpos to screen at y between State.left and State.right -- draw a line starting from startpos to screen at y between State.left and State.right
-- return the final y, and position of start of final screen line drawn -- return the final y, and position of start of final screen line drawn
function Text.draw(State, line_index, y, startpos) function Text.draw(State, line_index, y, startpos)
--? print('text.draw', line_index, y)
local line = State.lines[line_index] local line = State.lines[line_index]
local line_cache = State.line_cache[line_index] local line_cache = State.line_cache[line_index]
line_cache.starty = y line_cache.starty = y
line_cache.startpos = startpos line_cache.startpos = startpos
-- wrap long lines -- wrap long lines
local x = State.left local final_screen_line_starting_pos = startpos -- track value to return
local pos = 1 Text.populate_screen_line_starting_pos(State, line_index)
local screen_line_starting_pos = startpos assert(#line_cache.screen_line_starting_pos >= 1)
Text.compute_fragments(State, line_index) for i=1,#line_cache.screen_line_starting_pos do
for _, f in ipairs(line_cache.fragments) do local pos = line_cache.screen_line_starting_pos[i]
App.color(Text_color)
local frag, frag_text = f.data, f.text
local frag_len = utf8.len(frag)
--? print('text.draw:', frag, 'at', line_index,pos, 'after', x,y)
if pos < startpos then if pos < startpos then
-- render nothing -- render nothing
--? print('skipping', frag) --? print('skipping', f)
else else
final_screen_line_starting_pos = pos
local f = Text.screen_line(line, line_cache, i)
--? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
local frag_len = utf8.len(f)
-- render fragment -- render fragment
local frag_width = App.width(frag_text)
if x + frag_width > State.right then
assert(x > State.left) -- no overfull lines
y = y + State.line_height
if y + State.line_height > App.screen.height then
return y, screen_line_starting_pos
end
screen_line_starting_pos = pos
x = State.left
end
if State.selection1.line then if State.selection1.line then
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len) local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
Text.draw_highlight(State, line, x,y, pos, lo,hi) Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
end end
App.screen.draw(frag_text, x,y) App.color(Text_color)
App.screen.print(f, State.left,y)
-- render cursor if necessary -- render cursor if necessary
if line_index == State.cursor1.line then if line_index == State.cursor1.line then
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
if State.search_term then if State.search_term then
if State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then if State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then
local lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)) local lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term))
App.color(Text_color) App.color(Text_color)
love.graphics.print(State.search_term, x+lo_px,y) love.graphics.print(State.search_term, State.left+lo_px,y)
end end
else else
Text.draw_cursor(State, x+Text.x(frag, State.cursor1.pos-pos+1), y) Text.draw_cursor(State, State.left+Text.x(f, State.cursor1.pos-pos+1), y)
end end
end end
end end
x = x + frag_width y = y + State.line_height
end if y >= App.screen.height then
pos = pos + frag_len break
end end
if State.search_term == nil then
if line_index == State.cursor1.line and State.cursor1.pos == pos then
Text.draw_cursor(State, x, y)
end end
end end
return y, screen_line_starting_pos return y - State.line_height, final_screen_line_starting_pos
end
function Text.screen_line(line, line_cache, i)
local pos = line_cache.screen_line_starting_pos[i]
local offset = Text.offset(line.data, pos)
if i >= #line_cache.screen_line_starting_pos then
return line.data:sub(offset)
end
local endpos = line_cache.screen_line_starting_pos[i+1]-1
local end_offset = Text.offset(line.data, endpos)
return line.data:sub(offset, end_offset)
end end
function Text.draw_cursor(State, x, y) function Text.draw_cursor(State, x, y)
@ -81,67 +81,34 @@ function Text.populate_screen_line_starting_pos(State, line_index)
if line_cache.screen_line_starting_pos then if line_cache.screen_line_starting_pos then
return return
end end
-- duplicate some logic from Text.draw
Text.compute_fragments(State, line_index)
line_cache.screen_line_starting_pos = {1} line_cache.screen_line_starting_pos = {1}
local x = State.left local x = 0
local pos = 1 local pos = 1
for _, f in ipairs(line_cache.fragments) do
local frag, frag_text = f.data, f.text
-- render fragment
local frag_width = App.width(frag_text)
if x + frag_width > State.right then
x = State.left
table.insert(line_cache.screen_line_starting_pos, pos)
end
x = x + frag_width
local frag_len = utf8.len(frag)
pos = pos + frag_len
end
end
function Text.compute_fragments(State, line_index)
--? print('compute_fragments', line_index, 'between', State.left, State.right)
local line = State.lines[line_index]
local line_cache = State.line_cache[line_index]
if line_cache.fragments then
return
end
line_cache.fragments = {}
local x = State.left
-- try to wrap at word boundaries -- try to wrap at word boundaries
for frag in line.data:gmatch('%S*%s*') do for frag in line.data:gmatch('%S*%s*') do
local frag_text = App.newText(love.graphics.getFont(), frag) local frag_width = App.width(frag)
local frag_width = App.width(frag_text) --? print('-- frag:', frag, pos, x, frag_width, State.width)
--? print('x: '..tostring(x)..'; frag_width: '..tostring(frag_width)..'; '..tostring(State.right-x)..'px to go') while x + frag_width > State.width do
while x + frag_width > State.right do --? print('frag:', frag, pos, x, frag_width, State.width)
--? print(('checking whether to split fragment ^%s$ of width %d when rendering from %d'):format(frag, frag_width, x)) if x < 0.8 * State.width then
if (x-State.left) < 0.8 * (State.right-State.left) then
--? print('splitting')
-- long word; chop it at some letter -- long word; chop it at some letter
-- We're not going to reimplement TeX here. -- We're not going to reimplement TeX here.
local bpos = Text.nearest_pos_less_than(frag, State.right - x) local bpos = Text.nearest_pos_less_than(frag, State.width - x)
--? print('bpos', bpos) -- everything works if bpos == 0, but is a little inefficient
if bpos == 0 then break end -- avoid infinite loop when window is too narrow pos = pos + bpos
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
--? print('space for '..tostring(bpos)..' graphemes, '..tostring(boffset-1)..' bytes')
local frag1 = string.sub(frag, 1, boffset-1)
local frag1_text = App.newText(love.graphics.getFont(), frag1)
local frag1_width = App.width(frag1_text)
--? print('extracting ^'..frag1..'$ of width '..tostring(frag1_width)..'px')
assert(x + frag1_width <= State.right)
table.insert(line_cache.fragments, {data=frag1, text=frag1_text})
frag = string.sub(frag, boffset) frag = string.sub(frag, boffset)
frag_text = App.newText(love.graphics.getFont(), frag) --? if bpos > 0 then
frag_width = App.width(frag_text) --? print('after chop:', frag)
--? end
frag_width = App.width(frag)
end end
x = State.left -- new line --? print('screen line:', pos)
end table.insert(line_cache.screen_line_starting_pos, pos)
if #frag > 0 then x = 0 -- new screen line
--? print('inserting ^'..frag..'$ of width '..tostring(frag_width)..'px')
table.insert(line_cache.fragments, {data=frag, text=frag_text})
end end
x = x + frag_width x = x + frag_width
pos = pos + utf8.len(frag)
end end
end end
@ -687,8 +654,7 @@ function Text.screen_line_width(State, line_index, i)
else else
screen_line = string.sub(line.data, start_pos) screen_line = string.sub(line.data, start_pos)
end end
local screen_line_text = App.newText(love.graphics.getFont(), screen_line) return App.width(screen_line)
return App.width(screen_line_text)
end end
function Text.screen_line_index(screen_line_starting_pos, pos) function Text.screen_line_index(screen_line_starting_pos, pos)
@ -776,15 +742,13 @@ function Text.x_after(s, pos)
local offset = Text.offset(s, math.min(pos+1, #s+1)) local offset = Text.offset(s, math.min(pos+1, #s+1))
local s_before = s:sub(1, offset-1) local s_before = s:sub(1, offset-1)
--? print('^'..s_before..'$') --? print('^'..s_before..'$')
local text_before = App.newText(love.graphics.getFont(), s_before) return App.width(s_before)
return App.width(text_before)
end end
function Text.x(s, pos) function Text.x(s, pos)
local offset = Text.offset(s, pos) local offset = Text.offset(s, pos)
local s_before = s:sub(1, offset-1) local s_before = s:sub(1, offset-1)
local text_before = App.newText(love.graphics.getFont(), s_before) return App.width(s_before)
return App.width(text_before)
end end
function Text.to2(State, loc1) function Text.to2(State, loc1)
@ -914,7 +878,6 @@ function Text.redraw_all(State)
end end
function Text.clear_screen_line_cache(State, line_index) function Text.clear_screen_line_cache(State, line_index)
State.line_cache[line_index].fragments = nil
State.line_cache[line_index].screen_line_starting_pos = nil State.line_cache[line_index].screen_line_starting_pos = nil
end end

View File

@ -952,7 +952,7 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
y = y + Editor_state.line_height y = y + Editor_state.line_height
App.screen.check(y, 'jkl ', 'screen:2') App.screen.check(y, 'jkl ', 'screen:2')
y = y + Editor_state.line_height y = y + Editor_state.line_height
App.screen.check(y, 'mno ', 'screen:3') App.screen.check(y, 'mn', 'screen:3')
end end
function test_pagedown_never_moves_up() function test_pagedown_never_moves_up()

View File

@ -58,7 +58,7 @@ function snapshot(State, s,e)
-- deep copy lines without cached stuff like text fragments -- deep copy lines without cached stuff like text fragments
for i=s,e do for i=s,e do
local line = State.lines[i] local line = State.lines[i]
table.insert(event.lines, {data=line.data}) table.insert(event.lines, {data=line.data}) -- I've forgotten: should we deepcopy(line.data)?
end end
return event return event
end end