Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit 4e59330

Browse files
author
Allen Webster
committed
make sure CR does not appear in result from push_buffer_line
1 parent 27e81c4 commit 4e59330

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

custom/4coder_helper.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ get_line_start_pos(Application_Links *app, Buffer_ID buffer, i64 line_number){
373373
return(get_line_side_pos(app, buffer, line_number, Side_Min));
374374
}
375375

376-
// NOTE(allen): The position returned has the index of the terminating newline character,
376+
// NOTE(allen): The position returned has the index of the terminating LF.
377377
// not one past the newline character.
378378
function Buffer_Cursor
379379
get_line_end(Application_Links *app, Buffer_ID buffer, i64 line_number){
@@ -384,7 +384,7 @@ get_line_end_pos(Application_Links *app, Buffer_ID buffer, i64 line_number){
384384
return(get_line_side_pos(app, buffer, line_number, Side_Max));
385385
}
386386

387-
// NOTE(allen): The range returned does not include the terminating newline character
387+
// NOTE(allen): The range returned does not include the terminating LF or CRLF
388388
function Range_Cursor
389389
get_line_range(Application_Links *app, Buffer_ID buffer, i64 line_number){
390390
b32 success = false;
@@ -402,7 +402,7 @@ get_line_range(Application_Links *app, Buffer_ID buffer, i64 line_number){
402402
return(result);
403403
}
404404

405-
// NOTE(allen): The range returned does not include the terminating newline character
405+
// NOTE(allen): The range returned does not include the terminating LF or CRLF
406406
function Range_i64
407407
get_line_pos_range(Application_Links *app, Buffer_ID buffer, i64 line_number){
408408
Range_Cursor range = get_line_range(app, buffer, line_number);
@@ -1025,7 +1025,18 @@ push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Token
10251025

10261026
function String_Const_u8
10271027
push_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 line_number){
1028-
return(push_buffer_range(app, arena, buffer, get_line_pos_range(app, buffer, line_number)));
1028+
// NOTE(allen): 4coder flaw
1029+
// The system for dealing with CRLF vs LF is too sloppy. There is no way to
1030+
// avoid returning the CR from this function by adjusting the more
1031+
// fundamental position getter functions without risking breaking some of
1032+
// the users of those functions. It seems okay to just chop the CR
1033+
// off here - but it's clearly sloppy. Oh well - we're in duct tape mode
1034+
// these days anyways.
1035+
String_Const_u8 string = push_buffer_range(app, arena, buffer, get_line_pos_range(app, buffer, line_number));
1036+
for (;string.size > 0 && string.str[string.size - 1] == '\r';){
1037+
string.size -= 1;
1038+
}
1039+
return(string);
10291040
}
10301041

10311042
function String_Const_u8

custom/generated/command_metadata.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ static Command_Metadata fcoder_metacmd_table[268] = {
343343
{ PROC_LINKS(execute_previous_cli, 0), false, "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\\custom\\4coder_cli_command.cpp", 41, 7 },
344344
{ PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 846 },
345345
{ PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1653 },
346-
{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2247 },
347-
{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2255 },
346+
{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2258 },
347+
{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2266 },
348348
{ PROC_LINKS(goto_first_jump, 0), false, "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 525 },
349349
{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), false, "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\\custom\\4coder_jump_sticky.cpp", 41, 542 },
350350
{ PROC_LINKS(goto_jump_at_cursor, 0), false, "goto_jump_at_cursor", 19, "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, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 348 },
@@ -493,10 +493,10 @@ static Command_Metadata fcoder_metacmd_table[268] = {
493493
{ PROC_LINKS(save_to_query, 0), false, "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1427 },
494494
{ PROC_LINKS(search, 0), false, "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1109 },
495495
{ PROC_LINKS(search_identifier, 0), false, "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1121 },
496-
{ PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2235 },
497-
{ PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2223 },
498-
{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2241 },
499-
{ PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2229 },
496+
{ PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2246 },
497+
{ PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2234 },
498+
{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2252 },
499+
{ PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2240 },
500500
{ PROC_LINKS(select_all, 0), false, "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\\custom\\4coder_base_commands.cpp", 43, 541 },
501501
{ PROC_LINKS(select_next_scope_absolute, 0), false, "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\\custom\\4coder_scope_commands.cpp", 44, 57 },
502502
{ PROC_LINKS(select_next_scope_after_current, 0), false, "select_next_scope_after_current", 31, "If a scope is selected, find first scope that starts after the selected scope. Otherwise find the first scope that starts after the cursor.", 139, "W:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 66 },

0 commit comments

Comments
 (0)