update to paste API

This commit is contained in:
Allen Webster 2016-06-14 15:00:03 -04:00
parent 7523900181
commit df6eaf7e29
9 changed files with 218 additions and 123 deletions

View File

@ -120,11 +120,6 @@ enum Command_ID{
cmdid_word_complete,
//cmdid_copy,
//cmdid_cut,
cmdid_paste,
cmdid_paste_next,
cmdid_undo,
cmdid_redo,
cmdid_history_backward,

View File

@ -8,7 +8,7 @@
#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 CLIPBOARD_INDEX_SIG(n) int n(Application_Links *app, int index, char *out, int len)
#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)
@ -31,6 +31,9 @@
#define VIEW_SET_MARK_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek)
#define VIEW_SET_HIGHLIGHT_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int turn_on)
#define VIEW_SET_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, int buffer_id)
#define VIEW_POST_FADE_SIG(n) int n(Application_Links *app, View_Summary *view, int ticks, int start, int end, unsigned int color)
#define VIEW_SET_PASTE_REWRITE__SIG(n) void n(Application_Links *app, View_Summary *view)
#define VIEW_GET_PASTE_REWRITE__SIG(n) int n(Application_Links *app, View_Summary *view)
#define VIEW_OPEN_FILE_SIG(n) int n(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background)
#define VIEW_KILL_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer)
#define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, unsigned int get_type, unsigned int abort_type)
@ -43,6 +46,7 @@
#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int len)
#define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int len)
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int count)
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int count)
extern "C"{
typedef EXEC_COMMAND_SIG(Exec_Command_Function);
typedef EXEC_SYSTEM_COMMAND_SIG(Exec_System_Command_Function);
@ -77,6 +81,9 @@ extern "C"{
typedef VIEW_SET_MARK_SIG(View_Set_Mark_Function);
typedef VIEW_SET_HIGHLIGHT_SIG(View_Set_Highlight_Function);
typedef VIEW_SET_BUFFER_SIG(View_Set_Buffer_Function);
typedef VIEW_POST_FADE_SIG(View_Post_Fade_Function);
typedef VIEW_SET_PASTE_REWRITE__SIG(View_Set_Paste_Rewrite__Function);
typedef VIEW_GET_PASTE_REWRITE__SIG(View_Get_Paste_Rewrite__Function);
typedef VIEW_OPEN_FILE_SIG(View_Open_File_Function);
typedef VIEW_KILL_BUFFER_SIG(View_Kill_Buffer_Function);
typedef GET_USER_INPUT_SIG(Get_User_Input_Function);
@ -89,6 +96,7 @@ extern "C"{
typedef CHANGE_THEME_SIG(Change_Theme_Function);
typedef CHANGE_FONT_SIG(Change_Font_Function);
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function);
}
struct Application_Links{
void *memory;
@ -126,6 +134,9 @@ struct Application_Links{
View_Set_Mark_Function *view_set_mark;
View_Set_Highlight_Function *view_set_highlight;
View_Set_Buffer_Function *view_set_buffer;
View_Post_Fade_Function *view_post_fade;
View_Set_Paste_Rewrite__Function *view_set_paste_rewrite_;
View_Get_Paste_Rewrite__Function *view_get_paste_rewrite_;
View_Open_File_Function *view_open_file;
View_Kill_Buffer_Function *view_kill_buffer;
Get_User_Input_Function *get_user_input;
@ -138,6 +149,7 @@ struct Application_Links{
Change_Theme_Function *change_theme;
Change_Font_Function *change_font;
Set_Theme_Colors_Function *set_theme_colors;
Get_Theme_Colors_Function *get_theme_colors;
void *cmd_context;
void *system_links;
void *current_coroutine;
@ -177,6 +189,9 @@ app_links->view_set_cursor = external_view_set_cursor;\
app_links->view_set_mark = external_view_set_mark;\
app_links->view_set_highlight = external_view_set_highlight;\
app_links->view_set_buffer = external_view_set_buffer;\
app_links->view_post_fade = external_view_post_fade;\
app_links->view_set_paste_rewrite_ = external_view_set_paste_rewrite_;\
app_links->view_get_paste_rewrite_ = external_view_get_paste_rewrite_;\
app_links->view_open_file = external_view_open_file;\
app_links->view_kill_buffer = external_view_kill_buffer;\
app_links->get_user_input = external_get_user_input;\
@ -188,4 +203,5 @@ app_links->end_query_bar = external_end_query_bar;\
app_links->print_message = external_print_message;\
app_links->change_theme = external_change_theme;\
app_links->change_font = external_change_font;\
app_links->set_theme_colors = external_set_theme_colors; } while(false)
app_links->set_theme_colors = external_set_theme_colors;\
app_links->get_theme_colors = external_get_theme_colors; } while(false)

View File

@ -309,8 +309,8 @@ default_keys(Bind_Helper *context){
bind(context, 's', MDFR_CTRL, cmdid_save);
bind(context, 'u', MDFR_CTRL, cmdid_to_uppercase);
bind(context, 'U', MDFR_CTRL, rewrite_as_single_caps);
bind(context, 'v', MDFR_CTRL, cmdid_paste);
bind(context, 'V', MDFR_CTRL, cmdid_paste_next);
bind(context, 'v', MDFR_CTRL, paste);
bind(context, 'V', MDFR_CTRL, paste_next);
bind(context, 'w', MDFR_ALT, cmdid_hide_scrollbar);
bind(context, 'x', MDFR_CTRL, cut);
bind(context, 'y', MDFR_CTRL, cmdid_redo);

View File

@ -222,14 +222,15 @@ CUSTOM_COMMAND_SIG(move_right){
static int
clipboard_copy(Application_Links *app, int start, int end, Buffer_Summary *buffer_out){
Buffer_Summary buffer = get_active_buffer(app);
View_Summary view = app->get_active_view(app);
Buffer_Summary buffer = app->get_buffer(app, view.locked_buffer_id);
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){
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;}
@ -265,6 +266,94 @@ CUSTOM_COMMAND_SIG(cut){
clipboard_cut(app, range.min, range.max, 0);
}
struct View_Paste_Index{
int index;
};
View_Paste_Index view_paste_index_[16];
View_Paste_Index *view_paste_index = view_paste_index_ - 1;
CUSTOM_COMMAND_SIG(paste){
int count = app->clipboard_count(app);
if (count > 0){
View_Summary view = app->get_active_view(app);
// NOTE(allen): THIS is a very temporary poop-sauce
// system that I just threw in to get this working.
// Please don't start calling it anywhere.
app->view_set_paste_rewrite_(app, &view);
int paste_index = 0;
view_paste_index[view.view_id].index = paste_index;
int len = app->clipboard_index(app, paste_index, 0, 0);
char *str = 0;
if (len <= app->memory_size){
str = (char*)app->memory;
}
if (str){
app->clipboard_index(app, paste_index, str, len);
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id);
int pos = view.cursor.pos;
app->buffer_replace_range(app, &buffer, pos, pos, str, len);
app->view_set_mark(app, &view, seek_pos(pos));
app->view_set_cursor(app, &view, seek_pos(pos + len), true);
// TODO(allen): Send this to all views.
Theme_Color paste;
paste.tag = Stag_Paste;
app->get_theme_colors(app, &paste, 1);
app->view_post_fade(app, &view, 20, pos, pos + len, paste.color);
}
}
}
CUSTOM_COMMAND_SIG(paste_next){
int count = app->clipboard_count(app);
if (count > 0){
View_Summary view = app->get_active_view(app);
// NOTE(allen): THIS is a very temporary poop-sauce
// system that I just threw in to get this working.
// Please don't start calling it anywhere.
if (app->view_get_paste_rewrite_(app, &view)){
app->view_set_paste_rewrite_(app, &view);
int paste_index = view_paste_index[view.view_id].index + 1;
view_paste_index[view.view_id].index = paste_index;
int len = app->clipboard_index(app, paste_index, 0, 0);
char *str = 0;
if (len <= app->memory_size){
str = (char*)app->memory;
}
if (str){
app->clipboard_index(app, paste_index, str, len);
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id);
Range range = get_range(&view);
int pos = range.min;
app->buffer_replace_range(app, &buffer, range.min, range.max, str, len);
app->view_set_cursor(app, &view, seek_pos(pos + len), true);
// TODO(allen): Send this to all views.
Theme_Color paste;
paste.tag = Stag_Paste;
app->get_theme_colors(app, &paste, 1);
app->view_post_fade(app, &view, 20, pos, pos + len, paste.color);
}
}
else{
exec_command(app, paste);
}
}
}
//
// Various Forms of Seek

106
4ed.cpp
View File

@ -531,105 +531,7 @@ COMMAND_DECL(word_complete){
}
}
#if 0
COMMAND_DECL(copy){
USE_MODELS(models);
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (range.start < range.end){
clipboard_copy(system, &models->mem.general, &models->working_set, range, file);
}
}
COMMAND_DECL(cut){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (range.start < range.end){
i32 next_cursor_pos = range.start;
clipboard_copy(system, &models->mem.general, &models->working_set, range, file);
view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos);
view->recent->mark = range.start;
view_cursor_move(view, next_cursor_pos);
}
}
#endif
COMMAND_DECL(paste){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
View_Iter iter;
String *src;
i32 pos_left, next_cursor_pos;
if (models->working_set.clipboard_size > 0){
view->next_mode.rewrite = 1;
src = working_set_clipboard_head(&models->working_set);
pos_left = view->recent->cursor.pos;
next_cursor_pos = pos_left+src->size;
view_replace_range(system, models, view, pos_left, pos_left, src->str, src->size, next_cursor_pos);
view_cursor_move(view, next_cursor_pos);
view->recent->mark = pos_left;
Style *style = main_style(models);
u32 paste_color = style->main.paste_color;
for (iter = file_view_iter_init(&models->layout, file, 0);
file_view_iter_good(iter);
iter = file_view_iter_next(iter)){
view_post_paste_effect(iter.view, 20, pos_left, src->size, paste_color);
}
}
}
COMMAND_DECL(paste_next){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
View_Iter iter;
Range range;
String *src;
i32 next_cursor_pos;
if (models->working_set.clipboard_size > 0 && view->mode.rewrite == 1){
view->next_mode.rewrite = 1;
range = make_range(view->recent->mark, view->recent->cursor.pos);
src = working_set_clipboard_roll_down(&models->working_set);
next_cursor_pos = range.start+src->size;
view_replace_range(system,
models, view, range.start, range.end,
src->str, src->size, next_cursor_pos);
view_cursor_move(view, next_cursor_pos);
view->recent->mark = range.start;
Style *style = main_style(models);
u32 paste_color = style->main.paste_color;
for (iter = file_view_iter_init(&models->layout, file, 0);
file_view_iter_good(iter);
iter = file_view_iter_next(iter)){
view_post_paste_effect(iter.view, 20, range.start, src->size, paste_color);
}
}
else{
command_paste(system, command, binding);
}
}
// TODO(allen): FIX THIS FUCKIN SHIT!
// TODO(allen): FIX THIS SHIT!
COMMAND_DECL(undo){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
@ -1162,11 +1064,6 @@ setup_command_table(){
SET(word_complete);
//SET(copy);
//SET(cut);
SET(paste);
SET(paste_next);
SET(undo);
SET(redo);
SET(history_backward);
@ -1188,7 +1085,6 @@ setup_command_table(){
SET(toggle_show_whitespace);
SET(clean_all_lines);
//SET(auto_tab_range);
SET(eol_dosify);
SET(eol_nixify);

View File

@ -326,7 +326,8 @@ CLIPBOARD_INDEX_SIG(external_clipboard_index){
if (str){
size = str->size;
if (out){
copy_fast_unsafe(out, *str);
String out_str = make_string(out, 0, len);
copy(&out_str, *str);
}
}
@ -930,6 +931,77 @@ VIEW_SET_BUFFER_SIG(external_view_set_buffer){
return(result);
}
VIEW_POST_FADE_SIG(external_view_post_fade){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Live_Views *live_set;
View *vptr;
Models *models;
int view_id;
int result = false;
if (view->exists){
models = cmd->models;
live_set = cmd->live_set;
view_id = view->view_id - 1;
if (view_id >= 0 && view_id < live_set->max){
vptr = live_set->views + view_id;
if (end > start){
int size = end - start;
result = true;
view_post_paste_effect(vptr, ticks, start, size, color);
}
}
}
return(result);
}
// TODO(allen): standardize the safe get view/buffer code
VIEW_SET_PASTE_REWRITE__SIG(external_view_set_paste_rewrite_){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Live_Views *live_set;
View *vptr;
Models *models;
int view_id;
if (view->exists){
models = cmd->models;
live_set = cmd->live_set;
view_id = view->view_id - 1;
if (view_id >= 0 && view_id < live_set->max){
vptr = live_set->views + view_id;
vptr->next_mode.rewrite = true;
}
}
}
VIEW_GET_PASTE_REWRITE__SIG(external_view_get_paste_rewrite_){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Live_Views *live_set;
View *vptr;
Models *models;
int view_id;
int result = false;
if (view->exists){
models = cmd->models;
live_set = cmd->live_set;
view_id = view->view_id - 1;
if (view_id >= 0 && view_id < live_set->max){
vptr = live_set->views + view_id;
result = vptr->mode.rewrite;
}
}
return(result);
}
VIEW_OPEN_FILE_SIG(external_view_open_file){
Command_Data *cmd = (Command_Data*)app->cmd_context;
@ -1135,5 +1207,24 @@ SET_THEME_COLORS_SIG(external_set_theme_colors){
}
}
GET_THEME_COLORS_SIG(external_get_theme_colors){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Style *style = main_style(cmd->models);
Theme_Color *theme_color;
u32 *color;
i32 i;
theme_color = colors;
for (i = 0; i < count; ++i, ++theme_color){
color = style_index_by_tag(&style->main, theme_color->tag);
if (color){
theme_color->color = *color | 0xFF000000;
}
else{
theme_color->color = 0xFF000000;
}
}
}
// BOTTOM

View File

@ -22,9 +22,9 @@ popd
pushd ..\build
REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.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
call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp
REM call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp
REM call "..\code\buildsuper.bat" ..\4vim\4coder_chronal.cpp
if %ERRORLEVEL% neq 0 (set FirstError=1)
set EXPORTS=/EXPORT:app_get_functions

View File

@ -14,7 +14,7 @@ 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);
int Clipboard_Index(Application_Links *app, int index, char *out, int len);
// Direct buffer manipulation
Buffer_Summary Get_Buffer_First(Application_Links *app);
@ -50,6 +50,14 @@ int View_Set_Mark(Application_Links *app, View_Summary *view, Buffer_Seek seek);
int View_Set_Highlight(Application_Links *app, View_Summary *view, int start, int end, int turn_on);
int View_Set_Buffer(Application_Links *app, View_Summary *view, int buffer_id);
// TODO(allen): Switch from ticks to seconds.
int View_Post_Fade(Application_Links *app, View_Summary *view, int ticks, int start, int end, unsigned int color);
// TODO(allen):
// Get rid of this temporary hack ass soon ass possible.
void View_Set_Paste_Rewrite_(Application_Links *app, View_Summary *view);
int View_Get_Paste_Rewrite_(Application_Links *app, View_Summary *view);
// TODO(allen): Make sure this is just right.
int View_Open_File(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background);
int View_Kill_Buffer(Application_Links *app, View_Summary *view, Buffer_Identifier buffer);
@ -71,5 +79,5 @@ void Print_Message(Application_Links *app, char *string, int len);
void Change_Theme(Application_Links *app, char *name, int len);
void Change_Font(Application_Links *app, char *name, int len);
void Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int count);
void Get_Theme_Colors(Application_Links *app, Theme_Color *colors, int count);

View File

@ -452,7 +452,7 @@ CUSTOM_COMMAND_SIG(casey_kill_to_end_of_line)
CUSTOM_COMMAND_SIG(casey_paste_and_tab)
{
exec_command(app, cmdid_paste);
exec_command(app, paste);
exec_command(app, auto_tab_range);
}