bring a few things in sync between run and source

This commit is contained in:
Kartik K. Agaram 2023-03-17 21:18:17 -07:00
parent 81ebc6a559
commit ae429cd78a
3 changed files with 29 additions and 8 deletions

View File

@ -143,7 +143,10 @@ end
function edit.draw(State)
State.button_handlers = {}
App.color(Text_color)
assert(#State.lines == #State.line_cache)
if #State.lines ~= #State.line_cache then
print(('line_cache is out of date; %d when it should be %d'):format(#State.line_cache, #State.lines))
assert(false)
end
if not Text.le1(State.screen_top1, State.cursor1) then
print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
assert(false)

View File

@ -96,8 +96,8 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
em = App.newText(love.graphics.getFont(), 'm'), -- widest possible character width
top = top,
left = left,
right = right,
left = math.floor(left),
right = math.floor(right),
width = right-left,
filename = love.filesystem.getUserDirectory()..'/lines.txt', -- '/' should work even on Windows
@ -227,12 +227,14 @@ function edit.quit(State)
-- make sure to save before quitting
if State.next_save then
save_to_disk(State)
-- give some time for the OS to flush everything to disk
love.timer.sleep(0.1)
end
end
function edit.mouse_press(State, x,y, mouse_button)
if State.search_term then return end
--? print('press')
--? print('press', State.selection1.line, State.selection1.pos)
if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
-- press on a button and it returned 'true' to short-circuit
return

View File

@ -1721,10 +1721,26 @@ function rtrim(s)
return s:gsub('%s+$', '')
end
function starts_with(s, sub)
return s:find(sub, 1, --[[no escapes]] true) == 1
function starts_with(s, prefix)
if #s < #prefix then
return false
end
for i=1,#prefix do
if s:sub(i,i) ~= prefix:sub(i,i) then
return false
end
end
return true
end
function ends_with(s, sub)
return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1
function ends_with(s, suffix)
if #s < #suffix then
return false
end
for i=0,#suffix-1 do
if s:sub(#s-i,#s-i) ~= suffix:sub(#suffix-i,#suffix-i) then
return false
end
end
return true
end