diff --git a/edit.lua b/edit.lua index ae9c161..be7f5a8 100644 --- a/edit.lua +++ b/edit.lua @@ -366,9 +366,8 @@ function edit.keychord_press(State, chord, key, readonly) local before = snapshot(State, before_line) local clipboard_data = App.get_clipboard() Text.insert_text(State, clipboard_data) - schedule_save(State) record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)}) - -- dispatch to text + schedule_save(State) else Text.keychord_press(State, chord, readonly) end diff --git a/text.lua b/text.lua index 40891c3..70b197f 100644 --- a/text.lua +++ b/text.lua @@ -156,7 +156,7 @@ function Text.text_input(State, t) if App.mouse_down(1) then return end if App.any_modifier_down() then if App.key_down(t) then - -- The modifiers didn't change the key. Handle it in keychord_pressed. + -- The modifiers didn't change the key. Handle it in keychord_press. return else -- Key mutated by the keyboard layout. Continue below. @@ -183,17 +183,16 @@ end function Text.keychord_press(State, chord, readonly) --? print('chord', chord, State.selection1.line, State.selection1.pos) if not readonly then - --== shortcuts that mutate text + --== shortcuts that mutate text (must schedule_save) if chord == 'return' then local before_line = State.cursor1.line local before = snapshot(State, before_line) Text.insert_return(State) - State.selection1 = {} if State.cursor_y > State.bottom - State.line_height then Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right) end - schedule_save(State) record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)}) + schedule_save(State) elseif chord == 'tab' then local before = snapshot(State, State.cursor1.line) --? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) @@ -203,8 +202,8 @@ function Text.keychord_press(State, chord, readonly) Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right) --? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) end - schedule_save(State) record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)}) + schedule_save(State) elseif chord == 'backspace' then if State.selection1.line then Text.delete_selection(State, State.left, State.right) @@ -246,8 +245,8 @@ function Text.keychord_press(State, chord, readonly) end Text.refresh_screen_line_cache(State, State.cursor1.line) assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)) - schedule_save(State) record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)}) + schedule_save(State) elseif chord == 'delete' then if State.selection1.line then Text.delete_selection(State, State.left, State.right) @@ -278,8 +277,8 @@ function Text.keychord_press(State, chord, readonly) table.remove(State.line_cache, State.cursor1.line+1) end Text.refresh_screen_line_cache(State, State.cursor1.line) - schedule_save(State) record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)}) + schedule_save(State) end end --== shortcuts that move the cursor