@@ -555,6 +555,42 @@ fn test_no_pair_delete_with_content_between() {
555555// Macro Recording and Playback Tests
556556// =============================================================================
557557
558+ /// Helper: open command palette, type a command, press Enter
559+ fn run_command ( harness : & mut EditorTestHarness , command : & str ) {
560+ harness
561+ . send_key ( KeyCode :: Char ( 'p' ) , KeyModifiers :: CONTROL )
562+ . unwrap ( ) ;
563+ harness. render ( ) . unwrap ( ) ;
564+ harness. type_text ( command) . unwrap ( ) ;
565+ harness. render ( ) . unwrap ( ) ;
566+ harness
567+ . send_key ( KeyCode :: Enter , KeyModifiers :: NONE )
568+ . unwrap ( ) ;
569+ harness. render ( ) . unwrap ( ) ;
570+ }
571+
572+ /// Helper: start recording a macro via command palette ("Record Macro" → register digit)
573+ fn start_recording_macro ( harness : & mut EditorTestHarness , register : char ) {
574+ run_command ( harness, "Record Macro" ) ;
575+ // The prompt asks for a register (0-9)
576+ harness. type_text ( & register. to_string ( ) ) . unwrap ( ) ;
577+ harness
578+ . send_key ( KeyCode :: Enter , KeyModifiers :: NONE )
579+ . unwrap ( ) ;
580+ harness. render ( ) . unwrap ( ) ;
581+ }
582+
583+ /// Helper: play a macro via command palette ("Play Macro" → register digit)
584+ fn play_macro_via_palette ( harness : & mut EditorTestHarness , register : char ) {
585+ run_command ( harness, "Play Macro" ) ;
586+ // The prompt asks for a register (0-9)
587+ harness. type_text ( & register. to_string ( ) ) . unwrap ( ) ;
588+ harness
589+ . send_key ( KeyCode :: Enter , KeyModifiers :: NONE )
590+ . unwrap ( ) ;
591+ harness. render ( ) . unwrap ( ) ;
592+ }
593+
558594/// Test starting and stopping macro recording
559595#[ test]
560596fn test_macro_recording_toggle ( ) {
@@ -565,11 +601,8 @@ fn test_macro_recording_toggle() {
565601 let mut harness = harness_with_auto_indent ( ) ;
566602 harness. open_file ( & file_path) . unwrap ( ) ;
567603
568- // Start recording macro 0 with Alt+Shift+0
569- harness
570- . send_key ( KeyCode :: Char ( '0' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
571- . unwrap ( ) ;
572- harness. render ( ) . unwrap ( ) ;
604+ // Start recording macro 0 via command palette
605+ start_recording_macro ( & mut harness, '0' ) ;
573606
574607 // Verify recording state through status message
575608 let status = harness
@@ -583,11 +616,8 @@ fn test_macro_recording_toggle() {
583616 status
584617 ) ;
585618
586- // Stop recording by toggling again (Alt+Shift+0)
587- harness
588- . send_key ( KeyCode :: Char ( '0' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
589- . unwrap ( ) ;
590- harness. render ( ) . unwrap ( ) ;
619+ // Stop recording by toggling again via command palette
620+ start_recording_macro ( & mut harness, '0' ) ;
591621
592622 let status = harness
593623 . editor ( )
@@ -614,11 +644,8 @@ fn test_macro_record_and_playback() {
614644 // Position at beginning of line 1
615645 harness. send_key ( KeyCode :: Home , KeyModifiers :: NONE ) . unwrap ( ) ;
616646
617- // Start recording macro 1
618- harness
619- . send_key ( KeyCode :: Char ( '1' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
620- . unwrap ( ) ;
621- harness. render ( ) . unwrap ( ) ;
647+ // Start recording macro 1 via command palette
648+ start_recording_macro ( & mut harness, '1' ) ;
622649
623650 // Record actions: go to end of line, type "!"
624651 harness. send_key ( KeyCode :: End , KeyModifiers :: NONE ) . unwrap ( ) ;
@@ -628,10 +655,8 @@ fn test_macro_record_and_playback() {
628655 harness. send_key ( KeyCode :: Down , KeyModifiers :: NONE ) . unwrap ( ) ;
629656 harness. send_key ( KeyCode :: Home , KeyModifiers :: NONE ) . unwrap ( ) ;
630657
631- // Stop recording by toggling again (Alt+Shift+1)
632- harness
633- . send_key ( KeyCode :: Char ( '1' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
634- . unwrap ( ) ;
658+ // Stop recording with F5
659+ harness. send_key ( KeyCode :: F ( 5 ) , KeyModifiers :: NONE ) . unwrap ( ) ;
635660 harness. render ( ) . unwrap ( ) ;
636661
637662 let content = harness. get_buffer_content ( ) . unwrap ( ) ;
@@ -642,11 +667,8 @@ fn test_macro_record_and_playback() {
642667 content
643668 ) ;
644669
645- // Play macro 1 with Ctrl+1 to process line2
646- harness
647- . send_key ( KeyCode :: Char ( '1' ) , KeyModifiers :: CONTROL )
648- . unwrap ( ) ;
649- harness. render ( ) . unwrap ( ) ;
670+ // Play macro 1 via command palette to process line2
671+ play_macro_via_palette ( & mut harness, '1' ) ;
650672
651673 let content = harness. get_buffer_content ( ) . unwrap ( ) ;
652674 // line2 should now have "!" appended
@@ -657,10 +679,7 @@ fn test_macro_record_and_playback() {
657679 ) ;
658680
659681 // Play macro again for line3
660- harness
661- . send_key ( KeyCode :: Char ( '1' ) , KeyModifiers :: CONTROL )
662- . unwrap ( ) ;
663- harness. render ( ) . unwrap ( ) ;
682+ play_macro_via_palette ( & mut harness, '1' ) ;
664683
665684 let content = harness. get_buffer_content ( ) . unwrap ( ) ;
666685 // line3 should now have "!" appended
@@ -681,11 +700,8 @@ fn test_multiple_macro_slots() {
681700 let mut harness = harness_with_auto_indent ( ) ;
682701 harness. open_file ( & file_path) . unwrap ( ) ;
683702
684- // Record macro in slot 5
685- harness
686- . send_key ( KeyCode :: Char ( '5' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
687- . unwrap ( ) ;
688- harness. render ( ) . unwrap ( ) ;
703+ // Record macro in slot 5 via command palette
704+ start_recording_macro ( & mut harness, '5' ) ;
689705
690706 let status = harness
691707 . editor ( )
@@ -700,13 +716,11 @@ fn test_multiple_macro_slots() {
700716
701717 // Stop recording
702718 harness. send_key ( KeyCode :: F ( 5 ) , KeyModifiers :: NONE ) . unwrap ( ) ;
703-
704- // Record macro in slot 9
705- harness
706- . send_key ( KeyCode :: Char ( '9' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
707- . unwrap ( ) ;
708719 harness. render ( ) . unwrap ( ) ;
709720
721+ // Record macro in slot 9 via command palette
722+ start_recording_macro ( & mut harness, '9' ) ;
723+
710724 let status = harness
711725 . editor ( )
712726 . get_status_message ( )
@@ -731,13 +745,8 @@ fn test_play_nonexistent_macro() {
731745 let mut harness = harness_with_auto_indent ( ) ;
732746 harness. open_file ( & file_path) . unwrap ( ) ;
733747
734- // Try to play macro 8 (which was never recorded)
735- // Note: We use 8 instead of 7 because Ctrl+7 is now mapped to toggle_comment
736- // (as the terminal equivalent of Ctrl+/)
737- harness
738- . send_key ( KeyCode :: Char ( '8' ) , KeyModifiers :: CONTROL )
739- . unwrap ( ) ;
740- harness. render ( ) . unwrap ( ) ;
748+ // Try to play macro 8 (which was never recorded) via command palette
749+ play_macro_via_palette ( & mut harness, '8' ) ;
741750
742751 let status = harness
743752 . editor ( )
@@ -765,11 +774,8 @@ fn test_toggle_macro_recording() {
765774 let mut harness = harness_with_auto_indent ( ) ;
766775 harness. open_file ( & file_path) . unwrap ( ) ;
767776
768- // Toggle ON - start recording
769- harness
770- . send_key ( KeyCode :: Char ( '2' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
771- . unwrap ( ) ;
772- harness. render ( ) . unwrap ( ) ;
777+ // Toggle ON - start recording via command palette
778+ start_recording_macro ( & mut harness, '2' ) ;
773779
774780 let status = harness
775781 . editor ( )
@@ -782,11 +788,8 @@ fn test_toggle_macro_recording() {
782788 status
783789 ) ;
784790
785- // Toggle OFF - stop recording
786- harness
787- . send_key ( KeyCode :: Char ( '2' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
788- . unwrap ( ) ;
789- harness. render ( ) . unwrap ( ) ;
791+ // Toggle OFF - toggle same register via command palette
792+ start_recording_macro ( & mut harness, '2' ) ;
790793
791794 let status = harness
792795 . editor ( )
@@ -811,11 +814,8 @@ fn test_macro_recording_hint_shows_correct_keybinding() {
811814 let mut harness = harness_with_auto_indent ( ) ;
812815 harness. open_file ( & file_path) . unwrap ( ) ;
813816
814- // Start recording macro 1 using Alt+Shift+1
815- harness
816- . send_key ( KeyCode :: Char ( '1' ) , KeyModifiers :: ALT | KeyModifiers :: SHIFT )
817- . unwrap ( ) ;
818- harness. render ( ) . unwrap ( ) ;
817+ // Start recording macro 1 via command palette
818+ start_recording_macro ( & mut harness, '1' ) ;
819819
820820 // Get the status message
821821 let status = harness
@@ -862,9 +862,11 @@ fn test_macro_recording_hint_shows_correct_keybinding() {
862862 status_after
863863 ) ;
864864
865- // The saved message should also contain a play hint mentioning command palette
865+ // The saved message should also contain a play hint mentioning F4 or command palette
866866 assert ! (
867- status_after. contains( "Ctrl+P" ) || status_after. contains( "Play" ) ,
867+ status_after. contains( "Ctrl+P" )
868+ || status_after. contains( "Play" )
869+ || status_after. contains( "F4" ) ,
868870 "Saved message should mention how to play macro, got: {}" ,
869871 status_after
870872 ) ;
0 commit comments