diff --git a/4coder_custom.h b/4coder_custom.h index 70a6a859..197f7828 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -120,8 +120,8 @@ enum Command_ID{ cmdid_word_complete, - cmdid_copy, - cmdid_cut, + //cmdid_copy, + //cmdid_cut, cmdid_paste, cmdid_paste_next, diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 4ea68146..f6613263 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -6,6 +6,9 @@ #define DIRECTORY_CD_SIG(n) int n(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len) #define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int len) #define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list) +#define CLIPBOARD_POST_SIG(n) int n(Application_Links *app, char *str, int len) +#define CLIPBOARD_COUNT_SIG(n) int n(Application_Links *app) +#define CLIPBOARD_INDEX_SIG(n) int n(Application_Links *app, int index, char *out) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer) #define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int index) @@ -49,6 +52,9 @@ extern "C"{ typedef DIRECTORY_CD_SIG(Directory_CD_Function); typedef GET_FILE_LIST_SIG(Get_File_List_Function); typedef FREE_FILE_LIST_SIG(Free_File_List_Function); + typedef CLIPBOARD_POST_SIG(Clipboard_Post_Function); + typedef CLIPBOARD_COUNT_SIG(Clipboard_Count_Function); + typedef CLIPBOARD_INDEX_SIG(Clipboard_Index_Function); typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function); typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function); typedef GET_BUFFER_SIG(Get_Buffer_Function); @@ -95,6 +101,9 @@ struct Application_Links{ Directory_CD_Function *directory_cd; Get_File_List_Function *get_file_list; Free_File_List_Function *free_file_list; + Clipboard_Post_Function *clipboard_post; + Clipboard_Count_Function *clipboard_count; + Clipboard_Index_Function *clipboard_index; Get_Buffer_First_Function *get_buffer_first; Get_Buffer_Next_Function *get_buffer_next; Get_Buffer_Function *get_buffer; @@ -143,6 +152,9 @@ app_links->file_exists = external_file_exists;\ app_links->directory_cd = external_directory_cd;\ app_links->get_file_list = external_get_file_list;\ app_links->free_file_list = external_free_file_list;\ +app_links->clipboard_post = external_clipboard_post;\ +app_links->clipboard_count = external_clipboard_count;\ +app_links->clipboard_index = external_clipboard_index;\ app_links->get_buffer_first = external_get_buffer_first;\ app_links->get_buffer_next = external_get_buffer_next;\ app_links->get_buffer = external_get_buffer;\ diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index e2a8559f..1a940502 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -290,7 +290,7 @@ default_keys(Bind_Helper *context){ bind(context, ' ', MDFR_CTRL, set_mark); bind(context, 'a', MDFR_CTRL, replace_in_range); - bind(context, 'c', MDFR_CTRL, cmdid_copy); + bind(context, 'c', MDFR_CTRL, copy); bind(context, 'd', MDFR_CTRL, delete_range); bind(context, 'e', MDFR_CTRL, cmdid_center_view); bind(context, 'E', MDFR_CTRL, cmdid_left_adjust_view); @@ -312,7 +312,7 @@ default_keys(Bind_Helper *context){ bind(context, 'v', MDFR_CTRL, cmdid_paste); bind(context, 'V', MDFR_CTRL, cmdid_paste_next); bind(context, 'w', MDFR_ALT, cmdid_hide_scrollbar); - bind(context, 'x', MDFR_CTRL, cmdid_cut); + bind(context, 'x', MDFR_CTRL, cut); bind(context, 'y', MDFR_CTRL, cmdid_redo); bind(context, 'z', MDFR_CTRL, cmdid_undo); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index b306a6a8..0bafa681 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -215,6 +215,57 @@ CUSTOM_COMMAND_SIG(move_right){ true); } + +// +// Clipboard +// + +static int +clipboard_copy(Application_Links *app, int start, int end, Buffer_Summary *buffer_out){ + Buffer_Summary buffer = get_active_buffer(app); + int result = false; + + if (0 <= start && start <= end && end <= buffer.size){ + int size = (end - start); + char *str = (char*)app->memory; + + if (size > app->memory_size){ + app->buffer_read_range(app, &buffer, start, end, str); + app->clipboard_post(app, str, size); + if (buffer_out){*buffer_out = buffer;} + result = true; + } + } + + return(result); +} + +static int +clipboard_cut(Application_Links *app, int start, int end, Buffer_Summary *buffer_out){ + Buffer_Summary buffer = {0}; + int result = false; + + if (clipboard_copy(app, start, end, &buffer)){ + app->buffer_replace_range(app, &buffer, start, end, 0, 0); + if (buffer_out){*buffer_out = buffer;} + } + + return(result); +} + +CUSTOM_COMMAND_SIG(copy){ + View_Summary view = app->get_active_view(app); + Range range = get_range(&view); + clipboard_copy(app, range.min, range.max, 0); +} + +CUSTOM_COMMAND_SIG(cut){ + View_Summary view = app->get_active_view(app); + Range range = get_range(&view); + clipboard_cut(app, range.min, range.max, 0); +} + + // // Various Forms of Seek // diff --git a/4ed.cpp b/4ed.cpp index 606931a8..6adacaa1 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -531,6 +531,7 @@ COMMAND_DECL(word_complete){ } } +#if 0 COMMAND_DECL(copy){ USE_MODELS(models); REQ_READABLE_VIEW(view); @@ -558,6 +559,7 @@ COMMAND_DECL(cut){ view_cursor_move(view, next_cursor_pos); } } +#endif COMMAND_DECL(paste){ @@ -1160,8 +1162,8 @@ setup_command_table(){ SET(word_complete); - SET(copy); - SET(cut); + //SET(copy); + //SET(cut); SET(paste); SET(paste_next); diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index d4bf2b09..27a1b5dd 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -295,6 +295,44 @@ FREE_FILE_LIST_SIG(external_free_file_list){ system->set_file_list(&list, make_string(0, 0)); } +CLIPBOARD_POST_SIG(external_clipboard_post){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + General_Memory *general = &models->mem.general; + Working_Set *working = &models->working_set; + int result = false; + + String *dest = working_set_next_clipboard_string(general, working, len); + copy(dest, make_string(str, len)); + system->post_clipboard(*dest); + + return(result); +} + +CLIPBOARD_COUNT_SIG(external_clipboard_count){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Working_Set *working = &cmd->models->working_set; + int count = working->clipboard_size; + return(count); +} + +CLIPBOARD_INDEX_SIG(external_clipboard_index){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Working_Set *working = &cmd->models->working_set; + + int size = 0; + String *str = working_set_clipboard_index(working, index); + if (str){ + size = str->size; + if (out){ + copy_fast_unsafe(out, *str); + } + } + + return(size); +} + GET_BUFFER_FIRST_SIG(external_get_buffer_first){ Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working_set = &cmd->models->working_set; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 8511cc63..ed5f03ba 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -2438,15 +2438,28 @@ working_set_next_clipboard_string(General_Memory *general, Working_Set *working, return result; } +internal String* +working_set_clipboard_index(Working_Set *working, i32 index){ + String *result = 0; + i32 size = working->clipboard_size; + i32 current = working->clipboard_current; + if (index >= 0 && size > 0){ + index = index % size; + index = current + size - index; + index = index % size; + result = &working->clipboards[index]; + } + return(result); +} + internal String* working_set_clipboard_head(Working_Set *working){ String *result = 0; if (working->clipboard_size > 0){ - i32 clipboard_index = working->clipboard_current; - working->clipboard_rolling = clipboard_index; - result = &working->clipboards[clipboard_index]; + working->clipboard_rolling = 0; + result = working_set_clipboard_index(working, working->clipboard_rolling); } - return result; + return(result); } internal String* @@ -2454,14 +2467,11 @@ working_set_clipboard_roll_down(Working_Set *working){ String *result = 0; if (working->clipboard_size > 0){ i32 clipboard_index = working->clipboard_rolling; - --clipboard_index; - if (clipboard_index < 0){ - clipboard_index = working->clipboard_size-1; - } + ++clipboard_index; working->clipboard_rolling = clipboard_index; - result = &working->clipboards[clipboard_index]; + result = working_set_clipboard_index(working, working->clipboard_rolling); } - return result; + return(result); } internal void diff --git a/build_all.bat b/build_all.bat index a5873ee7..6b94d3e3 100644 --- a/build_all.bat +++ b/build_all.bat @@ -22,8 +22,9 @@ popd pushd ..\build REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp -call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp -REM call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp +REM call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp +call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp +call "..\code\buildsuper.bat" ..\4vim\4coder_chronal.cpp if %ERRORLEVEL% neq 0 (set FirstError=1) set EXPORTS=/EXPORT:app_get_functions diff --git a/custom_api_spec.cpp b/custom_api_spec.cpp index e4ff62c9..a7ba095b 100644 --- a/custom_api_spec.cpp +++ b/custom_api_spec.cpp @@ -11,6 +11,11 @@ int Directory_CD(Application_Links *app, char *dir, int *len, int capacity, char File_List Get_File_List(Application_Links *app, char *dir, int len); void Free_File_List(Application_Links *app, File_List list); +// Clipboard +int Clipboard_Post(Application_Links *app, char *str, int len); +int Clipboard_Count(Application_Links *app); +int Clipboard_Index(Application_Links *app, int index, char *out); + // Direct buffer manipulation Buffer_Summary Get_Buffer_First(Application_Links *app); void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer); diff --git a/power/4coder_casey.cpp b/power/4coder_casey.cpp index e994b5bd..70d36278 100644 --- a/power/4coder_casey.cpp +++ b/power/4coder_casey.cpp @@ -1288,13 +1288,13 @@ DEFINE_MODAL_KEY(modal_m, casey_save_and_make_without_asking); DEFINE_MODAL_KEY(modal_n, casey_goto_next_error); DEFINE_MODAL_KEY(modal_o, query_replace); DEFINE_MODAL_KEY(modal_p, replace_in_range); -DEFINE_MODAL_KEY(modal_q, cmdid_copy); +DEFINE_MODAL_KEY(modal_q, copy); DEFINE_MODAL_KEY(modal_r, reverse_search); // NOTE(allen): I've modified my default search so you can use it now. DEFINE_MODAL_KEY(modal_s, search); DEFINE_MODAL_KEY(modal_t, casey_load_todo); DEFINE_MODAL_KEY(modal_u, cmdid_undo); DEFINE_MODAL_KEY(modal_v, casey_switch_buffer_other_window); -DEFINE_MODAL_KEY(modal_w, cmdid_cut); +DEFINE_MODAL_KEY(modal_w, cut); DEFINE_MODAL_KEY(modal_x, casey_find_corresponding_file_other_window); DEFINE_MODAL_KEY(modal_y, cmdid_redo); DEFINE_MODAL_KEY(modal_z, cmdid_interactive_open);