diff --git a/code/custom/4coder_base_commands.cpp b/code/custom/4coder_base_commands.cpp index 93a733b7..37686763 100644 --- a/code/custom/4coder_base_commands.cpp +++ b/code/custom/4coder_base_commands.cpp @@ -1895,7 +1895,7 @@ CUSTOM_DOC("Advances forwards through the undo history of the current buffer.") History_Record_Index current = buffer_history_get_current_state_index(app, buffer); History_Record_Index max_index = buffer_history_get_max_record_index(app, buffer); if (current < max_index){ - Record_Info record = buffer_history_get_record_info(app, buffer, current); + Record_Info record = buffer_history_get_record_info(app, buffer, current + 1); i64 new_position = record_get_new_cursor_position_redo(app, buffer, current + 1, record); buffer_history_set_current_state_index(app, buffer, current + 1); diff --git a/code/custom/4coder_default_map.cpp b/code/custom/4coder_default_map.cpp index 266e01df..1e8c051e 100644 --- a/code/custom/4coder_default_map.cpp +++ b/code/custom/4coder_default_map.cpp @@ -121,9 +121,9 @@ setup_default_mapping(Mapping *mapping, i64 global_id, i64 file_id, i64 code_id) Bind(move_right_alpha_numeric_or_camel_boundary, KeyCode_Right, KeyCode_Alt); Bind(comment_line_toggle, KeyCode_Semicolon, KeyCode_Control); Bind(word_complete, KeyCode_Tab); - Bind(auto_indent_range, KeyCode_Tab, KeyCode_Control); - Bind(auto_indent_line_at_cursor, KeyCode_Tab, KeyCode_Shift); + Bind(word_complete_prev, KeyCode_Tab, KeyCode_Shift); Bind(word_complete_drop_down, KeyCode_Tab, KeyCode_Shift, KeyCode_Control); + Bind(auto_indent_range, KeyCode_Tab, KeyCode_Control); Bind(write_block, KeyCode_R, KeyCode_Alt); Bind(write_todo, KeyCode_T, KeyCode_Alt); Bind(write_note, KeyCode_Y, KeyCode_Alt); diff --git a/code/custom/4coder_jump_sticky.cpp b/code/custom/4coder_jump_sticky.cpp index b39acd49..a3f97c16 100644 --- a/code/custom/4coder_jump_sticky.cpp +++ b/code/custom/4coder_jump_sticky.cpp @@ -454,7 +454,8 @@ get_locked_jump_state(Application_Links *app, Heap *heap){ Buffer_ID buffer = view_get_buffer(app, result.view, Access_Always); result.list = get_or_make_list_for_buffer(app, heap, buffer); - i64 cursor_position = view_get_cursor_pos(app, result.view); + i64 size = buffer_get_size(app, buffer); + i64 cursor_position = size == 0 ? 0 : view_get_cursor_pos(app, result.view) % size; Buffer_Cursor cursor = buffer_compute_cursor(app, buffer, seek_pos(cursor_position)); result.list_index = get_index_nearest_from_list(app, result.list, cursor.line); } @@ -468,7 +469,8 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ - i64 cursor_position = view_get_cursor_pos(app, jump_state.view); + i64 size = buffer_get_size(app, view_get_buffer(app, jump_state.view, Access_Always)); + i64 cursor_position = size == 0 ? 0 : view_get_cursor_pos(app, jump_state.view) % size; Buffer_Cursor cursor = view_compute_cursor(app, jump_state.view, seek_pos(cursor_position)); i64 line = get_line_from_list(app, jump_state.list, jump_state.list_index); if (line <= cursor.line){ diff --git a/code/custom/4coder_search.cpp b/code/custom/4coder_search.cpp index 1377f6a3..cdd471cb 100644 --- a/code/custom/4coder_search.cpp +++ b/code/custom/4coder_search.cpp @@ -52,6 +52,7 @@ print_string_match_list_to_buffer(Application_Links *app, Buffer_ID out_buffer_i } end_buffer_insertion(&out); + lock_jump_buffer(app, out_buffer_id); } internal void @@ -398,6 +399,20 @@ word_complete_iter_next(Word_Complete_Iterator *it){ } } +function void +word_complete_iter_prev(Word_Complete_Iterator *it){ + if (it->node == 0 || it->node == it->list.first){ + it->node = it->list.first; + } + else{ + Node_String_Const_u8 *node = it->list.first; + while (node != 0 && node->next != it->node){ + node = node->next; + } + it->node = node; + } +} + function String_Const_u8 word_complete_iter_read(Word_Complete_Iterator *it){ String_Const_u8 result = {}; @@ -449,31 +464,59 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with set_next_rewrite(app, view, Rewrite_WordComplete); Word_Complete_Iterator *it = word_complete_get_shared_iter(app); - local_persist b32 initialized = false; - local_persist Range_i64 range = {}; - if (first_completion || !initialized){ + if (first_completion || !it->initialized){ ProfileBlock(app, "word complete state init"); - initialized = false; + it->initialized = false; i64 pos = view_get_cursor_pos(app, view); Range_i64 needle_range = get_word_complete_needle_range(app, buffer, pos); if (range_size(needle_range) > 0){ - initialized = true; - range = needle_range; word_complete_iter_init(buffer, needle_range, it); + it->initialized = true; + it->range = needle_range; } } - if (initialized){ + if (it->initialized){ ProfileBlock(app, "word complete apply"); word_complete_iter_next(it); String_Const_u8 str = word_complete_iter_read(it); - buffer_replace_range(app, buffer, range, str); + buffer_replace_range(app, buffer, it->range, str); + + it->range.max = it->range.min + str.size; + view_set_cursor_and_preferred_x(app, view, seek_pos(it->range.max)); + } + } +} + +CUSTOM_COMMAND_SIG(word_complete_prev) +CUSTOM_DOC("Reverse iterates the word_complete list") +{ + ProfileScope(app, "word complete prev"); + + View_ID view = get_active_view(app, Access_ReadWriteVisible); + Buffer_ID buffer = view_get_buffer(app, view, Access_ReadWriteVisible); + if (buffer != 0){ + Managed_Scope scope = view_get_managed_scope(app, view); + Word_Complete_Iterator *it = word_complete_get_shared_iter(app); + set_next_rewrite(app, view, Rewrite_WordComplete); + + Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); + if (*rewrite != Rewrite_WordComplete || !it->initialized){ + word_complete(app); + } + else { + ProfileBlock(app, "word complete apply prev"); + + word_complete_iter_prev(it); + String_Const_u8 str = word_complete_iter_read(it); + + buffer_replace_range(app, buffer, it->range, str); - range.max = range.min + str.size; - view_set_cursor_and_preferred_x(app, view, seek_pos(range.max)); + it->range.max = it->range.min + str.size; + view_set_cursor_and_preferred_x(app, view, seek_pos(it->range.max)); } } } diff --git a/code/custom/4coder_search.h b/code/custom/4coder_search.h index 752c5c21..b5e00d06 100644 --- a/code/custom/4coder_search.h +++ b/code/custom/4coder_search.h @@ -17,6 +17,9 @@ struct Word_Complete_Iterator{ Application_Links *app; Arena *arena; + b32 initialized; + Range_i64 range; + Temp_Memory arena_restore; Buffer_ID first_buffer; Buffer_ID current_buffer; diff --git a/code/project.4coder b/code/project.4coder index 6c865c35..76da43cd 100644 --- a/code/project.4coder +++ b/code/project.4coder @@ -1,6 +1,11 @@ version(2); project_name = "4coder"; +indent_with_tabs = false; +indent_width = 4; +default_tab_width = 4; +indent_clear_blank_lines = false; + patterns = { "*.c", "*.cpp", diff --git a/code/ship_files/bindings.4coder b/code/ship_files/bindings.4coder index d07a2c84..8fa6b823 100644 --- a/code/ship_files/bindings.4coder +++ b/code/ship_files/bindings.4coder @@ -112,8 +112,8 @@ keys_code = { { "move_right_alpha_numeric_or_camel_boundary", "Right", "Alt" }, { "comment_line_toggle", "Semicolon", "Control" }, { "word_complete", "Tab" }, + { "word_complete_prev", "Tab", "Shift" }, { "auto_indent_range", "Tab", "Control" }, - { "auto_indent_line_at_cursor", "Tab", "Shift" }, { "word_complete_drop_down", "Tab", "Shift", "Control" }, { "write_block", "R", "Alt" }, { "write_todo", "T", "Alt" }, diff --git a/code/ship_files/config.4coder b/code/ship_files/config.4coder index 31d32a87..30b82268 100644 --- a/code/ship_files/config.4coder +++ b/code/ship_files/config.4coder @@ -18,10 +18,11 @@ use_error_highlight = true; use_jump_highlight = true; use_scope_highlight = true; use_paren_helper = true; -use_comment_keywords = true; +use_comment_keyword = true; lister_whole_word_backspace_when_modified = true; show_line_number_margins = false; enable_output_wrapping = false; +highlight_line_at_cursor = true; enable_undo_fade_out = true;