bring couple more globals back to the app level

This commit is contained in:
Kartik K. Agaram 2022-07-12 13:45:38 -07:00
parent 094f3bd7e8
commit a5f725ab3b
2 changed files with 21 additions and 24 deletions

View File

@ -102,12 +102,6 @@ Search_term = nil
Search_text = nil
Search_backup = nil -- stuff to restore when cancelling search
-- resize
Last_resize_time = nil
-- blinking cursor
Cursor_time = 0
end -- App.initialize_globals
function edit.draw()
@ -172,15 +166,6 @@ function edit.draw()
end
function edit.update(dt)
Cursor_time = Cursor_time + dt
-- some hysteresis while resizing
if Last_resize_time then
if App.getTime() - Last_resize_time < 0.1 then
return
else
Last_resize_time = nil
end
end
Drawing.update(dt)
if Next_save and Next_save < App.getTime() then
save_to_disk(Lines, Filename)
@ -203,8 +188,6 @@ end
function edit.mouse_pressed(x,y, mouse_button)
if Search_term then return end
-- ensure cursor is visible immediately after it moves
Cursor_time = 0
--? print('press', Selection1.line, Selection1.pos)
propagate_to_button_handlers(x,y, mouse_button)
@ -245,8 +228,6 @@ end
function edit.mouse_released(x,y, mouse_button)
if Search_term then return end
--? print('release')
-- ensure cursor is visible immediately after it moves
Cursor_time = 0
if Lines.current_drawing then
Drawing.mouse_released(x,y, mouse_button)
schedule_save()
@ -284,8 +265,6 @@ function edit.mouse_released(x,y, mouse_button)
end
function edit.textinput(t)
-- ensure cursor is visible immediately after it moves
Cursor_time = 0
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
if Search_term then
Search_term = Search_term..t
@ -304,8 +283,6 @@ function edit.textinput(t)
end
function edit.keychord_pressed(chord, key)
-- ensure cursor is visible immediately after it moves
Cursor_time = 0
if Selection1.line and
not Lines.current_drawing and
-- printable character created using shift key => delete selection

View File

@ -14,7 +14,13 @@ Editor_state = {}
-- called both in tests and real run
function App.initialize_globals()
return edit.initialize_globals()
edit.initialize_globals()
-- resize
Last_resize_time = nil
-- blinking cursor
Cursor_time = 0
end
-- called only for real run
@ -144,6 +150,15 @@ function App.draw()
end
function App.update(dt)
Cursor_time = Cursor_time + dt
-- some hysteresis while resizing
if Last_resize_time then
if App.getTime() - Last_resize_time < 0.1 then
return
else
Last_resize_time = nil
end
end
edit.update(dt)
end
@ -165,21 +180,26 @@ function love.quit()
end
function App.mousepressed(x,y, mouse_button)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
return edit.mouse_pressed(x,y, mouse_button)
end
function App.mousereleased(x,y, mouse_button)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
return edit.mouse_released(x,y, mouse_button)
end
function App.textinput(t)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
return edit.textinput(t)
end
function App.keychord_pressed(chord, key)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
return edit.keychord_pressed(chord, key)
end
function App.keyreleased(key, scancode)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
return edit.key_released(key, scancode)
end