Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/custom/4coder_base_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions code/custom/4coder_default_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions code/custom/4coder_jump_sticky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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){
Expand Down
63 changes: 53 additions & 10 deletions code/custom/4coder_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions code/custom/4coder_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions code/project.4coder
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion code/ship_files/bindings.4coder
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
3 changes: 2 additions & 1 deletion code/ship_files/config.4coder
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down