1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265  | bool cro_selection_active = false;
CUSTOM_COMMAND_SIG(cro_selection_abort)
{
    View_Summary view = get_active_view(app, AccessProtected);
    view_set_highlight(app, &view, 0, 0, false);
    cro_selection_active = false;
}
void cro_selection_cont(Application_Links *app, Custom_Command_Function wrapped_func)
{
    bool was_active = cro_selection_active;
    if (!cro_selection_active)
    {
        cro_selection_active = true;
        set_mark(app);
    }
    wrapped_func(app);
    View_Summary view = get_active_view(app, AccessProtected);
    Range range = get_range(&view);
    int32_t pos = view.cursor.character_pos;
    view_set_highlight(app, &view, range.min, range.max, true);
    view_set_cursor(app, &view, seek_character_pos(pos), 1);
    center_view(app); /// because for some reason when you select move down the buffer doesn't scroll with your...
}
void cro_selection_delete_or_cmd(Application_Links *app, Custom_Command_Function wrapped_func)
{
    if (cro_selection_active)
    {
        View_Summary view = get_active_view(app, AccessProtected);
        Range range = get_range(&view);
        Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
        buffer_replace_range(app, &buffer, range.min, range.max, 0, 0);
        cro_selection_abort(app);
    }
    else
    {
        if (wrapped_func)
            wrapped_func(app);
    }
}
CUSTOM_COMMAND_SIG(cro_selection_write_character)
{
    uint32_t access = AccessOpen;
    View_Summary view = get_active_view(app, access);
    User_Input in = get_command_input(app);
    uint8_t character[4];
    uint32_t length = to_writable_character(in, character);
    if (length != 0)
    {
        Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
        int32_t pos = view.cursor.pos;
        Marker next_cursor_marker = {0};
        next_cursor_marker.pos = character_pos_to_pos(app, &view, &buffer, view.cursor.character_pos);
        next_cursor_marker.lean_right = true;
        Marker_Handle handle = buffer_add_markers(app, &buffer, 1);
        buffer_set_markers(app, &buffer, handle, 0, 1, &next_cursor_marker);
        if (cro_selection_active)
        {
            Range range = get_range(&view);
            buffer_replace_range(app, &buffer, range.min, range.max, (char *)character, length);
            cro_selection_abort(app);
        }
        else
        {
            buffer_replace_range(app, &buffer, pos, pos, (char *)character, length);
        }
        buffer_get_markers(app, &buffer, handle, 0, 1, &next_cursor_marker);
        buffer_remove_markers(app, &buffer, handle);
        view_set_cursor(app, &view, seek_pos(next_cursor_marker.pos), true);
    }
}
void fill_keys_custom(Bind_Helper *context)
{
    begin_map(context, mapid_global);
    bind(context, 'p', MDFR_CTRL, open_panel_vsplit);
    bind(context, '_', MDFR_CTRL, open_panel_hsplit);
    bind(context, 'P', MDFR_CTRL, close_panel);
    bind(context, ',', MDFR_CTRL, change_active_panel);
    bind(context, '<', MDFR_CTRL, change_active_panel_backwards);
    bind(context, 'n', MDFR_CTRL, interactive_new);
    bind(context, 'o', MDFR_CTRL, interactive_open_or_new);
    bind(context, 'o', MDFR_ALT, open_in_other);
    bind(context, 'k', MDFR_CTRL, interactive_kill_buffer);
    bind(context, 'i', MDFR_CTRL, interactive_switch_buffer);
    bind(context, 'h', MDFR_CTRL, project_go_to_root_directory);
    bind(context, 'H', MDFR_CTRL, reload_current_project);
    bind(context, 'S', MDFR_CTRL, save_all_dirty_buffers);
    bind(context, 'c', MDFR_ALT, open_color_tweaker);
    bind(context, 'd', MDFR_ALT, open_debug);
    bind(context, '.', MDFR_ALT, change_to_build_panel);
    bind(context, ',', MDFR_ALT, close_build_panel);
    bind(context, 'n', MDFR_ALT, goto_next_jump_no_skips_sticky);
    bind(context, 'N', MDFR_ALT, goto_prev_jump_no_skips_sticky);
    bind(context, 'M', MDFR_ALT, goto_first_jump_sticky);
    bind(context, 'm', MDFR_ALT, build_in_build_panel);
    bind(context, 'z', MDFR_ALT, execute_any_cli);
    bind(context, 'Z', MDFR_ALT, execute_previous_cli);
    bind(context, 'x', MDFR_ALT, execute_arbitrary_command);
    bind(context, 's', MDFR_ALT, show_scrollbar);
    bind(context, 'w', MDFR_ALT, hide_scrollbar);
    bind(context, 'b', MDFR_ALT, toggle_filebar);
    bind(context, '@', MDFR_ALT, toggle_mouse);
    bind(context, key_page_up, MDFR_CTRL, toggle_fullscreen);
    bind(context, 'E', MDFR_ALT, exit_4coder);
    bind(context, '+', MDFR_CTRL, increase_face_size);
    bind(context, '-', MDFR_CTRL, decrease_face_size);
    bind(context, key_f1, MDFR_NONE, project_fkey_command);
    bind(context, key_f2, MDFR_NONE, project_fkey_command);
    bind(context, key_f3, MDFR_NONE, project_fkey_command);
    bind(context, key_f4, MDFR_NONE, project_fkey_command);
    bind(context, key_f5, MDFR_NONE, project_fkey_command);
    bind(context, key_f6, MDFR_NONE, project_fkey_command);
    bind(context, key_f7, MDFR_NONE, project_fkey_command);
    bind(context, key_f8, MDFR_NONE, project_fkey_command);
    bind(context, key_f9, MDFR_NONE, project_fkey_command);
    bind(context, key_f10, MDFR_NONE, project_fkey_command);
    bind(context, key_f11, MDFR_NONE, project_fkey_command);
    bind(context, key_f12, MDFR_NONE, project_fkey_command);
    bind(context, key_f13, MDFR_NONE, project_fkey_command);
    bind(context, key_f14, MDFR_NONE, project_fkey_command);
    bind(context, key_f15, MDFR_NONE, project_fkey_command);
    bind(context, key_f16, MDFR_NONE, project_fkey_command);
    end_map(context);
    begin_map(context, mapid_file);
    bind_vanilla_keys(context, write_character);
    bind(context, key_mouse_left, MDFR_NONE, click_set_cursor);
    bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark);
    bind(context, key_mouse_right, MDFR_NONE, click_set_mark);
