Fix sticky jump crash

This commit is contained in:
Allen Webster 2018-09-20 12:21:39 -07:00
parent fd1abc2d26
commit 77a9541fc4
2 changed files with 69 additions and 54 deletions

View File

@ -269,21 +269,21 @@ static Command_Metadata fcoder_metacmd_table[208] = {
{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1168 }, { PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1168 },
{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1175 }, { PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1175 },
{ PROC_LINKS(goto_first_jump_direct, 0), "goto_first_jump_direct", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 84 }, { PROC_LINKS(goto_first_jump_direct, 0), "goto_first_jump_direct", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 84 },
{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 524 }, { PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 539 },
{ PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 506 }, { PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 521 },
{ PROC_LINKS(goto_jump_at_cursor_direct, 0), "goto_jump_at_cursor_direct", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 8 }, { PROC_LINKS(goto_jump_at_cursor_direct, 0), "goto_jump_at_cursor_direct", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 8 },
{ PROC_LINKS(goto_jump_at_cursor_same_panel_direct, 0), "goto_jump_at_cursor_same_panel_direct", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..", 168, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 29 }, { PROC_LINKS(goto_jump_at_cursor_same_panel_direct, 0), "goto_jump_at_cursor_same_panel_direct", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..", 168, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 29 },
{ PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 352 }, { PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 365 },
{ PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 324 }, { PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 337 },
{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 591 }, { PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 591 },
{ PROC_LINKS(goto_next_jump_direct, 0), "goto_next_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 48 }, { PROC_LINKS(goto_next_jump_direct, 0), "goto_next_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 48 },
{ PROC_LINKS(goto_next_jump_no_skips_direct, 0), "goto_next_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 66 }, { PROC_LINKS(goto_next_jump_no_skips_direct, 0), "goto_next_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 66 },
{ PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 475 }, { PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 490 },
{ PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 445 }, { PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 460 },
{ PROC_LINKS(goto_prev_jump_direct, 0), "goto_prev_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 57 }, { PROC_LINKS(goto_prev_jump_direct, 0), "goto_prev_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 57 },
{ PROC_LINKS(goto_prev_jump_no_skips_direct, 0), "goto_prev_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 75 }, { PROC_LINKS(goto_prev_jump_no_skips_direct, 0), "goto_prev_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 75 },
{ PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 491 }, { PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 506 },
{ PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 461 }, { PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 476 },
{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 477 }, { PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 477 },
{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 463 }, { PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 463 },
{ PROC_LINKS(highlight_next_scope_absolute, 0), "highlight_next_scope_absolute", 29, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 363 }, { PROC_LINKS(highlight_next_scope_absolute, 0), "highlight_next_scope_absolute", 29, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 363 },
@ -343,8 +343,8 @@ static Command_Metadata fcoder_metacmd_table[208] = {
{ PROC_LINKS(move_up_10, 0), "move_up_10", 10, "Moves the cursor up ten lines.", 30, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 262 }, { PROC_LINKS(move_up_10, 0), "move_up_10", 10, "Moves the cursor up ten lines.", 30, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 262 },
{ PROC_LINKS(newline_or_goto_position_direct, 0), "newline_or_goto_position_direct", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 101 }, { PROC_LINKS(newline_or_goto_position_direct, 0), "newline_or_goto_position_direct", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 101 },
{ PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 116 }, { PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 116 },
{ PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 562 }, { PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 577 },
{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 547 }, { PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 562 },
{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1067 }, { PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1067 },
{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1074 }, { PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1074 },
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "c:\\4ed\\code\\4coder_lists.cpp", 28, 897 }, { PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "c:\\4ed\\code\\4coder_lists.cpp", 28, 897 },

View File

@ -230,21 +230,26 @@ static bool32
get_stored_jump_from_list(Application_Links *app, Marker_List *list, int32_t index, get_stored_jump_from_list(Application_Links *app, Marker_List *list, int32_t index,
Sticky_Jump_Stored *stored_out){ Sticky_Jump_Stored *stored_out){
Sticky_Jump_Stored stored = {0}; Sticky_Jump_Stored stored = {0};
if (managed_object_load_data(app, list->jump_array, index, 1, &stored)){ if (list != 0){
*stored_out = stored; if (managed_object_load_data(app, list->jump_array, index, 1, &stored)){
return(true); *stored_out = stored;
return(true);
}
} }
return(false); return(false);
} }
static Sticky_Jump_Stored* static Sticky_Jump_Stored*
get_all_stored_jumps_from_list(Application_Links *app, Partition *arena, Marker_List *list){ get_all_stored_jumps_from_list(Application_Links *app, Partition *arena, Marker_List *list){
Temp_Memory restore_point = begin_temp_memory(arena); Sticky_Jump_Stored *stored = 0;
Sticky_Jump_Stored *stored = push_array(arena, Sticky_Jump_Stored, list->jump_count); if (list != 0){
if (stored != 0){ Temp_Memory restore_point = begin_temp_memory(arena);
if (!managed_object_load_data(app, list->jump_array, 0, list->jump_count, stored)){ stored = push_array(arena, Sticky_Jump_Stored, list->jump_count);
stored = 0; if (stored != 0){
end_temp_memory(restore_point); if (!managed_object_load_data(app, list->jump_array, 0, list->jump_count, stored)){
stored = 0;
end_temp_memory(restore_point);
}
} }
} }
return(stored); return(stored);
@ -277,9 +282,11 @@ get_jump_from_list(Application_Links *app, Marker_List *list, int32_t index, ID_
static int32_t static int32_t
get_line_from_list(Application_Links *app, Marker_List *list, int32_t index){ get_line_from_list(Application_Links *app, Marker_List *list, int32_t index){
int32_t result = 0; int32_t result = 0;
Sticky_Jump_Stored stored = {0}; if (list != 0){
if (get_stored_jump_from_list(app, list, index, &stored)){ Sticky_Jump_Stored stored = {0};
result = stored.list_line; if (get_stored_jump_from_list(app, list, index, &stored)){
result = stored.list_line;
}
} }
return(result); return(result);
} }
@ -287,9 +294,11 @@ get_line_from_list(Application_Links *app, Marker_List *list, int32_t index){
static bool32 static bool32
get_is_sub_error_from_list(Application_Links *app, Marker_List *list, int32_t index){ get_is_sub_error_from_list(Application_Links *app, Marker_List *list, int32_t index){
bool32 result = false; bool32 result = false;
Sticky_Jump_Stored stored = {0}; if (list != 0){
if (get_stored_jump_from_list(app, list, index, &stored)){ Sticky_Jump_Stored stored = {0};
result = stored.is_sub_error; if (get_stored_jump_from_list(app, list, index, &stored)){
result = stored.is_sub_error;
}
} }
return(result); return(result);
} }
@ -297,27 +306,31 @@ get_is_sub_error_from_list(Application_Links *app, Marker_List *list, int32_t in
static int32_t static int32_t
get_index_nearest_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){ get_index_nearest_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){
int32_t result = -1; int32_t result = -1;
Temp_Memory temp = begin_temp_memory(scratch); if (list != 0){
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); Temp_Memory temp = begin_temp_memory(scratch);
if (stored != 0){ Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
result = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line); if (stored != 0){
result = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line);
}
end_temp_memory(temp);
} }
end_temp_memory(temp);
return(result); return(result);
} }
static int32_t static int32_t
get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){ get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){
int32_t result = -1; int32_t result = -1;
Temp_Memory temp = begin_temp_memory(scratch); if (list != 0){
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); Temp_Memory temp = begin_temp_memory(scratch);
if (stored != 0){ Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
int32_t index = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line); if (stored != 0){
if (stored[index].list_line == line){ int32_t index = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line);
result = index; if (stored[index].list_line == line){
result = index;
}
} }
end_temp_memory(temp);
} }
end_temp_memory(temp);
return(result); return(result);
} }
@ -408,26 +421,28 @@ static void
goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_Summary *jump_view, int32_t list_index, int32_t direction, bool32 skip_repeats, bool32 skip_sub_errors){ goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_Summary *jump_view, int32_t list_index, int32_t direction, bool32 skip_repeats, bool32 skip_sub_errors){
Assert(direction == 1 || direction == -1); Assert(direction == 1 || direction == -1);
while (list_index >= 0 && list_index < list->jump_count){ if (list != 0){
ID_Pos_Jump_Location location = {0}; for (;list_index >= 0 && list_index < list->jump_count;){
if (get_jump_from_list(app, list, list_index, &location)){ ID_Pos_Jump_Location location = {0};
bool32 skip_this = false; if (get_jump_from_list(app, list, list_index, &location)){
if (skip_repeats && jump_is_repeat(prev_location, location)){ bool32 skip_this = false;
skip_this = true; if (skip_repeats && jump_is_repeat(prev_location, location)){
} skip_this = true;
else if (skip_sub_errors && get_is_sub_error_from_list(app, list, list_index)){ }
skip_this = true; else if (skip_sub_errors && get_is_sub_error_from_list(app, list, list_index)){
skip_this = true;
}
if (!skip_this){
goto_jump_in_order(app, list, jump_view, location);
int32_t updated_line = get_line_from_list(app, list, list_index);
view_set_cursor(app, jump_view, seek_line_char(updated_line, 1), true);
break;
}
} }
if (!skip_this){ list_index += direction;
goto_jump_in_order(app, list, jump_view, location);
int32_t updated_line = get_line_from_list(app, list, list_index);
view_set_cursor(app, jump_view, seek_line_char(updated_line, 1), true);
break;
}
} }
list_index += direction;
} }
} }