bring a few things in sync between run and source
This commit is contained in:
parent
81ebc6a559
commit
ae429cd78a
5
edit.lua
5
edit.lua
|
@ -143,7 +143,10 @@ end
|
||||||
function edit.draw(State)
|
function edit.draw(State)
|
||||||
State.button_handlers = {}
|
State.button_handlers = {}
|
||||||
App.color(Text_color)
|
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
|
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)
|
print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
|
@ -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
|
em = App.newText(love.graphics.getFont(), 'm'), -- widest possible character width
|
||||||
|
|
||||||
top = top,
|
top = top,
|
||||||
left = left,
|
left = math.floor(left),
|
||||||
right = right,
|
right = math.floor(right),
|
||||||
width = right-left,
|
width = right-left,
|
||||||
|
|
||||||
filename = love.filesystem.getUserDirectory()..'/lines.txt', -- '/' should work even on Windows
|
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
|
-- make sure to save before quitting
|
||||||
if State.next_save then
|
if State.next_save then
|
||||||
save_to_disk(State)
|
save_to_disk(State)
|
||||||
|
-- give some time for the OS to flush everything to disk
|
||||||
|
love.timer.sleep(0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function edit.mouse_press(State, x,y, mouse_button)
|
function edit.mouse_press(State, x,y, mouse_button)
|
||||||
if State.search_term then return end
|
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
|
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
|
-- press on a button and it returned 'true' to short-circuit
|
||||||
return
|
return
|
||||||
|
|
|
@ -1721,10 +1721,26 @@ function rtrim(s)
|
||||||
return s:gsub('%s+$', '')
|
return s:gsub('%s+$', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
function starts_with(s, sub)
|
function starts_with(s, prefix)
|
||||||
return s:find(sub, 1, --[[no escapes]] true) == 1
|
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
|
end
|
||||||
|
|
||||||
function ends_with(s, sub)
|
function ends_with(s, suffix)
|
||||||
return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue