there are currently gaps in our undo/redo functionality when it comes to stuff like deleting a selection, "hello large world" mark "large" and delete, try to press cmd+z it wont redo, but instead place a z there, which of in itself is a bug, cmd+z and shift+cmd+z should be handled as commands and not "type into the doc", review hte codebase and consult oracle to figure out best approach to fix this, use TDD approach
Undo/redo gaps with selection deletion
All done! Here's a summary of the fixes:
Summary
Fixed two undo/redo bugs using TDD approach:
Bug 1: Cmd+Z types "z" instead of triggering undo (macOS)
Root cause: The keybinding handler used ctrl but macOS Cmd key sets logo modifier.
Fix (main.rs#L1133-1143):
- Changed
ctrlto(ctrl || logo)for undo/redo shortcuts - Changed character input guard from
!ctrlto!(ctrl || logo)to prevent typing when Cmd is held
Bug 2: Undo doesn't restore text after deleting selection and typing
Root cause: When typing over a selection, two edit operations were pushed (Delete + Insert). Undo only popped one at a time.
Fix:
- Added a new
Replacevariant toEditOperationin document.rs#L8-30 that stores bothdeleted_textandinserted_text - Updated Undo/Redo handlers in update.rs#L1051-1100 to handle
Replaceatomically - Changed
InsertChar,InsertNewline, andPasteto useReplacewhen typing over a selection
Tests added:
test_cmd_z_triggers_undo_not_insert_ztest_cmd_shift_z_triggers_redo_not_insert_ztest_ctrl_z_still_works_for_undotest_undo_insert_char_over_selection_restores_original_texttest_redo_insert_char_over_selection_reapplies_replacementtest_undo_delete_backward_with_selectiontest_undo_insert_newline_over_selection
lets rapid fire implement some convenient features: cmd+d duplicate line, or selection (inserts after selection end), clicking on the status bar, should not propogate the click to the edit under it, aka, statusbar should capture the click and not not pass it through etc, TDD it out
Both features implemented successfully:
Summary
1. Cmd+D Duplicate Line/Selection
- Added
DocumentMsg::Duplicatemessage in messages.rs#L124 - Implemented handler in update.rs#L1391-1470:
- No selection: Duplicates current line below, cursor moves to duplicated line
- With selection: Duplicates selected text after selection end, cursor at end of duplicate
- Added Cmd+D keybinding in main.rs#L1252-1255
- Tests: 5 new tests for duplicate line, last line, selection, multiline selection, and undo
2. Status Bar Click Capture
- Added
is_in_status_bar()method in main.rs#L936-941 - Updated left-click handler in main.rs#L1637-1641 to ignore clicks on status bar
- Updated middle-click handler in main.rs#L1719-1723 for same protection
All 204 tests pass.
fun error, if you resize the window to be 0 width app crashes, see if we can TDD these kind of things in a seperate monkey-test file where we do random weird shit like that to try to fuzz out bugs
Done! Here's a summary:
Summary
Created Monkey Tests
Created tests/monkey_tests.rs with 23 edge case/fuzz tests:
Window Resize Edge Cases:
- Zero width, zero height, zero both, tiny (1x1), rapid resize sequences
Empty Document Edge Cases:
- All operations on empty document, repeated deletes, undo/redo spam
Extreme Cursor Positions:
- Cursor beyond line length, cursor beyond document
Selection Edge Cases:
- Inverted selection (anchor after head), selection spanning beyond document
Rapid Operation Sequences:
- Insert/delete cycles, undo during typing, alternating movements
Large Document Stress Tests:
- 10,000 line document operations, duplicating large selections
Unicode & Special Characters:
- Moving through unicode, inserting special chars (null, emoji, etc.)
Viewport Edge Cases:
- Scroll beyond document, zero visible lines
Multi-cursor Edge Cases:
- Adding many cursors, cursors at same position
Bugs Fixed
- Overflow in viewport calculations (editor.rs#L433-438) - Used
saturating_subto prevent panic whenvisible_linesis 0 - Overflow in PageDown (update.rs#L148-152) - Same fix
- Overflow in PageDownWithSelection (update.rs#L398-402) - Same fix