moved mark-cursor-swap, and Home/End to custom layer

This commit is contained in:
Allen Webster 2016-06-06 14:41:17 -04:00
parent 201b7f65a4
commit fb1230e991
6 changed files with 156 additions and 191 deletions

View File

@ -216,14 +216,14 @@ enum Command_ID{
cmdid_open_panel_hsplit,
cmdid_close_panel,
cmdid_seek_end_of_line,
cmdid_seek_beginning_of_line,
cmdid_page_up,
cmdid_page_down,
cmdid_cursor_mark_swap,
cmdid_open_color_tweaker,
cmdid_open_config,
cmdid_open_menu,
cmdid_open_debug,
cmdid_hide_scrollbar,
cmdid_show_scrollbar,
cmdid_set_settings,

View File

@ -322,8 +322,8 @@ default_keys(Bind_Helper *context){
bind(context, key_back, MDFR_NONE, backspace_char);
bind(context, key_up, MDFR_NONE, move_up);
bind(context, key_down, MDFR_NONE, move_down);
bind(context, key_end, MDFR_NONE, cmdid_seek_end_of_line);
bind(context, key_home, MDFR_NONE, cmdid_seek_beginning_of_line);
bind(context, key_end, MDFR_NONE, seek_end_of_line);
bind(context, key_home, MDFR_NONE, seek_beginning_of_line);
bind(context, key_page_up, MDFR_NONE, cmdid_page_up);
bind(context, key_page_down, MDFR_NONE, cmdid_page_down);
@ -350,7 +350,7 @@ default_keys(Bind_Helper *context){
bind(context, 'j', MDFR_CTRL, cmdid_to_lowercase);
bind(context, 'K', MDFR_CTRL, cmdid_kill_buffer);
bind(context, 'l', MDFR_CTRL, cmdid_toggle_line_wrap);
bind(context, 'm', MDFR_CTRL, cmdid_cursor_mark_swap);
bind(context, 'm', MDFR_CTRL, cursor_mark_swap);
bind(context, 'O', MDFR_CTRL, cmdid_reopen);
bind(context, 'q', MDFR_CTRL, query_replace);
bind(context, 'r', MDFR_CTRL, reverse_search);

View File

@ -85,7 +85,17 @@ CUSTOM_COMMAND_SIG(set_mark){
app->view_set_mark(app, &view, seek_pos(view.cursor.pos));
// TODO(allen): Just expose the preferred_x seperately
app->view_set_cursor(app, &view, seek_pos(view.cursor.pos), 1);
app->view_set_cursor(app, &view, seek_pos(view.cursor.pos), true);
}
CUSTOM_COMMAND_SIG(cursor_mark_swap){
View_Summary view = app->get_active_view(app);
int cursor = view.cursor.pos;
int mark = view.mark.pos;
app->view_set_cursor(app, &view, seek_pos(mark), true);
app->view_set_mark(app, &view, seek_pos(cursor));
}
CUSTOM_COMMAND_SIG(delete_range){
@ -295,6 +305,86 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down){
true);
}
static int
seek_line_end(Application_Links *app, Buffer_Summary *buffer, int pos){
char chunk[1024];
int chunk_size = sizeof(chunk);
Stream_Chunk stream = {0};
int still_looping;
char at_pos;
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
still_looping = 1;
do{
for (; pos < stream.end; ++pos){
at_pos = stream.data[pos];
if (at_pos == '\n'){
goto double_break;
}
}
still_looping = forward_stream_chunk(&stream);
}while(still_looping);
double_break:;
if (pos > buffer->size){
pos = buffer->size;
}
}
return(pos);
}
static int
seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int pos){
char chunk[1024];
int chunk_size = sizeof(chunk);
Stream_Chunk stream = {0};
int still_looping;
char at_pos;
--pos;
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
still_looping = 1;
do{
for (; pos >= stream.start; --pos){
at_pos = stream.data[pos];
if (at_pos == '\n'){
goto double_break;
}
}
still_looping = backward_stream_chunk(&stream);
}while(still_looping);
double_break:;
if (pos != 0){
++pos;
}
if (pos < 0){
pos = 0;
}
}
return(pos);
}
CUSTOM_COMMAND_SIG(seek_end_of_line){
View_Summary view = app->get_active_view(app);
Buffer_Summary buffer = app->get_buffer(app, view.locked_buffer_id);
int new_pos = seek_line_end(app, &buffer, view.cursor.pos);
app->view_set_cursor(app, &view, seek_pos(new_pos), true);
}
CUSTOM_COMMAND_SIG(seek_beginning_of_line){
View_Summary view = app->get_active_view(app);
Buffer_Summary buffer = app->get_buffer(app, view.locked_buffer_id);
int new_pos = seek_line_beginning(app, &buffer, view.cursor.pos);
app->view_set_cursor(app, &view, seek_pos(new_pos), true);
}
static void
basic_seek(Application_Links *app, Command_ID seek_type, unsigned int flags){
push_parameter(app, par_flags, flags);

157
4ed.cpp
View File

@ -712,11 +712,11 @@ COMMAND_DECL(history_forward){
}
COMMAND_DECL(interactive_new){
USE_MODELS(models);
USE_VIEW(view);
view_show_interactive(system, view, &models->map_ui,
IAct_New, IInt_Sys_File_List, make_lit_string("New: "));
view_show_interactive(system, view,
IAct_New, IInt_Sys_File_List,
make_lit_string("New: "));
}
COMMAND_DECL(interactive_open){
@ -752,8 +752,9 @@ COMMAND_DECL(interactive_open){
}
}
else{
view_show_interactive(system, view, &models->map_ui,
IAct_Open, IInt_Sys_File_List, make_lit_string("Open: "));
view_show_interactive(system, view,
IAct_Open, IInt_Sys_File_List,
make_lit_string("Open: "));
}
}
@ -830,8 +831,9 @@ COMMAND_DECL(save){
}
}
else{
view_show_interactive(system, view, &models->map_ui,
IAct_Save_As, IInt_Sys_File_List, make_lit_string("Save As: "));
view_show_interactive(system, view,
IAct_Save_As, IInt_Sys_File_List,
make_lit_string("Save As: "));
}
}
}
@ -858,7 +860,6 @@ COMMAND_DECL(save){
}
COMMAND_DECL(change_active_panel){
USE_MODELS(models);
USE_PANEL(panel);
@ -870,21 +871,19 @@ COMMAND_DECL(change_active_panel){
}
COMMAND_DECL(interactive_switch_buffer){
USE_VIEW(view);
USE_MODELS(models);
view_show_interactive(system, view, &models->map_ui,
IAct_Switch, IInt_Live_File_List, make_lit_string("Switch Buffer: "));
view_show_interactive(system, view,
IAct_Switch, IInt_Live_File_List,
make_lit_string("Switch Buffer: "));
}
COMMAND_DECL(interactive_kill_buffer){
USE_VIEW(view);
USE_MODELS(models);
view_show_interactive(system, view, &models->map_ui,
IAct_Kill, IInt_Live_File_List, make_lit_string("Kill Buffer: "));
view_show_interactive(system, view,
IAct_Kill, IInt_Live_File_List,
make_lit_string("Kill Buffer: "));
}
COMMAND_DECL(kill_buffer){
@ -1206,81 +1205,6 @@ COMMAND_DECL(close_panel){
}
}
#if 0
COMMAND_DECL(move_left){
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = view->recent->cursor.pos;
if (pos > 0) --pos;
view_cursor_move(view, pos);
}
COMMAND_DECL(move_right){
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer);
i32 pos = view->recent->cursor.pos;
if (pos < size) ++pos;
view_cursor_move(view, pos);
}
COMMAND_DECL(delete){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer);
i32 cursor_pos = view->recent->cursor.pos;
if (0 < size && cursor_pos < size){
i32 start, end;
start = cursor_pos;
end = cursor_pos+1;
i32 next_cursor_pos = start;
view_replace_range(system, models, view,
start, end, 0, 0, next_cursor_pos);
view_cursor_move(view, next_cursor_pos);
}
}
COMMAND_DECL(backspace){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer);
i32 cursor_pos = view->recent->cursor.pos;
if (cursor_pos > 0 && cursor_pos <= size){
i32 start, end;
end = cursor_pos;
start = cursor_pos-1;
i32 next_cursor_pos = view->recent->cursor.pos - 1;
view_replace_range(system, models, view, start, end, 0, 0, next_cursor_pos);
view_cursor_move(view, next_cursor_pos);
}
}
#endif
COMMAND_DECL(seek_end_of_line){
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = view_find_end_of_line(view, view->recent->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_beginning_of_line){
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = view_find_beginning_of_line(view, view->recent->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(page_down){
REQ_READABLE_VIEW(view);
@ -1308,36 +1232,22 @@ COMMAND_DECL(page_up){
COMMAND_DECL(open_color_tweaker){
USE_VIEW(view);
USE_MODELS(models);
view_show_theme(view, &models->map_ui);
view_show_theme(view);
}
COMMAND_DECL(open_config){
USE_VIEW(view);
USE_MODELS(models);
view_show_config(view, &models->map_ui);
view_show_GUI(view, VUI_Config);
}
COMMAND_DECL(open_menu){
USE_VIEW(view);
USE_MODELS(models);
view_show_menu(view, &models->map_ui);
view_show_GUI(view, VUI_Menu);
}
COMMAND_DECL(close_minor_view){
COMMAND_DECL(open_debug){
USE_VIEW(view);
view_show_file(view);
}
COMMAND_DECL(cursor_mark_swap){
REQ_READABLE_VIEW(view);
i32 pos = view->recent->cursor.pos;
view_cursor_move(view, view->recent->mark);
view->recent->mark = pos;
view_show_GUI(view, VUI_Debug);
}
COMMAND_DECL(user_callback){
@ -2368,7 +2278,6 @@ setup_ui_commands(Command_Map *commands, Partition *part, Command_Map *parent){
map_add(commands, key_up, mdfr, command_null);
map_add(commands, key_down, mdfr, command_null);
map_add(commands, key_back, mdfr, command_null);
map_add(commands, key_esc, mdfr, command_close_minor_view);
}
}
@ -2418,16 +2327,19 @@ setup_command_table(){
SET(open_panel_hsplit);
SET(close_panel);
SET(seek_end_of_line);
SET(seek_beginning_of_line);
SET(page_up);
SET(page_down);
SET(open_color_tweaker);
SET(cursor_mark_swap);
SET(open_config);
SET(open_menu);
SET(open_debug);
SET(hide_scrollbar);
SET(show_scrollbar);
SET(set_settings);
SET(command_line);
#undef SET
@ -3601,9 +3513,10 @@ App_Step_Sig(app_step){
if (there_is_unsaved){
Coroutine *command_coroutine = models->command_coroutine;
View *view = cmd->view;
i32 i = 0;
while (command_coroutine){
for (i32 i = 0;
i < 128 && command_coroutine;
++i){
User_Input user_in = {0};
user_in.abort = 1;
@ -3611,12 +3524,10 @@ App_Step_Sig(app_step){
app_resume_coroutine(system, &models->app_links, Co_Command,
command_coroutine, &user_in,
models->command_coroutine_flags);
++i;
if (i >= 128){
// TODO(allen): post grave warning, resource cleanup system.
command_coroutine = 0;
}
}
if (command_coroutine != 0){
// TODO(allen): post grave warning
command_coroutine = 0;
}
if (view != 0){
init_query_set(&view->query_set);
@ -3627,7 +3538,7 @@ App_Step_Sig(app_step){
view = panel->view;
}
view_show_interactive(system, view, &models->map_ui,
view_show_interactive(system, view,
IAct_Sure_To_Close, IInt_Sure_To_Close,
make_lit_string("Are you sure?"));

View File

@ -127,6 +127,7 @@ enum View_UI{
VUI_Interactive,
VUI_Menu,
VUI_Config,
VUI_Debug
};
enum Color_View_Mode{
@ -2380,48 +2381,6 @@ view_history_step(System_Functions *system, Models *models, View *view, History_
}
}
// TODO(allen): write these as streamed operations
internal i32
view_find_end_of_line(View *view, i32 pos){
#if BUFFER_EXPERIMENT_SCALPEL <= 0
Editing_File *file = view->file_data.file;
char *data = file->state.buffer.data;
while (pos < file->state.buffer.size && data[pos] != '\n') ++pos;
if (pos > file->state.buffer.size) pos = file->state.buffer.size;
#endif
return pos;
}
internal i32
view_find_beginning_of_line(View *view, i32 pos){
#if BUFFER_EXPERIMENT_SCALPEL <= 0
Editing_File *file = view->file_data.file;
char *data = file->state.buffer.data;
if (pos > 0){
--pos;
while (pos > 0 && data[pos] != '\n') --pos;
if (pos != 0) ++pos;
}
#endif
return pos;
}
internal i32
view_find_beginning_of_next_line(View *view, i32 pos){
#if BUFFER_EXPERIMENT_SCALPEL <= 0
Editing_File *file = view->file_data.file;
char *data = file->state.buffer.data;
while (pos < file->state.buffer.size &&
!starts_new_line(data[pos])){
++pos;
}
if (pos < file->state.buffer.size){
++pos;
}
#endif
return pos;
}
internal String*
working_set_next_clipboard_string(General_Memory *general, Working_Set *working, i32 str_size){
String *result = 0;
@ -3072,25 +3031,18 @@ remeasure_file_view(System_Functions *system, View *view){
}
inline void
view_show_menu(View *view, Command_Map *gui_map){
view->map = gui_map;
view->showing_ui = VUI_Menu;
view->current_scroll = &view->gui_scroll;
view->changed_context_in_step = 1;
}
inline void
view_show_config(View *view, Command_Map *gui_map){
view->map = gui_map;
view->showing_ui = VUI_Config;
view_show_GUI(View *view, View_UI ui){
view->map = &view->persistent.models->map_ui;
view->showing_ui = ui;
view->current_scroll = &view->gui_scroll;
view->changed_context_in_step = 1;
}
inline void
view_show_interactive(System_Functions *system, View *view,
Command_Map *gui_map, Interactive_Action action,
Interactive_Interaction interaction, String query){
Interactive_Action action,
Interactive_Interaction interaction,
String query){
Models *models = view->persistent.models;
@ -3101,7 +3053,7 @@ view_show_interactive(System_Functions *system, View *view,
view->list_i = 0;
view->current_scroll = &view->gui_scroll;
view->map = gui_map;
view->map = &models->map_ui;
hot_directory_clean_end(&models->hot_directory);
hot_directory_reload(system, &models->hot_directory, &models->working_set);
@ -3109,8 +3061,8 @@ view_show_interactive(System_Functions *system, View *view,
}
inline void
view_show_theme(View *view, Command_Map *gui_map){
view->map = gui_map;
view_show_theme(View *view){
view->map = &view->persistent.models->map_ui;
view->showing_ui = VUI_Theme;
view->color_mode = CV_Mode_Library;
view->color = super_color_create(0xFF000000);
@ -3315,7 +3267,7 @@ try_kill_file(System_Functions *system, Models *models,
if (view == 0){
view = models->layout.panels[models->layout.active_panel].view;
}
view_show_interactive(system, view, &models->map_ui,
view_show_interactive(system, view,
IAct_Sure_To_Kill, IInt_Sure_To_Kill,
make_lit_string("Are you sure?"));
copy(&view->dest, file->name.live_name);
@ -3992,13 +3944,13 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
id.id[0] = 0;
message = make_lit_string("Theme");
if (gui_do_fixed_option(target, id, message, 0)){
view_show_theme(view, view->map);
view_show_theme(view);
}
id.id[0] = 1;
message = make_lit_string("Config");
if (gui_do_fixed_option(target, id, message, 0)){
view_show_config(view, view->map);
view_show_GUI(view, VUI_Config);
}
}break;
@ -4513,6 +4465,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
interactive_view_complete(system, view, comp_dest, comp_action);
}
}break;
case VUI_Debug:
{
}break;
}
}
}

View File

@ -40,6 +40,13 @@
// Win32_Vars structs
//
#if FRED_INTERNAL
struct Debug_Log_Entry{
u64 time;
i64 message;
};
#endif
struct Thread_Context{
u32 job_id;
b32 running;