Fixed up seeks even more

master
Allen Webster 2019-02-20 22:58:34 -08:00
parent c012eefcd5
commit 5ddc8e2b86
9 changed files with 189 additions and 149 deletions

View File

@ -353,7 +353,7 @@ RENDER_CALLER_SIG(default_render_caller){
}
// NOTE(allen): Token highlight setup
bool32 do_token_highlight = false;
bool32 do_token_highlight = true;
if (do_token_highlight){
Theme_Color color = {};
color.tag = Stag_Cursor;
@ -363,15 +363,18 @@ RENDER_CALLER_SIG(default_render_caller){
uint32_t token_flags = BoundaryToken|BoundaryWhitespace;
int32_t pos0 = view.cursor.pos;
int32_t pos1 = buffer_boundary_seek(app, &buffer, pos0, DirLeft , token_flags);
int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, DirRight, token_flags);
Managed_Object token_highlight = alloc_buffer_markers_on_buffer(app, buffer.buffer_id, 2, &render_scope);
Marker range_markers[2] = {};
range_markers[0].pos = pos1;
range_markers[1].pos = pos2;
managed_object_store_data(app, token_highlight, 0, 2, range_markers);
Marker_Visual visual = create_marker_visual(app, token_highlight);
marker_visual_set_effect(app, visual, VisualType_CharacterHighlightRanges, token_color, SymbolicColorFromPalette(Stag_At_Highlight), 0);
if (pos1 >= 0){
int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, DirRight, token_flags);
if (pos2 <= buffer.size){
Managed_Object token_highlight = alloc_buffer_markers_on_buffer(app, buffer.buffer_id, 2, &render_scope);
Marker range_markers[2] = {};
range_markers[0].pos = pos1;
range_markers[1].pos = pos2;
managed_object_store_data(app, token_highlight, 0, 2, range_markers);
Marker_Visual visual = create_marker_visual(app, token_highlight);
marker_visual_set_effect(app, visual, VisualType_CharacterHighlightRanges, token_color, SymbolicColorFromPalette(Stag_At_Highlight), 0);
}
}
}
// NOTE(allen): Matching enclosure highlight setup
@ -386,10 +389,7 @@ RENDER_CALLER_SIG(default_render_caller){
for (int32_t i = 0; i < 4; i += 1){
colors[i] = theme_colors[i].color;
}
mark_enclosures(app, scratch, render_scope,
&buffer, view.cursor.pos, FindScope_Brace,
VisualType_LineHighlightRanges,
colors, 0, color_count);
mark_enclosures(app, scratch, render_scope, &buffer, view.cursor.pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count);
}
if (do_matching_paren_highlight){
Theme_Color theme_colors[color_count];
@ -410,10 +410,7 @@ RENDER_CALLER_SIG(default_render_caller){
pos -= 1;
}
}
mark_enclosures(app, scratch, render_scope,
&buffer, pos, FindScope_Paren,
VisualType_CharacterBlocks,
0, colors, color_count);
mark_enclosures(app, scratch, render_scope, &buffer, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count);
}
do_core_render(app);

View File

@ -393,7 +393,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in
Cpp_Get_Token_Result result;
if (buffer_get_token_index(app, &buffer, view.cursor.pos, &result)){
if (!result.in_whitespace){
if (!result.in_whitespace_after_token){
static const int32_t stream_space_size = 512;
Cpp_Token stream_space[stream_space_size];
Stream_Tokens_DEP stream = {};
@ -551,7 +551,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
Cpp_Get_Token_Result result;
if (buffer_get_token_index(app, &buffer, view.cursor.pos, &result)){
if (!result.in_whitespace){
if (!result.in_whitespace_after_token){
Cpp_Token stream_space[32];
Stream_Tokens_DEP stream = {};

View File

@ -260,7 +260,7 @@ static Command_Metadata fcoder_metacmd_table[234] = {
{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 732 },
{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 711 },
{ PROC_LINKS(backspace_char, 0), "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 101 },
{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1260 },
{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1257 },
{ PROC_LINKS(basic_change_active_panel, 0), "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 509 },
{ PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 187 },
{ PROC_LINKS(build_search, 0), "build_search", 12, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*.", 153, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 155 },
@ -289,15 +289,15 @@ static Command_Metadata fcoder_metacmd_table[234] = {
{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1170 },
{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1422 },
{ PROC_LINKS(delete_range, 0), "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 139 },
{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1266 },
{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1263 },
{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1400 },
{ PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 654 },
{ PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 662 },
{ PROC_LINKS(execute_any_cli, 0), "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "w:\\4ed\\code\\4coder_system_command.cpp", 37, 23 },
{ PROC_LINKS(execute_previous_cli, 0), "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "w:\\4ed\\code\\4coder_system_command.cpp", 37, 7 },
{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 670 },
{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1179 },
{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1187 },
{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1176 },
{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1184 },
{ 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, "w:\\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, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 551 },
{ 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, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 533 },
@ -423,24 +423,24 @@ static Command_Metadata fcoder_metacmd_table[234] = {
{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 747 },
{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 897 },
{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 911 },
{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1240 },
{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1252 },
{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1246 },
{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1234 },
{ PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1133 },
{ PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1113 },
{ PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1145 },
{ PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1123 },
{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1216 },
{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1210 },
{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1228 },
{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1222 },
{ PROC_LINKS(seek_whitespace_down, 0), "seek_whitespace_down", 20, "Seeks the cursor down to the next blank line.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1103 },
{ PROC_LINKS(seek_whitespace_down_end_line, 0), "seek_whitespace_down_end_line", 29, "Seeks the cursor down to the next blank line and places it at the end of the line.", 82, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1168 },
{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1204 },
{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1198 },
{ PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1093 },
{ PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1157 },
{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1237 },
{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1249 },
{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1243 },
{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1231 },
{ PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1130 },
{ PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1110 },
{ PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1142 },
{ PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1120 },
{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1213 },
{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1207 },
{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1225 },
{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1219 },
{ PROC_LINKS(seek_whitespace_down, 0), "seek_whitespace_down", 20, "Seeks the cursor down to the next blank line.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1100 },
{ PROC_LINKS(seek_whitespace_down_end_line, 0), "seek_whitespace_down_end_line", 29, "Seeks the cursor down to the next blank line and places it at the end of the line.", 82, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1165 },
{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1201 },
{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1195 },
{ PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1090 },
{ PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1154 },
{ PROC_LINKS(select_all, 0), "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 392 },
{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 387 },
{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 407 },
@ -457,8 +457,8 @@ static Command_Metadata fcoder_metacmd_table[234] = {
{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1491 },
{ PROC_LINKS(show_filebar, 0), "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 540 },
{ PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 526 },
{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1272 },
{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1278 },
{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1269 },
{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1275 },
{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 248 },
{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 236 },
{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1559 },

View File

@ -768,7 +768,7 @@ get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Toke
int32_t line_start = buffer_get_line_start(app, buffer, line);
Cpp_Get_Token_Result get_token = cpp_get_token(tokens, line_start);
if (get_token.in_whitespace){
if (get_token.in_whitespace_after_token){
get_token.token_index += 1;
}
@ -1158,10 +1158,10 @@ get_token_or_word_under_pos(Application_Links *app, Buffer_Summary *buffer, int3
String result = {};
Cpp_Get_Token_Result get_result = {};
bool32 success = buffer_get_token_index(app, buffer, pos, &get_result);
if (success && !get_result.in_whitespace){
int32_t size = get_result.token_end - get_result.token_start;
if (success && !get_result.in_whitespace_after_token){
int32_t size = get_result.token_one_past_last - get_result.token_start;
if (size > 0 && size <= capacity){
success = buffer_read_range(app, buffer, get_result.token_start, get_result.token_end, space);
success = buffer_read_range(app, buffer, get_result.token_start, get_result.token_one_past_last, space);
if (success){
result = make_string(space, size);
}

View File

@ -107,8 +107,10 @@ struct Stream_Chunk{
Buffer_Summary *buffer;
char *base_data;
int32_t start, end;
int32_t min_start, max_end;
int32_t start;
int32_t end;
int32_t min_start;
int32_t max_end;
bool32 add_null;
uint32_t data_size;

View File

@ -532,6 +532,49 @@ DOC(This call finds the token that contains a particular position, or if the pos
DOC_SEE(Cpp_Get_Token_Result)
*/{
Cpp_Get_Token_Result result = {};
Cpp_Token *tokens = array.tokens;
i32_4tech count = array.count;
i32_4tech first_index = 0;
i32_4tech one_past_last_index = count;
for (;;){
if (first_index == one_past_last_index){
result.token_index = -1;
result.in_whitespace_after_token = 1;
break;
}
i32_4tech mid_index = (first_index + one_past_last_index)/2;
Cpp_Token *token = tokens + mid_index;
i32_4tech range_first = token->start;
i32_4tech range_one_past_last = 0x7FFFFFFF;
if (mid_index + 1 < count){
range_one_past_last = tokens[mid_index + 1].start;
}
if (range_first <= pos && pos < range_one_past_last){
result.token_index = mid_index;
i32_4tech token_one_past_last = range_first + token->size;
if (token_one_past_last <= pos){
result.in_whitespace_after_token = 1;
}
result.token_start = range_first;
result.token_one_past_last = token_one_past_last;
break;
}
if (pos < range_first){
one_past_last_index = mid_index;
}
else if (range_one_past_last <= pos){
first_index = mid_index + 1;
}
}
return(result);
#if 0
Cpp_Get_Token_Result result = {};
Cpp_Token *token_array = array.tokens;
Cpp_Token *token = 0;
@ -591,6 +634,7 @@ DOC_SEE(Cpp_Get_Token_Result)
}
return(result);
#endif
}
// TODO(allen): eliminate this and just make a table.

View File

@ -361,13 +361,13 @@ STRUCT Cpp_Get_Token_Result{
int32_t token_index;
/* DOC(The in_whitespace field is true when the query position was actually in whitespace after the result token.) */
int32_t in_whitespace;
int32_t in_whitespace_after_token;
/* DOC(If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.) */
int32_t token_start;
/* DOC(If the token_index refers to an actual token, this is the start + size value of the token. Otherwise this is zero.) */
int32_t token_end;
int32_t token_one_past_last;
};
/* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.)

View File

@ -50,7 +50,7 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos
int32_t token_index = get_result.token_index;
if (flags & FindScope_Parent){
--token_index;
if (get_result.in_whitespace){
if (get_result.in_whitespace_after_token){
++token_index;
}
}
@ -107,7 +107,7 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_
int32_t token_index = get_result.token_index + 1;
if (flags & FindScope_Parent){
--token_index;
if (get_result.in_whitespace){
if (get_result.in_whitespace_after_token){
++token_index;
}
}
@ -727,7 +727,7 @@ find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, int32_
if (buffer_get_token_index(app, buffer, pos, &get_result)){
Statement_Parser parser = make_statement_parser(app, buffer, get_result.token_index);
if (parser.buffer != 0){
if (get_result.in_whitespace){
if (get_result.in_whitespace_after_token){
parser_next_token(&parser);
}

View File

@ -214,76 +214,74 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3
static int32_t
buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
char data_chunk[1024];
Stream_Chunk stream = {};
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (!char_is_whitespace(stream.data[pos])){
goto double_break1;
}
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break1:;
still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (char_is_whitespace(stream.data[pos])){
goto double_break2;
}
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break2:;
int32_t result = buffer->size + 1;
if (pos < 0){
pos = 0;
}
return(pos);
pos += 1;
if (pos < buffer->size){
char data_chunk[1024];
Stream_Chunk stream = {};
stream.add_null = true;
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
bool32 is_whitespace_1 = true;
is_whitespace_1 = char_is_whitespace(buffer_get_char(app, buffer, pos - 1));
do{
for (; pos < stream.end; ++pos){
char c2 = stream.data[pos];
bool32 is_whitespace_2 = true;
if (c2 != 0){
is_whitespace_2 = char_is_whitespace(c2);
}
if (!is_whitespace_1 && is_whitespace_2){
result = pos;
goto double_break;
}
is_whitespace_1 = is_whitespace_2;
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break:;
}
}
return(result);
}
static int32_t
buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
char data_chunk[1024];
Stream_Chunk stream = {};
--pos;
if (pos > 0){
if (init_stream_chunk(&stream, app, buffer,
pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = 1;
int32_t result = -1;
if (pos > buffer->size){
pos = buffer->size;
}
pos -= 2;
if (pos >= 0){
char data_chunk[1024];
Stream_Chunk stream = {};
if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){
bool32 still_looping = true;
bool32 is_whitespace_2 = char_is_whitespace(buffer_get_char(app, buffer, pos + 1));
do{
for (; pos >= stream.start; --pos){
if (!char_is_whitespace(stream.data[pos])){
goto double_break1;
char c1 = stream.data[pos];
bool32 is_whitespace_1 = char_is_whitespace(c1);
if (is_whitespace_1 && !is_whitespace_2){
result = pos + 1;
goto double_break;
}
is_whitespace_2 = is_whitespace_1;
}
still_looping = backward_stream_chunk(&stream);
}while(still_looping);
double_break1:;
still_looping = 1;
do{
for (; pos >= stream.start; --pos){
if (char_is_whitespace(stream.data[pos])){
++pos;
goto double_break2;
}
}
still_looping = backward_stream_chunk(&stream);
}while(still_looping);
double_break2:;
double_break:;
}
}
else{
pos = 0;
if (pos == -1){
if (!char_is_whitespace(buffer_get_char(app, buffer, 0))){
result = 0;
}
}
return(pos);
return(result);
}
static int32_t
@ -513,8 +511,8 @@ buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *b
static int32_t
seek_token_left(Cpp_Token_Array *tokens, int32_t pos){
int32_t result = 0;
int32_t token_get_pos = (pos > 0)?(pos - 1):0;
int32_t result = -1;
int32_t token_get_pos = pos - 1;
Cpp_Get_Token_Result get = cpp_get_token(*tokens, token_get_pos);
if (get.token_index >= 0){
result = get.token_start;
@ -524,20 +522,17 @@ seek_token_left(Cpp_Token_Array *tokens, int32_t pos){
static int32_t
seek_token_right(Cpp_Token_Array *tokens, int32_t pos, int32_t buffer_end){
int32_t result = 0;
int32_t result = buffer_end + 1;
Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos);
if (get.in_whitespace){
if (get.in_whitespace_after_token){
get.token_index += 1;
if (get.token_index < tokens->count){
Cpp_Token *token = tokens->tokens + get.token_index;
result = token->start + token->size;
}
else{
result = buffer_end;
}
}
else{
result = get.token_end;
result = get.token_one_past_last;
}
return(result);
}
@ -588,7 +583,7 @@ DOC_SEE(4coder_Buffer_Positioning_System)
if (seek_forward){
for (int32_t i = 0; i < ArrayCount(pos); ++i){
pos[i] = size;
pos[i] = size + 1;
}
if (flags & BoundaryWhitespace){
@ -617,16 +612,16 @@ DOC_SEE(4coder_Buffer_Positioning_System)
}
}
new_pos = size;
new_pos = size + 1;
for (int32_t i = 0; i < ArrayCount(pos); ++i){
if (pos[i] < new_pos){
if (new_pos > pos[i]){
new_pos = pos[i];
}
}
}
else{
for (int32_t i = 0; i < ArrayCount(pos); ++i){
pos[i] = 0;
pos[i] = -1;
}
if (flags & BoundaryWhitespace){
@ -655,9 +650,9 @@ DOC_SEE(4coder_Buffer_Positioning_System)
}
}
new_pos = 0;
new_pos = -1;
for (int32_t i = 0; i < ArrayCount(pos); ++i){
if (pos[i] > new_pos){
if (new_pos < pos[i]){
new_pos = pos[i];
}
}
@ -1006,31 +1001,29 @@ read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, int32_t p
static int32_t
flip_dir(int32_t dir){
if (dir == DirLeft){
return(DirRight);
dir = DirRight;
}
else{
return(DirLeft);
dir = DirLeft;
}
return(dir);
}
static int32_t
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer,
int32_t start_pos, int32_t dir, Seek_Boundary_Flag flags){
bool32 forward = (dir == DirRight);
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t dir, Seek_Boundary_Flag flags){
bool32 forward = (dir != DirLeft);
return(buffer_boundary_seek(app, buffer, &global_part, start_pos, forward, flags));
}
static void
view_buffer_boundary_seek_set_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer,
int32_t dir, uint32_t flags){
view_buffer_boundary_seek_set_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t dir, uint32_t flags){
int32_t pos = buffer_boundary_seek(app, buffer, &global_part, view->cursor.pos, dir, flags);
view_set_cursor(app, view, seek_pos(pos), true);
no_mark_snap_to_cursor_if_shift(app, view->view_id);
}
static void
view_boundary_seek_set_pos(Application_Links *app, View_Summary *view,
int32_t dir, uint32_t flags){
view_boundary_seek_set_pos(Application_Links *app, View_Summary *view, int32_t dir, uint32_t flags){
Buffer_Summary buffer = get_buffer(app, view->buffer_id, AccessProtected);
view_buffer_boundary_seek_set_pos(app, view, &buffer, dir, flags);
}
@ -1042,30 +1035,34 @@ current_view_boundary_seek_set_pos(Application_Links *app, int32_t dir, uint32_t
}
static Range
view_buffer_boundary_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer,
int32_t dir, uint32_t flags){
view_buffer_boundary_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t dir, uint32_t flags){
int32_t pos1 = view->cursor.pos;
int32_t pos2 = buffer_boundary_seek(app, buffer, pos1, dir, flags);
return(make_range(pos1, pos2));
}
static Range
view_buffer_snipe_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer,
int32_t dir, uint32_t flags){
view_buffer_snipe_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t dir, uint32_t flags){
Range result = {};
int32_t pos0 = view->cursor.pos;
int32_t pos1 = buffer_boundary_seek(app, buffer, pos0, dir , flags);
int32_t pos2 = buffer_boundary_seek(app, buffer, pos1, flip_dir(dir), flags);
if (dir == DirLeft){
if (pos2 < pos0){
pos2 = pos0;
int32_t pos1 = buffer_boundary_seek(app, buffer, pos0, dir, flags);
if (0 <= pos1 && pos1 <= buffer->size){
int32_t pos2 = buffer_boundary_seek(app, buffer, pos1, flip_dir(dir), flags);
if (0 <= pos2 && pos2 <= buffer->size){
if (dir == DirLeft){
if (pos2 < pos0){
pos2 = pos0;
}
}
else{
if (pos2 > pos0){
pos2 = pos0;
}
}
result = make_range(pos1, pos2);
}
}
else{
if (pos2 > pos0){
pos2 = pos0;
}
}
return(make_range(pos1, pos2));
return(result);
}
static void