//    bind(context, key_del, MDFR_NONE, delete_char);
    bind(context, key_del, MDFR_SHIFT, delete_char);
//    bind(context, key_back, MDFR_NONE, backspace_char);
    bind(context, key_back, MDFR_SHIFT, backspace_char);
    bind(context, key_up, MDFR_ALT, move_line_up);
    bind(context, key_down, MDFR_ALT, move_line_down);
    bind(context, key_back, MDFR_CTRL, backspace_word);
    bind(context, key_del, MDFR_CTRL, delete_word);
    bind(context, key_back, MDFR_ALT, snipe_token_or_word);
    bind(context, key_del, MDFR_ALT, snipe_token_or_word_right);
        bind_vanilla_keys(context, cro_selection_write_character);
    
#define __(_k, _m, _f) \
    bind(context, _k, _m|MDFR_SHIFT, [](Application_Links* app){cro_selection_cont(app, _f);}); \
    bind(context, _k, _m, [](Application_Links* app){cro_selection_abort(app); _f(app);})
    __(key_left,      MDFR_NONE, move_left);
    __(key_right,     MDFR_NONE, move_right);
    __(key_up,        MDFR_NONE, move_up);
    __(key_down,      MDFR_NONE, move_down);
    __(key_end,       MDFR_NONE, seek_end_of_line);
    __(key_home,      MDFR_NONE, seek_beginning_of_line);
    __(key_page_up,   MDFR_NONE, page_up);
    __(key_page_down, MDFR_NONE, page_down);
    __(key_right,     MDFR_CTRL|MDFR_ALT, seek_whitespace_right);
    __(key_left,      MDFR_CTRL|MDFR_ALT, seek_whitespace_left);
    __(key_right,     MDFR_CTRL, seek_token_right); // ?
    __(key_left,      MDFR_CTRL, seek_token_left); // ?
    __(key_right,     MDFR_ALT,  seek_white_or_token_right);
    __(key_left,      MDFR_ALT,  seek_white_or_token_left);
    __(key_up,        MDFR_CTRL, seek_whitespace_up_end_line);
    __(key_down,      MDFR_CTRL, seek_whitespace_down_end_line);
    __(key_up,        MDFR_ALT,  move_up_10);
    __(key_down,      MDFR_ALT,  move_down_10);
