diff --git a/app.lua b/app.lua index 212f755..e717220 100644 --- a/app.lua +++ b/app.lua @@ -144,7 +144,7 @@ function App.initialize_for_test() App.screen.init({width=100, height=50}) App.screen.contents = {} -- clear screen App.filesystem = {} - App.fake_key_pressed = {} + App.fake_keys_pressed = {} App.fake_mouse_state = {x=-1, y=-1} if App.initialize_globals then App.initialize_globals() end end @@ -237,15 +237,15 @@ function App.setClipboardText(s) App.clipboard = s end -App.fake_key_pressed = {} +App.fake_keys_pressed = {} function App.fake_key_press(key) - App.fake_key_pressed[key] = true + App.fake_keys_pressed[key] = true end function App.fake_key_release(key) - App.fake_key_pressed[key] = nil + App.fake_keys_pressed[key] = nil end function App.modifier_down(key) - return App.fake_key_pressed[key] + return App.fake_keys_pressed[key] end App.fake_mouse_state = {x=-1, y=-1} -- x,y always set @@ -286,7 +286,7 @@ end -- not all keys are textinput -- TODO: handle chords of multiple keys function App.run_after_keychord(chord) - App.keychord_pressed(chord) + App.keychord_press(chord) App.keyreleased(chord) App.screen.contents = {} App.draw() @@ -397,7 +397,7 @@ function App.disable_tests() App.run_after_mouse_click = nil App.run_after_mouse_press = nil App.run_after_mouse_release = nil - App.fake_key_pressed = nil + App.fake_keys_pressed = nil App.fake_key_press = nil App.fake_key_release = nil App.fake_mouse_state = nil diff --git a/commands.lua b/commands.lua index dd096ac..b1ac5ab 100644 --- a/commands.lua +++ b/commands.lua @@ -151,7 +151,7 @@ function reset_file_navigator() File_navigation.candidates = File_navigation.all_candidates end -function keychord_pressed_on_file_navigator(chord, key) +function keychord_press_on_file_navigator(chord, key) log(2, 'file navigator: '..chord) log(2, {name='file_navigator_state', files=File_navigation.candidates, index=File_navigation.index}) if chord == 'escape' then @@ -289,7 +289,7 @@ function file_index(fy, fx, fwidth) return best_guess end -function textinput_on_file_navigator(t) +function text_input_on_file_navigator(t) File_navigation.filter = File_navigation.filter..t File_navigation.candidates = source.file_navigator_candidates() end diff --git a/drawing.lua b/drawing.lua index 0343f85..3d9cd53 100644 --- a/drawing.lua +++ b/drawing.lua @@ -127,7 +127,7 @@ function Drawing.draw_pending_shape(drawing, top, left,right) local mx = Drawing.coord(pmx-left, width) local my = Drawing.coord(pmy-top, width) -- recreate pixels from coords to precisely mimic how the drawing will look - -- after mouse_released + -- after mouse_release pmx,pmy = px(mx), py(my) local shape = drawing.pending if shape.mode == nil then @@ -235,7 +235,7 @@ function Drawing.mouse_pressed(State, drawing_index, x,y, mouse_button) local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width) drawing.pending = {mode=State.current_drawing_mode, center=j} elseif State.current_drawing_mode == 'move' then - -- all the action is in mouse_released + -- all the action is in mouse_release elseif State.current_drawing_mode == 'name' then -- nothing else @@ -292,7 +292,7 @@ function Drawing.relax_constraints(drawing, p) end end -function Drawing.mouse_released(State, x,y, mouse_button) +function Drawing.mouse_release(State, x,y, mouse_button) if State.current_drawing_mode == 'move' then State.current_drawing_mode = State.previous_drawing_mode State.previous_drawing_mode = nil @@ -389,7 +389,7 @@ function Drawing.mouse_released(State, x,y, mouse_button) end end -function Drawing.keychord_pressed(State, chord) +function Drawing.keychord_press(State, chord) if chord == 'C-p' and not App.mouse_down(1) then State.current_drawing_mode = 'freehand' elseif App.mouse_down(1) and chord == 'l' then diff --git a/drawing_tests.lua b/drawing_tests.lua index feadd85..12e9329 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -165,7 +165,7 @@ function test_keys_do_not_affect_shape_when_mouse_up() edit.run_after_keychord(Editor_state, 'o') -- no change to drawing mode check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode') - -- no change to text either because we didn't run the textinput event + -- no change to text either because we didn't run the text_input event end function test_draw_circle_mid_stroke() @@ -185,7 +185,7 @@ function test_draw_circle_mid_stroke() -- draw a circle App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_textinput(Editor_state, 'o') + edit.run_after_text_input(Editor_state, 'o') edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1) local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes') @@ -214,7 +214,7 @@ function test_draw_arc() -- draw an arc edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) App.mouse_move(Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36) - edit.run_after_textinput(Editor_state, 'a') -- arc mode + edit.run_after_text_input(Editor_state, 'a') -- arc mode edit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 1) -- 45° local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_arc/#shapes') @@ -245,10 +245,10 @@ function test_draw_polygon() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_textinput(Editor_state, 'g') -- polygon mode + edit.run_after_text_input(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_textinput(Editor_state, 'p') -- add point + edit.run_after_text_input(Editor_state, 'p') -- add point -- final point edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -284,13 +284,13 @@ function test_draw_rectangle() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_textinput(Editor_state, 'r') -- rectangle mode + edit.run_after_text_input(Editor_state, 'r') -- rectangle mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') -- release (decides 'thickness' of rectangle perpendicular to first edge) edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -329,13 +329,13 @@ function test_draw_rectangle_intermediate() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_textinput(Editor_state, 'r') -- rectangle mode + edit.run_after_text_input(Editor_state, 'r') -- rectangle mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') local drawing = Editor_state.lines[1] check_eq(#drawing.points, 3, 'F - test_draw_rectangle_intermediate/#points') -- currently includes every point added local pending = drawing.pending @@ -366,13 +366,13 @@ function test_draw_square() check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes') -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) - edit.run_after_textinput(Editor_state, 's') -- square mode + edit.run_after_text_input(Editor_state, 's') -- square mode -- second point/first edge App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') -- override second point/first edge App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+66) - edit.run_after_textinput(Editor_state, 'p') + edit.run_after_text_input(Editor_state, 'p') -- release (decides which side of first edge to draw square on) edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1) local drawing = Editor_state.lines[1] @@ -421,7 +421,7 @@ function test_name_point() -- enter 'name' mode without moving the mouse edit.run_after_keychord(Editor_state, 'C-n') check_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:1') - edit.run_after_textinput(Editor_state, 'A') + edit.run_after_text_input(Editor_state, 'A') check_eq(p2.name, 'A', 'F - test_name_point') -- still in 'name' mode check_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:2') @@ -594,13 +594,13 @@ function test_delete_point_from_polygon() edit.draw(Editor_state) -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_textinput(Editor_state, 'g') -- polygon mode + edit.run_after_text_input(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_textinput(Editor_state, 'p') -- add point + edit.run_after_text_input(Editor_state, 'p') -- add point -- third point App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26) - edit.run_after_textinput(Editor_state, 'p') -- add point + edit.run_after_text_input(Editor_state, 'p') -- add point -- fourth point edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1) local drawing = Editor_state.lines[1] @@ -626,10 +626,10 @@ function test_delete_point_from_polygon() edit.draw(Editor_state) -- first point edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) - edit.run_after_textinput(Editor_state, 'g') -- polygon mode + edit.run_after_text_input(Editor_state, 'g') -- polygon mode -- second point App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36) - edit.run_after_textinput(Editor_state, 'p') -- add point + edit.run_after_text_input(Editor_state, 'p') -- add point -- third point edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1) local drawing = Editor_state.lines[1] @@ -671,7 +671,7 @@ function test_undo_name_point() --? print('a', Editor_state.lines.current_drawing) -- enter 'name' mode without moving the mouse edit.run_after_keychord(Editor_state, 'C-n') - edit.run_after_textinput(Editor_state, 'A') + edit.run_after_text_input(Editor_state, 'A') edit.run_after_keychord(Editor_state, 'return') check_eq(p2.name, 'A', 'F - test_undo_name_point/baseline') check_eq(#Editor_state.history, 3, 'F - test_undo_name_point/baseline/history:2') diff --git a/edit.lua b/edit.lua index 4945529..ed5a79f 100644 --- a/edit.lua +++ b/edit.lua @@ -214,7 +214,7 @@ function edit.mouse_pressed(State, x,y, mouse_button) -- sets cursor -- press and hold to start a selection: sets selection on press, cursor on release -- press and hold, then press shift: ignore shift - -- i.e. mouse_released should never look at shift state + -- i.e. mouse_release should never look at shift state State.old_cursor1 = State.cursor1 State.old_selection1 = State.selection1 State.mousepress_shift = App.shift_down() @@ -238,11 +238,11 @@ function edit.mouse_pressed(State, x,y, mouse_button) end end -function edit.mouse_released(State, x,y, mouse_button) +function edit.mouse_release(State, x,y, mouse_button) if State.search_term then return end --? print('release') if State.lines.current_drawing then - Drawing.mouse_released(State, x,y, mouse_button) + Drawing.mouse_release(State, x,y, mouse_button) schedule_save(State) if Drawing.before then record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)}) @@ -277,7 +277,7 @@ function edit.mouse_released(State, x,y, mouse_button) end end -function edit.textinput(State, t) +function edit.text_input(State, t) if State.search_term then State.search_term = State.search_term..t State.search_text = nil @@ -292,13 +292,13 @@ function edit.textinput(State, t) local drawing_index, drawing = Drawing.current_drawing(State) if drawing_index == nil then for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll - Text.textinput(State, t) + Text.text_input(State, t) end end schedule_save(State) end -function edit.keychord_pressed(State, chord, key) +function edit.keychord_press(State, chord, key) if State.selection1.line and not State.lines.current_drawing and -- printable character created using shift key => delete selection @@ -422,7 +422,7 @@ function edit.keychord_pressed(State, chord, key) local drawing_index, drawing = Drawing.current_drawing(State) if drawing_index then local before = snapshot(State, drawing_index) - Drawing.keychord_pressed(State, chord) + Drawing.keychord_press(State, chord) record_undo_event(State, {before=before, after=snapshot(State, drawing_index)}) schedule_save(State) end @@ -454,11 +454,11 @@ function edit.keychord_pressed(State, chord, key) schedule_save(State) else for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll - Text.keychord_pressed(State, chord) + Text.keychord_press(State, chord) end end -function edit.key_released(State, key, scancode) +function edit.key_release(State, key, scancode) end function edit.update_font_settings(State, font_height) @@ -486,21 +486,21 @@ function edit.initialize_test_state() 15) -- line height end --- all textinput events are also keypresses +-- all text_input events are also keypresses -- TODO: handle chords of multiple keys -function edit.run_after_textinput(State, t) - edit.keychord_pressed(State, t) - edit.textinput(State, t) - edit.key_released(State, t) +function edit.run_after_text_input(State, t) + edit.keychord_press(State, t) + edit.text_input(State, t) + edit.key_release(State, t) App.screen.contents = {} edit.update(State, 0) edit.draw(State) end --- not all keys are textinput +-- not all keys are text_input function edit.run_after_keychord(State, chord) - edit.keychord_pressed(State, chord) - edit.key_released(State, chord) + edit.keychord_press(State, chord) + edit.key_release(State, chord) App.screen.contents = {} edit.update(State, 0) edit.draw(State) @@ -510,7 +510,7 @@ function edit.run_after_mouse_click(State, x,y, mouse_button) App.fake_mouse_press(x,y, mouse_button) edit.mouse_pressed(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) - edit.mouse_released(State, x,y, mouse_button) + edit.mouse_release(State, x,y, mouse_button) App.screen.contents = {} edit.update(State, 0) edit.draw(State) @@ -526,7 +526,7 @@ end function edit.run_after_mouse_release(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) - edit.mouse_released(State, x,y, mouse_button) + edit.mouse_release(State, x,y, mouse_button) App.screen.contents = {} edit.update(State, 0) edit.draw(State) diff --git a/keychord.lua b/keychord.lua index 7be57d2..3b43519 100644 --- a/keychord.lua +++ b/keychord.lua @@ -8,7 +8,7 @@ function App.keypressed(key, scancode, isrepeat) return end -- include the modifier(s) when the non-modifer is pressed - App.keychord_pressed(App.combine_modifiers(key), key) + App.keychord_press(App.combine_modifiers(key), key) end function App.combine_modifiers(key) diff --git a/log_browser.lua b/log_browser.lua index 91f02eb..eb6c120 100644 --- a/log_browser.lua +++ b/log_browser.lua @@ -262,13 +262,13 @@ function log_browser.line_index(State, mx,my) end end -function log_browser.mouse_released(State, x,y, mouse_button) +function log_browser.mouse_release(State, x,y, mouse_button) end -function log_browser.textinput(State, t) +function log_browser.text_input(State, t) end -function log_browser.keychord_pressed(State, chord, key) +function log_browser.keychord_press(State, chord, key) -- move if chord == 'up' then while State.screen_top1.line > 1 do @@ -319,5 +319,5 @@ function log_browser.height(State, line_index) end end -function log_browser.keyreleased(State, key, scancode) +function log_browser.key_release(State, key, scancode) end diff --git a/main.lua b/main.lua index 7c3a482..c078f10 100644 --- a/main.lua +++ b/main.lua @@ -109,9 +109,9 @@ end function App.filedropped(file) if Current_app == 'run' then - if run.filedropped then run.filedropped(file) end + if run.file_drop then run.file_drop(file) end elseif Current_app == 'source' then - if source.filedropped then source.filedropped(file) end + if source.file_drop then source.file_drop(file) end else assert(false, 'unknown app "'..Current_app..'"') end @@ -156,7 +156,7 @@ function App.update(dt) end end -function App.keychord_pressed(chord, key) +function App.keychord_press(chord, key) -- ignore events for some time after window in focus (mostly alt-tab) if Current_time < Last_focus_time + 0.01 then return @@ -186,9 +186,9 @@ function App.keychord_pressed(chord, key) return end if Current_app == 'run' then - if run.keychord_pressed then run.keychord_pressed(chord, key) end + if run.keychord_press then run.keychord_press(chord, key) end elseif Current_app == 'source' then - if source.keychord_pressed then source.keychord_pressed(chord, key) end + if source.keychord_press then source.keychord_press(chord, key) end else assert(false, 'unknown app "'..Current_app..'"') end @@ -201,9 +201,9 @@ function App.textinput(t) end -- if Current_app == 'run' then - if run.textinput then run.textinput(t) end + if run.text_input then run.text_input(t) end elseif Current_app == 'source' then - if source.textinput then source.textinput(t) end + if source.text_input then source.text_input(t) end else assert(false, 'unknown app "'..Current_app..'"') end @@ -216,9 +216,9 @@ function App.keyreleased(chord, key) end -- if Current_app == 'run' then - if run.key_released then run.key_released(chord, key) end + if run.key_release then run.key_release(chord, key) end elseif Current_app == 'source' then - if source.key_released then source.key_released(chord, key) end + if source.key_release then source.key_release(chord, key) end else assert(false, 'unknown app "'..Current_app..'"') end @@ -237,9 +237,9 @@ end function App.mousereleased(x,y, mouse_button) if Current_app == 'run' then - if run.mouse_released then run.mouse_released(x,y, mouse_button) end + if run.mouse_release then run.mouse_release(x,y, mouse_button) end elseif Current_app == 'source' then - if source.mouse_released then source.mouse_released(x,y, mouse_button) end + if source.mouse_release then source.mouse_release(x,y, mouse_button) end else assert(false, 'unknown app "'..Current_app..'"') end diff --git a/run.lua b/run.lua index 3a17225..0bbcdc7 100644 --- a/run.lua +++ b/run.lua @@ -105,7 +105,7 @@ function run.resize(w, h) Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right) end -function run.filedropped(file) +function run.file_drop(file) -- first make sure to save edits on any existing file if Editor_state.next_save then save_to_disk(Editor_state) @@ -159,24 +159,24 @@ function run.mouse_pressed(x,y, mouse_button) return edit.mouse_pressed(Editor_state, x,y, mouse_button) end -function run.mouse_released(x,y, mouse_button) +function run.mouse_release(x,y, mouse_button) Cursor_time = 0 -- ensure cursor is visible immediately after it moves - return edit.mouse_released(Editor_state, x,y, mouse_button) + return edit.mouse_release(Editor_state, x,y, mouse_button) end -function run.textinput(t) +function run.text_input(t) Cursor_time = 0 -- ensure cursor is visible immediately after it moves - return edit.textinput(Editor_state, t) + return edit.text_input(Editor_state, t) end -function run.keychord_pressed(chord, key) +function run.keychord_press(chord, key) Cursor_time = 0 -- ensure cursor is visible immediately after it moves - return edit.keychord_pressed(Editor_state, chord, key) + return edit.keychord_press(Editor_state, chord, key) end -function run.key_released(key, scancode) +function run.key_release(key, scancode) Cursor_time = 0 -- ensure cursor is visible immediately after it moves - return edit.key_released(Editor_state, key, scancode) + return edit.key_release(Editor_state, key, scancode) end -- use this sparingly diff --git a/source.lua b/source.lua index f34c663..0e1d478 100644 --- a/source.lua +++ b/source.lua @@ -197,7 +197,7 @@ function source.resize(w, h) --? print('end resize') end -function source.filedropped(file) +function source.file_drop(file) -- first make sure to save edits on any existing file if Editor_state.next_save then save_to_disk(Editor_state) @@ -213,7 +213,7 @@ function source.filedropped(file) love.window.setTitle('lines.love - source') end --- a copy of source.filedropped when given a filename +-- a copy of source.file_drop when given a filename function source.switch_to_file(filename) -- first make sure to save edits on any existing file if Editor_state.next_save then @@ -313,33 +313,33 @@ function source.mouse_pressed(x,y, mouse_button) end end -function source.mouse_released(x,y, mouse_button) +function source.mouse_release(x,y, mouse_button) Cursor_time = 0 -- ensure cursor is visible immediately after it moves if Focus == 'edit' then - return edit.mouse_released(Editor_state, x,y, mouse_button) + return edit.mouse_release(Editor_state, x,y, mouse_button) else - return log_browser.mouse_released(Log_browser_state, x,y, mouse_button) + return log_browser.mouse_release(Log_browser_state, x,y, mouse_button) end end -function source.textinput(t) +function source.text_input(t) Cursor_time = 0 -- ensure cursor is visible immediately after it moves if Show_file_navigator then - textinput_on_file_navigator(t) + text_input_on_file_navigator(t) return end if Focus == 'edit' then - return edit.textinput(Editor_state, t) + return edit.text_input(Editor_state, t) else - return log_browser.textinput(Log_browser_state, t) + return log_browser.text_input(Log_browser_state, t) end end -function source.keychord_pressed(chord, key) +function source.keychord_press(chord, key) Cursor_time = 0 -- ensure cursor is visible immediately after it moves --? print('source keychord') if Show_file_navigator then - keychord_pressed_on_file_navigator(chord, key) + keychord_press_on_file_navigator(chord, key) return end if chord == 'C-l' then @@ -380,18 +380,18 @@ function source.keychord_pressed(chord, key) return end if Focus == 'edit' then - return edit.keychord_pressed(Editor_state, chord, key) + return edit.keychord_press(Editor_state, chord, key) else - return log_browser.keychord_pressed(Log_browser_state, chord, key) + return log_browser.keychord_press(Log_browser_state, chord, key) end end -function source.key_released(key, scancode) +function source.key_release(key, scancode) Cursor_time = 0 -- ensure cursor is visible immediately after it moves if Focus == 'edit' then - return edit.key_released(Editor_state, key, scancode) + return edit.key_release(Editor_state, key, scancode) else - return log_browser.keychord_pressed(Log_browser_state, chordkey, scancode) + return log_browser.keychord_press(Log_browser_state, chordkey, scancode) end end diff --git a/source_edit.lua b/source_edit.lua index 8c1b37d..53fb232 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -227,7 +227,7 @@ function edit.mouse_pressed(State, x,y, mouse_button) -- sets cursor -- press and hold to start a selection: sets selection on press, cursor on release -- press and hold, then press shift: ignore shift - -- i.e. mouse_released should never look at shift state + -- i.e. mouse_release should never look at shift state State.old_cursor1 = State.cursor1 State.old_selection1 = State.selection1 State.mousepress_shift = App.shift_down() @@ -250,11 +250,11 @@ function edit.mouse_pressed(State, x,y, mouse_button) end end -function edit.mouse_released(State, x,y, mouse_button) +function edit.mouse_release(State, x,y, mouse_button) if State.search_term then return end --? print('release') if State.lines.current_drawing then - Drawing.mouse_released(State, x,y, mouse_button) + Drawing.mouse_release(State, x,y, mouse_button) schedule_save(State) if Drawing.before then record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)}) @@ -287,7 +287,7 @@ function edit.mouse_released(State, x,y, mouse_button) end end -function edit.textinput(State, t) +function edit.text_input(State, t) if State.search_term then State.search_term = State.search_term..t State.search_text = nil @@ -302,13 +302,13 @@ function edit.textinput(State, t) local drawing_index, drawing = Drawing.current_drawing(State) if drawing_index == nil then for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll - Text.textinput(State, t) + Text.text_input(State, t) end end schedule_save(State) end -function edit.keychord_pressed(State, chord, key) +function edit.keychord_press(State, chord, key) if State.selection1.line and not State.lines.current_drawing and -- printable character created using shift key => delete selection @@ -461,7 +461,7 @@ function edit.keychord_pressed(State, chord, key) local drawing_index, drawing = Drawing.current_drawing(State) if drawing_index then local before = snapshot(State, drawing_index) - Drawing.keychord_pressed(State, chord) + Drawing.keychord_press(State, chord) record_undo_event(State, {before=before, after=snapshot(State, drawing_index)}) schedule_save(State) end @@ -493,7 +493,7 @@ function edit.keychord_pressed(State, chord, key) schedule_save(State) else for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll - Text.keychord_pressed(State, chord) + Text.keychord_press(State, chord) end end @@ -511,7 +511,7 @@ function edit.eradicate_locations_after_the_fold(State) end end -function edit.key_released(State, key, scancode) +function edit.key_release(State, key, scancode) end function edit.update_font_settings(State, font_height) @@ -539,21 +539,21 @@ function edit.initialize_test_state() 15) -- line height end --- all textinput events are also keypresses +-- all text_input events are also keypresses -- TODO: handle chords of multiple keys -function edit.run_after_textinput(State, t) - edit.keychord_pressed(State, t) - edit.textinput(State, t) - edit.key_released(State, t) +function edit.run_after_text_input(State, t) + edit.keychord_press(State, t) + edit.text_input(State, t) + edit.key_release(State, t) App.screen.contents = {} edit.update(State, 0) edit.draw(State) end --- not all keys are textinput +-- not all keys are text_input function edit.run_after_keychord(State, chord) - edit.keychord_pressed(State, chord) - edit.key_released(State, chord) + edit.keychord_press(State, chord) + edit.key_release(State, chord) App.screen.contents = {} edit.update(State, 0) edit.draw(State) @@ -563,7 +563,7 @@ function edit.run_after_mouse_click(State, x,y, mouse_button) App.fake_mouse_press(x,y, mouse_button) edit.mouse_pressed(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) - edit.mouse_released(State, x,y, mouse_button) + edit.mouse_release(State, x,y, mouse_button) App.screen.contents = {} edit.update(State, 0) edit.draw(State) @@ -579,7 +579,7 @@ end function edit.run_after_mouse_release(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) - edit.mouse_released(State, x,y, mouse_button) + edit.mouse_release(State, x,y, mouse_button) App.screen.contents = {} edit.update(State, 0) edit.draw(State) diff --git a/source_text.lua b/source_text.lua index 3e70343..71f4f7b 100644 --- a/source_text.lua +++ b/source_text.lua @@ -353,7 +353,7 @@ function Text.compute_fragmentsB(State, line_index, x) end end -function Text.textinput(State, t) +function Text.text_input(State, t) if App.mouse_down(1) then return end if App.ctrl_down() or App.alt_down() or App.cmd_down() then return end local before = snapshot(State, State.cursor1.line) @@ -381,8 +381,8 @@ function Text.insert_at_cursor(State, t) end end --- Don't handle any keys here that would trigger love.textinput above. -function Text.keychord_pressed(State, chord) +-- Don't handle any keys here that would trigger text_input above. +function Text.keychord_press(State, chord) --? print('chord', chord, State.selection1.line, State.selection1.pos) --== shortcuts that mutate text if chord == 'return' then diff --git a/source_text_tests.lua b/source_text_tests.lua index b8ffa7f..64f041f 100644 --- a/source_text_tests.lua +++ b/source_text_tests.lua @@ -65,7 +65,7 @@ function test_insert_first_character() Editor_state.lines = load_array{} Text.redraw_all(Editor_state) edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') local y = Editor_state.top App.screen.check(y, 'a', 'F - test_insert_first_character/screen:1') end @@ -606,8 +606,8 @@ function test_select_text() App.fake_key_press('lshift') edit.run_after_keychord(Editor_state, 'S-right') App.fake_key_release('lshift') - edit.key_released(Editor_state, 'lshift') - -- selection persists even after shift is released + edit.key_release(Editor_state, 'lshift') + -- selection persists even after shift is release check_eq(Editor_state.selection1.line, 1, 'F - test_select_text/selection:line') check_eq(Editor_state.selection1.pos, 1, 'F - test_select_text/selection:pos') check_eq(Editor_state.cursor1.line, 1, 'F - test_select_text/cursor:line') @@ -646,7 +646,7 @@ function test_edit_deletes_selection() Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- press a key - edit.run_after_textinput(Editor_state, 'x') + edit.run_after_text_input(Editor_state, 'x') -- selected text is deleted and replaced with the key check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_edit_deletes_selection') end @@ -665,9 +665,9 @@ function test_edit_with_shift_key_deletes_selection() edit.draw(Editor_state) -- mimic precise keypresses for a capital letter App.fake_key_press('lshift') - edit.keychord_pressed(Editor_state, 'd', 'd') - edit.textinput(Editor_state, 'D') - edit.key_released(Editor_state, 'd') + edit.keychord_press(Editor_state, 'd', 'd') + edit.text_input(Editor_state, 'D') + edit.key_release(Editor_state, 'd') App.fake_key_release('lshift') -- selected text is deleted and replaced with the key check_nil(Editor_state.selection1.line, 'F - test_edit_with_shift_key_deletes_selection') @@ -769,7 +769,7 @@ function test_edit_wrapping_text() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'g') + edit.run_after_text_input(Editor_state, 'g') local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_edit_wrapping_text/screen:1') y = y + Editor_state.line_height @@ -1503,7 +1503,7 @@ function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bot Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- after hitting the inserting_text key the screen does not scroll down - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') check_eq(Editor_state.screen_top1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top') check_eq(Editor_state.cursor1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line') check_eq(Editor_state.cursor1.pos, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos') @@ -1529,9 +1529,9 @@ function test_typing_on_bottom_line_scrolls_down() y = y + Editor_state.line_height App.screen.check(y, 'ghi', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:3') -- after typing something the line wraps and the screen scrolls down - edit.run_after_textinput(Editor_state, 'j') - edit.run_after_textinput(Editor_state, 'k') - edit.run_after_textinput(Editor_state, 'l') + edit.run_after_text_input(Editor_state, 'j') + edit.run_after_text_input(Editor_state, 'k') + edit.run_after_text_input(Editor_state, 'l') check_eq(Editor_state.screen_top1.line, 2, 'F - test_typing_on_bottom_line_scrolls_down/screen_top') check_eq(Editor_state.cursor1.line, 3, 'F - test_typing_on_bottom_line_scrolls_down/cursor:line') check_eq(Editor_state.cursor1.pos, 7, 'F - test_typing_on_bottom_line_scrolls_down/cursor:pos') @@ -1683,9 +1683,9 @@ function test_position_cursor_on_recently_edited_wrapping_line() y = y + Editor_state.line_height App.screen.check(y, 'xyz', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:3') -- add to the line until it's wrapping over 3 screen lines - edit.run_after_textinput(Editor_state, 's') - edit.run_after_textinput(Editor_state, 't') - edit.run_after_textinput(Editor_state, 'u') + edit.run_after_text_input(Editor_state, 's') + edit.run_after_text_input(Editor_state, 't') + edit.run_after_text_input(Editor_state, 'u') check_eq(Editor_state.cursor1.pos, 28, 'F - test_position_cursor_on_recently_edited_wrapping_line/cursor:pos') y = Editor_state.top App.screen.check(y, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:1') @@ -1883,7 +1883,7 @@ function test_undo_insert_text() Editor_state.screen_bottom1 = {} -- insert a character edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'g') + edit.run_after_text_input(Editor_state, 'g') check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_insert_text/baseline/cursor:line') check_eq(Editor_state.cursor1.pos, 5, 'F - test_undo_insert_text/baseline/cursor:pos') check_nil(Editor_state.selection1.line, 'F - test_undo_insert_text/baseline/selection:line') @@ -1959,7 +1959,7 @@ function test_undo_restores_selection() Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- delete selected text - edit.run_after_textinput(Editor_state, 'x') + edit.run_after_text_input(Editor_state, 'x') check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_undo_restores_selection/baseline') check_nil(Editor_state.selection1.line, 'F - test_undo_restores_selection/baseline:selection') -- undo @@ -1982,7 +1982,7 @@ function test_search() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'd') + edit.run_after_text_input(Editor_state, 'd') edit.run_after_keychord(Editor_state, 'return') check_eq(Editor_state.cursor1.line, 2, 'F - test_search/1/cursor:line') check_eq(Editor_state.cursor1.pos, 1, 'F - test_search/1/cursor:pos') @@ -1991,7 +1991,7 @@ function test_search() Editor_state.screen_top1 = {line=1, pos=1} -- search for second occurrence edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'de') + edit.run_after_text_input(Editor_state, 'de') edit.run_after_keychord(Editor_state, 'down') edit.run_after_keychord(Editor_state, 'return') check_eq(Editor_state.cursor1.line, 4, 'F - test_search/2/cursor:line') @@ -2010,7 +2010,7 @@ function test_search_upwards() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') -- search for previous occurrence edit.run_after_keychord(Editor_state, 'up') check_eq(Editor_state.cursor1.line, 1, 'F - test_search_upwards/2/cursor:line') @@ -2029,7 +2029,7 @@ function test_search_wrap() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') edit.run_after_keychord(Editor_state, 'return') -- cursor wraps check_eq(Editor_state.cursor1.line, 1, 'F - test_search_wrap/1/cursor:line') @@ -2048,7 +2048,7 @@ function test_search_wrap_upwards() edit.draw(Editor_state) -- search upwards for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') edit.run_after_keychord(Editor_state, 'up') -- cursor wraps check_eq(Editor_state.cursor1.line, 1, 'F - test_search_wrap_upwards/1/cursor:line') diff --git a/text.lua b/text.lua index 9720bfa..8232335 100644 --- a/text.lua +++ b/text.lua @@ -147,7 +147,7 @@ function Text.compute_fragments(State, line_index) end end -function Text.textinput(State, t) +function Text.text_input(State, t) if App.mouse_down(1) then return end if App.ctrl_down() or App.alt_down() or App.cmd_down() then return end local before = snapshot(State, State.cursor1.line) @@ -168,8 +168,8 @@ function Text.insert_at_cursor(State, t) State.cursor1.pos = State.cursor1.pos+1 end --- Don't handle any keys here that would trigger love.textinput above. -function Text.keychord_pressed(State, chord) +-- Don't handle any keys here that would trigger text_input above. +function Text.keychord_press(State, chord) --? print('chord', chord, State.selection1.line, State.selection1.pos) --== shortcuts that mutate text if chord == 'return' then diff --git a/text_tests.lua b/text_tests.lua index d34c416..c0104ad 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -65,7 +65,7 @@ function test_insert_first_character() Editor_state.lines = load_array{} Text.redraw_all(Editor_state) edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') local y = Editor_state.top App.screen.check(y, 'a', 'F - test_insert_first_character/screen:1') end @@ -606,8 +606,8 @@ function test_select_text() App.fake_key_press('lshift') edit.run_after_keychord(Editor_state, 'S-right') App.fake_key_release('lshift') - edit.key_released(Editor_state, 'lshift') - -- selection persists even after shift is released + edit.key_release(Editor_state, 'lshift') + -- selection persists even after shift is release check_eq(Editor_state.selection1.line, 1, 'F - test_select_text/selection:line') check_eq(Editor_state.selection1.pos, 1, 'F - test_select_text/selection:pos') check_eq(Editor_state.cursor1.line, 1, 'F - test_select_text/cursor:line') @@ -646,7 +646,7 @@ function test_edit_deletes_selection() Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- press a key - edit.run_after_textinput(Editor_state, 'x') + edit.run_after_text_input(Editor_state, 'x') -- selected text is deleted and replaced with the key check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_edit_deletes_selection') end @@ -665,9 +665,9 @@ function test_edit_with_shift_key_deletes_selection() edit.draw(Editor_state) -- mimic precise keypresses for a capital letter App.fake_key_press('lshift') - edit.keychord_pressed(Editor_state, 'd', 'd') - edit.textinput(Editor_state, 'D') - edit.key_released(Editor_state, 'd') + edit.keychord_press(Editor_state, 'd', 'd') + edit.text_input(Editor_state, 'D') + edit.key_release(Editor_state, 'd') App.fake_key_release('lshift') -- selected text is deleted and replaced with the key check_nil(Editor_state.selection1.line, 'F - test_edit_with_shift_key_deletes_selection') @@ -769,7 +769,7 @@ function test_edit_wrapping_text() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'g') + edit.run_after_text_input(Editor_state, 'g') local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_edit_wrapping_text/screen:1') y = y + Editor_state.line_height @@ -1534,7 +1534,7 @@ function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bot Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- after hitting the inserting_text key the screen does not scroll down - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') check_eq(Editor_state.screen_top1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top') check_eq(Editor_state.cursor1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line') check_eq(Editor_state.cursor1.pos, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos') @@ -1560,9 +1560,9 @@ function test_typing_on_bottom_line_scrolls_down() y = y + Editor_state.line_height App.screen.check(y, 'ghi', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:3') -- after typing something the line wraps and the screen scrolls down - edit.run_after_textinput(Editor_state, 'j') - edit.run_after_textinput(Editor_state, 'k') - edit.run_after_textinput(Editor_state, 'l') + edit.run_after_text_input(Editor_state, 'j') + edit.run_after_text_input(Editor_state, 'k') + edit.run_after_text_input(Editor_state, 'l') check_eq(Editor_state.screen_top1.line, 2, 'F - test_typing_on_bottom_line_scrolls_down/screen_top') check_eq(Editor_state.cursor1.line, 3, 'F - test_typing_on_bottom_line_scrolls_down/cursor:line') check_eq(Editor_state.cursor1.pos, 7, 'F - test_typing_on_bottom_line_scrolls_down/cursor:pos') @@ -1714,9 +1714,9 @@ function test_position_cursor_on_recently_edited_wrapping_line() y = y + Editor_state.line_height App.screen.check(y, 'xyz', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:3') -- add to the line until it's wrapping over 3 screen lines - edit.run_after_textinput(Editor_state, 's') - edit.run_after_textinput(Editor_state, 't') - edit.run_after_textinput(Editor_state, 'u') + edit.run_after_text_input(Editor_state, 's') + edit.run_after_text_input(Editor_state, 't') + edit.run_after_text_input(Editor_state, 'u') check_eq(Editor_state.cursor1.pos, 28, 'F - test_position_cursor_on_recently_edited_wrapping_line/cursor:pos') y = Editor_state.top App.screen.check(y, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:1') @@ -1914,7 +1914,7 @@ function test_undo_insert_text() Editor_state.screen_bottom1 = {} -- insert a character edit.draw(Editor_state) - edit.run_after_textinput(Editor_state, 'g') + edit.run_after_text_input(Editor_state, 'g') check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_insert_text/baseline/cursor:line') check_eq(Editor_state.cursor1.pos, 5, 'F - test_undo_insert_text/baseline/cursor:pos') check_nil(Editor_state.selection1.line, 'F - test_undo_insert_text/baseline/selection:line') @@ -1990,7 +1990,7 @@ function test_undo_restores_selection() Editor_state.screen_bottom1 = {} edit.draw(Editor_state) -- delete selected text - edit.run_after_textinput(Editor_state, 'x') + edit.run_after_text_input(Editor_state, 'x') check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_undo_restores_selection/baseline') check_nil(Editor_state.selection1.line, 'F - test_undo_restores_selection/baseline:selection') -- undo @@ -2013,7 +2013,7 @@ function test_search() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'd') + edit.run_after_text_input(Editor_state, 'd') edit.run_after_keychord(Editor_state, 'return') check_eq(Editor_state.cursor1.line, 2, 'F - test_search/1/cursor:line') check_eq(Editor_state.cursor1.pos, 1, 'F - test_search/1/cursor:pos') @@ -2022,7 +2022,7 @@ function test_search() Editor_state.screen_top1 = {line=1, pos=1} -- search for second occurrence edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'de') + edit.run_after_text_input(Editor_state, 'de') edit.run_after_keychord(Editor_state, 'down') edit.run_after_keychord(Editor_state, 'return') check_eq(Editor_state.cursor1.line, 4, 'F - test_search/2/cursor:line') @@ -2041,7 +2041,7 @@ function test_search_upwards() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') -- search for previous occurrence edit.run_after_keychord(Editor_state, 'up') check_eq(Editor_state.cursor1.line, 1, 'F - test_search_upwards/2/cursor:line') @@ -2060,7 +2060,7 @@ function test_search_wrap() edit.draw(Editor_state) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') edit.run_after_keychord(Editor_state, 'return') -- cursor wraps check_eq(Editor_state.cursor1.line, 1, 'F - test_search_wrap/1/cursor:line') @@ -2079,7 +2079,7 @@ function test_search_wrap_upwards() edit.draw(Editor_state) -- search upwards for a string edit.run_after_keychord(Editor_state, 'C-f') - edit.run_after_textinput(Editor_state, 'a') + edit.run_after_text_input(Editor_state, 'a') edit.run_after_keychord(Editor_state, 'up') -- cursor wraps check_eq(Editor_state.cursor1.line, 1, 'F - test_search_wrap_upwards/1/cursor:line')