Simplifying implementation of move line up/down
This commit is contained in:
parent
11cd6192ed
commit
0a9bfc8b84
|
@ -1010,7 +1010,7 @@ get_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Tok
|
||||||
|
|
||||||
static String_Const_u8
|
static String_Const_u8
|
||||||
read_entire_buffer(Application_Links *app, Buffer_ID buffer_id, Arena *scratch){
|
read_entire_buffer(Application_Links *app, Buffer_ID buffer_id, Arena *scratch){
|
||||||
return(push_entire_buffer(app, scratch, buffer_id));
|
return(push_whole_buffer(app, scratch, buffer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
static String_Const_u8
|
static String_Const_u8
|
||||||
|
|
|
@ -85,7 +85,7 @@ make_batch_from_indent_marks(Application_Links *app, Arena *arena, Buffer_ID buf
|
||||||
str_size = tab_count + space_count;
|
str_size = tab_count + space_count;
|
||||||
str = push_array(arena, char, str_size);
|
str = push_array(arena, char, str_size);
|
||||||
block_fill_u8(str, tab_count, '\t');
|
block_fill_u8(str, tab_count, '\t');
|
||||||
block_fill_u8(str + tab_count, space_count, ' ');
|
block_fill_u8(str + tab_count, space_count, ' ');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
str_size = correct_indentation;
|
str_size = correct_indentation;
|
||||||
|
|
|
@ -726,69 +726,40 @@ CUSTOM_DOC("Converts all ascii text in the range between the cursor and the mark
|
||||||
CUSTOM_COMMAND_SIG(clean_all_lines)
|
CUSTOM_COMMAND_SIG(clean_all_lines)
|
||||||
CUSTOM_DOC("Removes trailing whitespace from all lines in the current buffer.")
|
CUSTOM_DOC("Removes trailing whitespace from all lines in the current buffer.")
|
||||||
{
|
{
|
||||||
// TODO(allen): This command always iterates accross the entire
|
|
||||||
// buffer, so streaming it is actually the wrong call. Rewrite this
|
|
||||||
// to minimize calls to buffer_read_range.
|
|
||||||
View_ID view = 0;
|
View_ID view = 0;
|
||||||
get_active_view(app, AccessOpen, &view);
|
get_active_view(app, AccessOpen, &view);
|
||||||
Buffer_ID buffer_id = 0;
|
Buffer_ID buffer = 0;
|
||||||
view_get_buffer(app, view, AccessOpen, &buffer_id);
|
view_get_buffer(app, view, AccessOpen, &buffer);
|
||||||
|
|
||||||
i32 buffer_size = 0;
|
|
||||||
i32 line_count = 0;
|
i32 line_count = 0;
|
||||||
buffer_get_size(app, buffer_id, &buffer_size);
|
buffer_get_line_count(app, buffer, &line_count);
|
||||||
buffer_get_line_count(app, buffer_id, &line_count);
|
|
||||||
|
|
||||||
i32 edit_max = line_count;
|
Scratch_Block scratch(app);
|
||||||
|
Buffer_Edit *edits = push_array(scratch, Buffer_Edit, line_count);
|
||||||
|
Buffer_Edit *edit = edits;
|
||||||
|
|
||||||
if (edit_max*(i32)sizeof(Buffer_Edit) < app->memory_size){
|
String_Const_u8 text = push_whole_buffer(app, scratch, buffer);
|
||||||
Buffer_Edit *edits = (Buffer_Edit*)app->memory;
|
|
||||||
|
umem whitespace_start = 0;
|
||||||
char data[1024];
|
for (umem i = 0; i < text.size; i += 1){
|
||||||
Stream_Chunk chunk = {};
|
u8 v = string_get_character(text, i);
|
||||||
|
if (v == '\n' || i + 1 == text.size){
|
||||||
i32 i = 0;
|
if (whitespace_start < i){
|
||||||
if (init_stream_chunk(&chunk, app, buffer_id, i, data, sizeof(data))){
|
|
||||||
Buffer_Edit *edit = edits;
|
|
||||||
|
|
||||||
i32 still_looping = true;
|
|
||||||
i32 last_hard = buffer_size;
|
|
||||||
do{
|
|
||||||
for (; i < chunk.end; ++i){
|
|
||||||
char at_pos = chunk.data[i];
|
|
||||||
if (at_pos == '\n'){
|
|
||||||
if (last_hard + 1 < i){
|
|
||||||
edit->str_start = 0;
|
|
||||||
edit->len = 0;
|
|
||||||
edit->start = last_hard + 1;
|
|
||||||
edit->end = i;
|
|
||||||
++edit;
|
|
||||||
}
|
|
||||||
last_hard = buffer_size;
|
|
||||||
}
|
|
||||||
else if (character_is_whitespace(at_pos)){
|
|
||||||
// NOTE(allen): do nothing
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
last_hard = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
still_looping = forward_stream_chunk(&chunk);
|
|
||||||
}while(still_looping);
|
|
||||||
|
|
||||||
if (last_hard + 1 < buffer_size){
|
|
||||||
edit->str_start = 0;
|
edit->str_start = 0;
|
||||||
edit->len = 0;
|
edit->len = 0;
|
||||||
edit->start = last_hard + 1;
|
edit->start = (i32)whitespace_start;
|
||||||
edit->end = buffer_size;
|
edit->end = (i32)i;
|
||||||
++edit;
|
++edit;
|
||||||
}
|
}
|
||||||
|
whitespace_start = i + 1;
|
||||||
i32 edit_count = (i32)(edit - edits);
|
}
|
||||||
buffer_batch_edit(app, buffer_id, 0, edits, edit_count);
|
else if (!character_is_whitespace(v)){
|
||||||
|
whitespace_start = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i32 edit_count = (i32)(edit - edits);
|
||||||
|
buffer_batch_edit(app, buffer, 0, edits, edit_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
@ -1634,88 +1605,13 @@ CUSTOM_DOC("Queries the user for a name and creates a new directory with the giv
|
||||||
CUSTOM_COMMAND_SIG(move_line_up)
|
CUSTOM_COMMAND_SIG(move_line_up)
|
||||||
CUSTOM_DOC("Swaps the line under the cursor with the line above it, and moves the cursor up with it.")
|
CUSTOM_DOC("Swaps the line under the cursor with the line above it, and moves the cursor up with it.")
|
||||||
{
|
{
|
||||||
View_ID view = 0;
|
move_line_current_view(app, Scan_Backward);
|
||||||
get_active_view(app, AccessOpen, &view);
|
|
||||||
i32 cursor_pos = 0;
|
|
||||||
view_get_cursor_pos(app, view, &cursor_pos);
|
|
||||||
Full_Cursor cursor = {};
|
|
||||||
view_compute_cursor(app, view, seek_pos(cursor_pos), &cursor);
|
|
||||||
|
|
||||||
if (cursor.line > 1){
|
|
||||||
Buffer_ID buffer = 0;
|
|
||||||
if (view_get_buffer(app, view, AccessOpen, &buffer)){
|
|
||||||
Full_Cursor prev_line_cursor = {};
|
|
||||||
Full_Cursor this_line_cursor = {};
|
|
||||||
Full_Cursor next_line_cursor = {};
|
|
||||||
|
|
||||||
i32 this_line = cursor.line;
|
|
||||||
i32 prev_line = this_line - 1;
|
|
||||||
i32 next_line = this_line + 1;
|
|
||||||
|
|
||||||
if (view_compute_cursor(app, view, seek_line_char(prev_line, 1), &prev_line_cursor) &&
|
|
||||||
view_compute_cursor(app, view, seek_line_char(this_line, 1), &this_line_cursor) &&
|
|
||||||
view_compute_cursor(app, view, seek_line_char(next_line, 1), &next_line_cursor)){
|
|
||||||
|
|
||||||
i32 prev_line_pos = prev_line_cursor.pos;
|
|
||||||
i32 this_line_pos = this_line_cursor.pos;
|
|
||||||
i32 next_line_pos = next_line_cursor.pos;
|
|
||||||
|
|
||||||
Arena *scratch = context_get_arena(app);
|
|
||||||
Temp_Memory temp = begin_temp(scratch);
|
|
||||||
|
|
||||||
i32 length = next_line_pos - prev_line_pos;
|
|
||||||
char *swap = push_array(scratch, char, length + 1);
|
|
||||||
i32 first_len = next_line_pos - this_line_pos;
|
|
||||||
|
|
||||||
if (buffer_read_range(app, buffer, this_line_pos, next_line_pos, swap)){
|
|
||||||
b32 second_line_didnt_have_newline = true;
|
|
||||||
for (i32 i = first_len - 1; i >= 0; --i){
|
|
||||||
if (swap[i] == '\n'){
|
|
||||||
second_line_didnt_have_newline = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (second_line_didnt_have_newline){
|
|
||||||
swap[first_len] = '\n';
|
|
||||||
first_len += 1;
|
|
||||||
// NOTE(allen): Don't increase "length" because then we will be including
|
|
||||||
// the original newline and addignt this new one, making the file longer
|
|
||||||
// which shouldn't be possible for this command!
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_read_range(app, buffer, prev_line_pos, this_line_pos, swap + first_len)){
|
|
||||||
buffer_replace_range(app, buffer, make_range(prev_line_pos, next_line_pos), SCu8(swap, length));
|
|
||||||
view_set_cursor(app, view, seek_line_char(prev_line, 1), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
end_temp(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(move_line_down)
|
CUSTOM_COMMAND_SIG(move_line_down)
|
||||||
CUSTOM_DOC("Swaps the line under the cursor with the line below it, and moves the cursor down with it.")
|
CUSTOM_DOC("Swaps the line under the cursor with the line below it, and moves the cursor down with it.")
|
||||||
{
|
{
|
||||||
View_ID view = 0;
|
move_line_current_view(app, Scan_Forward);
|
||||||
get_active_view(app, AccessOpen, &view);
|
|
||||||
if (view != 0){
|
|
||||||
i32 cursor_pos = 0;
|
|
||||||
view_get_cursor_pos(app, view, &cursor_pos);
|
|
||||||
Full_Cursor cursor = {};
|
|
||||||
view_compute_cursor(app, view, seek_pos(cursor_pos), &cursor);
|
|
||||||
i32 next_line = cursor.line + 1;
|
|
||||||
Full_Cursor new_cursor = {};
|
|
||||||
if (view_compute_cursor(app, view, seek_line_char(next_line, 1), &new_cursor)){
|
|
||||||
if (new_cursor.line == next_line){
|
|
||||||
view_set_cursor(app, view, seek_pos(new_cursor.pos), true);
|
|
||||||
move_line_up(app);
|
|
||||||
move_down_textual(app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(duplicate_line)
|
CUSTOM_COMMAND_SIG(duplicate_line)
|
||||||
|
@ -1915,7 +1811,7 @@ CUSTOM_DOC("Set the other non-active panel to view the buffer that the active pa
|
||||||
view_set_buffer(app, view2, buffer1, 0);
|
view_set_buffer(app, view2, buffer1, 0);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
i32 p1 = 0;
|
i32 p1 = 0;
|
||||||
i32 m1 = 0;
|
i32 m1 = 0;
|
||||||
i32 p2 = 0;
|
i32 p2 = 0;
|
||||||
i32 m2 = 0;
|
i32 m2 = 0;
|
||||||
|
|
|
@ -321,56 +321,56 @@ static Command_Metadata fcoder_metacmd_table[234] = {
|
||||||
{ PROC_LINKS(to_uppercase, 0), "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 686 },
|
{ PROC_LINKS(to_uppercase, 0), "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 686 },
|
||||||
{ PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 706 },
|
{ PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 706 },
|
||||||
{ PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 726 },
|
{ PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 726 },
|
||||||
{ 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, 796 },
|
{ 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, 767 },
|
||||||
{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 805 },
|
{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 776 },
|
||||||
{ 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, 815 },
|
{ 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, 786 },
|
||||||
{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 823 },
|
{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 794 },
|
||||||
{ 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, 831 },
|
{ 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, 802 },
|
||||||
{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 839 },
|
{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 810 },
|
||||||
{ PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 847 },
|
{ PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 818 },
|
||||||
{ PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 857 },
|
{ PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 828 },
|
||||||
{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 869 },
|
{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 840 },
|
||||||
{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 875 },
|
{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 846 },
|
||||||
{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 887 },
|
{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 858 },
|
||||||
{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 899 },
|
{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 870 },
|
||||||
{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 913 },
|
{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 884 },
|
||||||
{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 927 },
|
{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 898 },
|
||||||
{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 944 },
|
{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 915 },
|
||||||
{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 956 },
|
{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 927 },
|
||||||
{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 966 },
|
{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 937 },
|
||||||
{ 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, 972 },
|
{ 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, 943 },
|
||||||
{ 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, 982 },
|
{ 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, 953 },
|
||||||
{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 992 },
|
{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 963 },
|
||||||
{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1000 },
|
{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 971 },
|
||||||
{ 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, 1228 },
|
{ 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, 1199 },
|
||||||
{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1234 },
|
{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1205 },
|
||||||
{ 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, 1240 },
|
{ 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, 1211 },
|
||||||
{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1255 },
|
{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1226 },
|
||||||
{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1270 },
|
{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1241 },
|
||||||
{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1379 },
|
{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1350 },
|
||||||
{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1402 },
|
{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1373 },
|
||||||
{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1421 },
|
{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1392 },
|
||||||
{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1465 },
|
{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1436 },
|
||||||
{ 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, 1490 },
|
{ 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, 1461 },
|
||||||
{ PROC_LINKS(save_to_query, 0), "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\\4coder_base_commands.cpp", 36, 1530 },
|
{ PROC_LINKS(save_to_query, 0), "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\\4coder_base_commands.cpp", 36, 1501 },
|
||||||
{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1568 },
|
{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1539 },
|
||||||
{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1611 },
|
{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1582 },
|
||||||
{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1634 },
|
{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1605 },
|
||||||
{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1699 },
|
{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1611 },
|
||||||
{ 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, 1721 },
|
{ 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, 1617 },
|
||||||
{ 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, 1739 },
|
{ 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, 1635 },
|
||||||
{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1831 },
|
{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1727 },
|
||||||
{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1869 },
|
{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1765 },
|
||||||
{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "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, 1884 },
|
{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "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, 1780 },
|
||||||
{ 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, 1899 },
|
{ 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, 1795 },
|
||||||
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1944 },
|
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1840 },
|
||||||
{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1954 },
|
{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1850 },
|
||||||
{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1968 },
|
{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1864 },
|
||||||
{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2032 },
|
{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1928 },
|
||||||
{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2048 },
|
{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1944 },
|
||||||
{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2066 },
|
{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1962 },
|
||||||
{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2145 },
|
{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2041 },
|
||||||
{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2255 },
|
{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2151 },
|
||||||
{ PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 8 },
|
{ PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 8 },
|
||||||
{ PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 16 },
|
{ PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 16 },
|
||||||
{ PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "w:\\4ed\\code\\4coder_lists.cpp", 28, 32 },
|
{ PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "w:\\4ed\\code\\4coder_lists.cpp", 28, 32 },
|
||||||
|
|
|
@ -638,9 +638,9 @@ scan(Application_Links *app, Boundary_Function_List funcs, Buffer_ID buffer, Sca
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
result = -1;
|
result = -1;
|
||||||
for (Boundary_Function_Node *node = funcs.first;
|
for (Boundary_Function_Node *node = funcs.first;
|
||||||
node != 0;
|
node != 0;
|
||||||
node = node->next){
|
node = node->next){
|
||||||
i32 pos = scan(app, node->func, buffer, direction, start_pos);
|
i32 pos = scan(app, node->func, buffer, direction, start_pos);
|
||||||
result = Max(result, pos);
|
result = Max(result, pos);
|
||||||
}
|
}
|
||||||
|
@ -1111,7 +1111,7 @@ push_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 lin
|
||||||
}
|
}
|
||||||
|
|
||||||
static String_Const_u8
|
static String_Const_u8
|
||||||
push_entire_buffer(Application_Links *app, Arena *arena, Buffer_ID buffer){
|
push_whole_buffer(Application_Links *app, Arena *arena, Buffer_ID buffer){
|
||||||
i32 size = 0;
|
i32 size = 0;
|
||||||
buffer_get_size(app, buffer, &size);
|
buffer_get_size(app, buffer, &size);
|
||||||
return(push_buffer_range(app, arena, buffer, 0, size));
|
return(push_buffer_range(app, arena, buffer, 0, size));
|
||||||
|
@ -1181,7 +1181,7 @@ get_pos_past_lead_whitespace(Application_Links *app, Buffer_ID buffer, i32 pos){
|
||||||
i32 line_number = get_line_number_from_pos(app, buffer, pos);
|
i32 line_number = get_line_number_from_pos(app, buffer, pos);
|
||||||
Range line_range = get_line_pos_range(app, buffer, line_number);
|
Range line_range = get_line_pos_range(app, buffer, line_number);
|
||||||
String_Const_u8 line = push_buffer_range(app, scratch, buffer, line_range);
|
String_Const_u8 line = push_buffer_range(app, scratch, buffer, line_range);
|
||||||
i32 result = line_range.end;
|
i32 result = line_range.end;
|
||||||
for (umem i = 0; i < line.size; i += 1){
|
for (umem i = 0; i < line.size; i += 1){
|
||||||
if (!character_is_whitespace(line.str[i])){
|
if (!character_is_whitespace(line.str[i])){
|
||||||
result = line_range.start + (i32)i;
|
result = line_range.start + (i32)i;
|
||||||
|
@ -1312,6 +1312,73 @@ replace_in_range(Application_Links *app, Buffer_ID buffer, Range range, String_C
|
||||||
history_group_end(group);
|
history_group_end(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal Range
|
||||||
|
swap_lines(Application_Links *app, Buffer_ID buffer, i32 line_1, i32 line_2){
|
||||||
|
Range result = {};
|
||||||
|
i32 line_count = 0;
|
||||||
|
buffer_get_line_count(app, buffer, &line_count);
|
||||||
|
if (1 <= line_1 && line_2 <= line_count){
|
||||||
|
Range range_1 = get_line_pos_range(app, buffer, line_1);
|
||||||
|
Range range_2 = get_line_pos_range(app, buffer, line_2);
|
||||||
|
|
||||||
|
Scratch_Block scratch(app);
|
||||||
|
|
||||||
|
String_Const_u8 text_1 = push_buffer_range(app, scratch, buffer, range_1);
|
||||||
|
String_Const_u8 text_2 = push_buffer_range(app, scratch, buffer, range_2);
|
||||||
|
|
||||||
|
History_Group group = history_group_begin(app, buffer);
|
||||||
|
buffer_replace_range(app, buffer, range_2, text_1);
|
||||||
|
buffer_replace_range(app, buffer, range_1, text_2);
|
||||||
|
history_group_end(group);
|
||||||
|
|
||||||
|
i32 shift = replace_range_compute_shift(range_1, (i32)text_2.size);
|
||||||
|
result.min = range_1.min;
|
||||||
|
result.max = range_2.min + shift;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
move_line(Application_Links *app, Buffer_ID buffer, i32 line_number, Scan_Direction direction){
|
||||||
|
i32 line_1 = 0;
|
||||||
|
i32 line_2 = 0;
|
||||||
|
if (direction == Scan_Forward){
|
||||||
|
line_1 = line_number;
|
||||||
|
line_2 = line_number + 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
line_1 = line_number - 1;
|
||||||
|
line_2 = line_number;
|
||||||
|
}
|
||||||
|
Range line_starts = swap_lines(app, buffer, line_1, line_2);
|
||||||
|
i32 result = 0;
|
||||||
|
if (line_starts.min < line_starts.max){
|
||||||
|
if (direction == Scan_Forward){
|
||||||
|
result = line_starts.max;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = line_starts.min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = get_line_side_pos(app, buffer, line_number, Side_Min);
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
move_line_current_view(Application_Links *app, Scan_Direction direction){
|
||||||
|
View_ID view = 0;
|
||||||
|
get_active_view(app, AccessOpen, &view);
|
||||||
|
Buffer_ID buffer = 0;
|
||||||
|
view_get_buffer(app, view, AccessOpen, &buffer);
|
||||||
|
i32 pos = 0;
|
||||||
|
view_get_cursor_pos(app, view, &pos);
|
||||||
|
i32 line_number = get_line_number_from_pos(app, buffer, pos);
|
||||||
|
pos = move_line(app, buffer, line_number, direction);
|
||||||
|
view_set_cursor(app, view, seek_pos(pos), true);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1699,7 +1766,7 @@ forward_stream_chunk(Stream_Chunk *chunk){
|
||||||
buffer_read_range(app, buffer_id, chunk->start, chunk->end, chunk->base_data);
|
buffer_read_range(app, buffer_id, chunk->start, chunk->end, chunk->base_data);
|
||||||
chunk->data = chunk->base_data - chunk->start;
|
chunk->data = chunk->base_data - chunk->start;
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (chunk->add_null && chunk->end + 1 < buffer_size){
|
else if (chunk->add_null && chunk->end + 1 < buffer_size){
|
||||||
|
@ -1828,7 +1895,7 @@ backward_stream_tokens(Stream_Tokens_DEP *stream){
|
||||||
stream->tokens = stream->base_tokens - stream->start;
|
stream->tokens = stream->base_tokens - stream->start;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue