@@ -675,6 +675,84 @@ F4_Boundary_TokenAndWhitespace(Application_Links *app, Buffer_ID buffer,
675
675
return (result);
676
676
}
677
677
678
+ // TODO(rjf): Replace with the final one from Jack's layer.
679
+ function i64
680
+ F4_Boundary_CursorTokenOrBlankLine_TEST (Application_Links *app, Buffer_ID buffer,
681
+ Side side, Scan_Direction direction, i64 pos)
682
+ {
683
+ Scratch_Block scratch (app);
684
+
685
+ Range_i64_Array scopes = get_enclosure_ranges (app, scratch, buffer, pos, FindNest_Scope);
686
+ // NOTE(jack): The outermost scope
687
+ Range_i64 outer_scope = scopes.ranges [scopes.count - 1 ];
688
+
689
+ // NOTE(jack): As we are issuing a move command here I will assume that buffer is the active buffer.
690
+ View_ID view = get_active_view (app, Access_Always);
691
+ i64 active_cursor_pos = view_get_cursor_pos (app, view);
692
+ Token_Array tokens = get_token_array_from_buffer (app, buffer);
693
+ Token_Iterator_Array active_cursor_it = token_iterator_pos (0 , &tokens, active_cursor_pos);
694
+ Token *active_cursor_token = token_it_read (&active_cursor_it);
695
+
696
+ String_Const_u8 cursor_string = push_buffer_range (app, scratch, buffer, Ii64 (active_cursor_token));
697
+ i64 cursor_offset = pos - active_cursor_token->pos ;
698
+
699
+ // NOTE(jack): If the cursor token is not an identifier, we will move to empty lines
700
+ i64 result = get_pos_of_blank_line_grouped (app, buffer, direction, pos);
701
+ result = view_get_character_legal_pos_from_pos (app, view, result);
702
+ if (tokens.tokens != 0 )
703
+ {
704
+ // NOTE(jack): if the the cursor token is an identifier, and we are inside of a scope
705
+ // perform the cursor occurance movement.
706
+ if (active_cursor_token->kind == TokenBaseKind_Identifier && !(scopes.count == 0 ))
707
+ {
708
+ // NOTE(jack): Reset result to prevent token movement to escape to blank line movement
709
+ // when you are on the first/last token in the outermost scope.
710
+ result = pos;
711
+ Token_Iterator_Array it = token_iterator_pos (0 , &tokens, pos);
712
+
713
+ for (;;)
714
+ {
715
+ b32 done = false ;
716
+ // NOTE(jack): Incremenet first so we dont move to the same cursor that the cursor is on.
717
+ switch (direction)
718
+ {
719
+ // NOTE(jack): I am using it.ptr->pos because its easier than reading the token with
720
+ // token_it_read
721
+ case Scan_Forward:
722
+ {
723
+ if (!token_it_inc_non_whitespace (&it) || it.ptr ->pos >= outer_scope.end ) {
724
+ done = true ;
725
+ }
726
+ } break ;
727
+
728
+ case Scan_Backward:
729
+ {
730
+ if (!token_it_dec_non_whitespace (&it) || it.ptr ->pos < outer_scope.start ) {
731
+ done = true ;
732
+ }
733
+ } break ;
734
+ }
735
+
736
+ if (!done)
737
+ {
738
+ Token *token = token_it_read (&it);
739
+ String_Const_u8 token_string = push_buffer_range (app, scratch, buffer, Ii64 (token));
740
+ if (string_match (cursor_string, token_string)) {
741
+ result = token->pos + cursor_offset;
742
+ break ;
743
+ }
744
+ }
745
+ else
746
+ {
747
+ break ;
748
+ }
749
+ }
750
+ }
751
+ }
752
+
753
+ return result ;
754
+ }
755
+
678
756
CUSTOM_COMMAND_SIG (f4_move_left)
679
757
CUSTOM_DOC(" Moves the cursor one character to the left." )
680
758
{
@@ -703,6 +781,20 @@ CUSTOM_DOC("Moves the cursor one character to the right.")
703
781
no_mark_snap_to_cursor_if_shift (app, view);
704
782
}
705
783
784
+ CUSTOM_COMMAND_SIG (f4_move_up_token_occurrence)
785
+ CUSTOM_DOC(" Moves the cursor to the previous occurrence of the token that the cursor is over." )
786
+ {
787
+ Scratch_Block scratch (app);
788
+ current_view_scan_move (app, Scan_Backward, push_boundary_list (scratch, F4_Boundary_CursorTokenOrBlankLine_TEST));
789
+ }
790
+
791
+ CUSTOM_COMMAND_SIG (f4_move_down_token_occurrence)
792
+ CUSTOM_DOC(" Moves the cursor to the next occurrence of the token that the cursor is over." )
793
+ {
794
+ Scratch_Block scratch (app);
795
+ current_view_scan_move (app, Scan_Forward, push_boundary_list (scratch, F4_Boundary_CursorTokenOrBlankLine_TEST));
796
+ }
797
+
706
798
CUSTOM_COMMAND_SIG (f4_move_right_token_boundary)
707
799
CUSTOM_DOC(" Seek right for boundary between alphanumeric characters and non-alphanumeric characters." )
708
800
{
0 commit comments