#undef __
        
    //    bind(context, key_del, MDFR_SHIFT, delete_char);
    bind(context, key_back, MDFR_NONE, [](Application_Links* app){
         cro_selection_delete_or_cmd(app, backspace_char);
    });
    bind(context, key_del, MDFR_NONE, [](Application_Links* app){
         cro_selection_delete_or_cmd(app, delete_char);
    });
    bind(context, key_esc, MDFR_NONE, cro_selection_abort);         
    bind(context, 'x', MDFR_CTRL, [](Application_Links* app){
         cut(app);
         cro_selection_abort(app);
    });
    bind(context, 'v', MDFR_CTRL, [](Application_Links* app){         
         cro_selection_delete_or_cmd(app, NULL);
         paste_and_indent(app);
    });
    bind(context, ' ', MDFR_SHIFT, cro_selection_write_character);
    bind(context, ' ', MDFR_CTRL, set_mark);
    bind(context, 'a', MDFR_CTRL, replace_in_range);
    bind(context, 'c', MDFR_CTRL, copy);
    bind(context, 'd', MDFR_CTRL, delete_range);
    bind(context, 'D', MDFR_CTRL, delete_line);
    bind(context, 'e', MDFR_CTRL, center_view);
    bind(context, 'E', MDFR_CTRL, left_adjust_view);
    bind(context, 'f', MDFR_CTRL, search);
    bind(context, 'F', MDFR_CTRL, list_all_locations);
    bind(context, 'F', MDFR_ALT, list_all_substring_locations_case_insensitive);
    bind(context, 'g', MDFR_CTRL, goto_line);
    bind(context, 'G', MDFR_CTRL, list_all_locations_of_selection);
    bind(context, 'j', MDFR_CTRL, to_lowercase);
    bind(context, 'K', MDFR_CTRL, kill_buffer);
    bind(context, 'l', MDFR_CTRL, toggle_line_wrap);
    bind(context, 'L', MDFR_CTRL, duplicate_line);
    bind(context, 'm', MDFR_CTRL, cursor_mark_swap);
    bind(context, 'O', MDFR_CTRL, reopen);
    bind(context, 'q', MDFR_CTRL, query_replace);
    bind(context, 'Q', MDFR_CTRL, query_replace_identifier);
    bind(context, 'q', MDFR_ALT, query_replace_selection);
    bind(context, 'r', MDFR_CTRL, reverse_search);
    bind(context, 's', MDFR_CTRL, save);
    bind(context, 't', MDFR_CTRL, search_identifier);
    bind(context, 'T', MDFR_CTRL, list_all_locations_of_identifier);
    bind(context, 'u', MDFR_CTRL, to_uppercase);
    bind(context, 'v', MDFR_CTRL, paste_and_indent);
    bind(context, 'v', MDFR_ALT, toggle_virtual_whitespace);
    bind(context, 'V', MDFR_CTRL, paste_next_and_indent);
    bind(context, 'x', MDFR_CTRL, cut);
    bind(context, 'y', MDFR_CTRL, redo);
    bind(context, 'z', MDFR_CTRL, undo);
    bind(context, '1', MDFR_CTRL, view_buffer_other_panel);
    bind(context, '2', MDFR_CTRL, swap_buffers_between_panels);
    bind(context, '?', MDFR_CTRL, toggle_show_whitespace);
    bind(context, '~', MDFR_CTRL, clean_all_lines);
    bind(context, '\n', MDFR_NONE, newline_or_goto_position_sticky);
    bind(context, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel_sticky);
    bind(context, ' ', MDFR_SHIFT, write_character);
    end_map(context);
    begin_map(context, default_code_map);
    inherit_map(context, mapid_file);
    bind(context, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right);
    bind(context, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left);
    bind(context, '\n', MDFR_NONE, write_and_auto_tab);
    bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
    bind(context, '}', MDFR_NONE, write_and_auto_tab);
    bind(context, ')', MDFR_NONE, write_and_auto_tab);
    bind(context, ']', MDFR_NONE, write_and_auto_tab);
    bind(context, ';', MDFR_NONE, write_and_auto_tab);
    bind(context, '#', MDFR_NONE, write_and_auto_tab);
    bind(context, '\t', MDFR_NONE, word_complete);
    bind(context, '\t', MDFR_CTRL, auto_tab_range);
    bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor);
    bind(context, 'h', MDFR_ALT, write_hack);
    bind(context, 'r', MDFR_ALT, write_block);
    bind(context, 't', MDFR_ALT, write_todo);
    bind(context, 'y', MDFR_ALT, write_note);
    bind(context, 'D', MDFR_ALT, list_all_locations_of_type_definition);
    bind(context, 'T', MDFR_ALT, list_all_locations_of_type_definition_of_identifier);
    bind(context, '[', MDFR_CTRL, open_long_braces);
    bind(context, '{', MDFR_CTRL, open_long_braces_semicolon);
    bind(context, '}', MDFR_CTRL, open_long_braces_break);
    bind(context, '[', MDFR_ALT, highlight_surrounding_scope);
    bind(context, ']', MDFR_ALT, highlight_prev_scope_absolute);
    bind(context, '\'', MDFR_ALT, highlight_next_scope_absolute);
    bind(context, '/', MDFR_ALT, place_in_scope);
    bind(context, '-', MDFR_ALT, delete_current_scope);
    bind(context, 'j', MDFR_ALT, scope_absorb_down);
    bind(context, 'i', MDFR_ALT, if0_off);
    bind(context, '1', MDFR_ALT, open_file_in_quotes);
    bind(context, '2', MDFR_ALT, open_matching_file_cpp);
    bind(context, '0', MDFR_CTRL, write_zero_struct);
    bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer);
    end_map(context);
}
 
 |