diff options
-rw-r--r-- | edit.lua | 5 | ||||
-rw-r--r-- | source_edit.lua | 8 | ||||
-rw-r--r-- | source_text.lua | 24 |
3 files changed, 29 insertions, 8 deletions
diff --git a/edit.lua b/edit.lua index a939bc4..715fd1a 100644 --- a/edit.lua +++ b/edit.lua @@ -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) diff --git a/source_edit.lua b/source_edit.lua index 5c90075..a296c53 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -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 diff --git a/source_text.lua b/source_text.lua index 7c00191..1a43842 100644 --- a/source_text.lua +++ b/source_text.lua @@ -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 |