diff --git a/4coder_scope_commands.cpp b/4coder_scope_commands.cpp index a695c9bd..3a286b42 100644 --- a/4coder_scope_commands.cpp +++ b/4coder_scope_commands.cpp @@ -39,7 +39,7 @@ find_scope_top(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flag b32 success = false; Token_Array array = get_token_array_from_buffer(app, buffer); if (array.tokens != 0){ - i64 position = 0; + i64 position = start_pos; i64 token_index = token_index_from_pos(&array, start_pos); Token_Iterator_Array it = token_iterator_index(buffer, &array, token_index); b32 good_status = true; @@ -73,7 +73,7 @@ find_scope_top(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flag good_status = token_it_dec(&it); } finished:; - *end_pos_out = start_pos; + *end_pos_out = position; } return(success); } @@ -83,7 +83,7 @@ find_scope_bottom(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 f b32 success = false; Token_Array array = get_token_array_from_buffer(app, buffer); if (array.tokens != 0){ - i64 position = 0; + i64 position = start_pos; i64 token_index = token_index_from_pos(&array, start_pos); Token_Iterator_Array it = token_iterator_index(buffer, &array, token_index); token_it_inc(&it); @@ -118,7 +118,7 @@ find_scope_bottom(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 f good_status = token_it_inc(&it); } finished:; - *end_pos_out = start_pos; + *end_pos_out = position; } return(success); } @@ -128,7 +128,7 @@ find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla b32 success = false; Token_Array array = get_token_array_from_buffer(app, buffer); if (array.tokens != 0){ - i64 position = 0; + i64 position = start_pos; i64 token_index = token_index_from_pos(&array, start_pos); Token_Iterator_Array it = token_iterator_index(buffer, &array, token_index); token_it_inc(&it); @@ -182,7 +182,7 @@ find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla } } finished:; - *end_pos_out = start_pos; + *end_pos_out = position; } return(success); } @@ -192,7 +192,7 @@ find_prev_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla b32 success = false; Token_Array array = get_token_array_from_buffer(app, buffer); if (array.tokens != 0){ - i64 position = 0; + i64 position = start_pos; i64 token_index = token_index_from_pos(&array, start_pos); Token_Iterator_Array it = token_iterator_index(buffer, &array, token_index); if (HasFlag(flags, FindScope_NextSibling)){ diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 0ab77569..fb9e61f4 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -552,10 +552,11 @@ buffer_cursor_from_line_col(Gap_Buffer *buffer, i64 line, i64 col){ i64 size = buffer_size(buffer); i64 line_index = line - 1; i64 line_count = buffer_line_count(buffer); - line_index = clamp(0, line_index, line_count); + line_index = clamp(0, line_index, line_count - 1); i64 this_start = buffer->line_starts[line_index]; i64 max_col = (buffer->line_starts[line_index + 1] - this_start); + max_col = clamp_bot(1, max_col); if (col < 0){ if (-col > max_col){