fixed issue with command coroutine timing, new input consumption system
This commit is contained in:
parent
8a9dd391a6
commit
00b3fc8020
|
@ -348,7 +348,6 @@ default_keys(Bind_Helper *context){
|
||||||
bind(context, '[', MDFR_CTRL, open_long_braces);
|
bind(context, '[', MDFR_CTRL, open_long_braces);
|
||||||
bind(context, '{', MDFR_CTRL, open_long_braces_semicolon);
|
bind(context, '{', MDFR_CTRL, open_long_braces_semicolon);
|
||||||
bind(context, '}', MDFR_CTRL, open_long_braces_break);
|
bind(context, '}', MDFR_CTRL, open_long_braces_break);
|
||||||
bind(context, '9', MDFR_CTRL, paren_wrap);
|
|
||||||
bind(context, 'i', MDFR_ALT, if0_off);
|
bind(context, 'i', MDFR_ALT, if0_off);
|
||||||
bind(context, '1', MDFR_ALT, open_file_in_quotes);
|
bind(context, '1', MDFR_ALT, open_file_in_quotes);
|
||||||
bind(context, '0', MDFR_CTRL, write_zero_struct);
|
bind(context, '0', MDFR_CTRL, write_zero_struct);
|
||||||
|
|
|
@ -74,38 +74,16 @@ CUSTOM_COMMAND_SIG(open_long_braces_break){
|
||||||
long_braces(app, text, size);
|
long_braces(app, text, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(paren_wrap){
|
// TODO(allen): Have this thing check if it is on
|
||||||
View_Summary view;
|
// a blank line and insert newlines as needed.
|
||||||
Buffer_Summary buffer;
|
|
||||||
|
|
||||||
char text1[] = "(";
|
|
||||||
int size1 = sizeof(text1) - 1;
|
|
||||||
|
|
||||||
char text2[] = ")";
|
|
||||||
int size2 = sizeof(text2) - 1;
|
|
||||||
|
|
||||||
Range range;
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
view = app->get_active_view(app);
|
|
||||||
buffer = app->get_active_buffer(app);
|
|
||||||
|
|
||||||
range = get_range(&view);
|
|
||||||
pos = range.max;
|
|
||||||
app->buffer_replace_range(app, &buffer, pos, pos, text2, size2);
|
|
||||||
|
|
||||||
pos = range.min;
|
|
||||||
app->buffer_replace_range(app, &buffer, pos, pos, text1, size1);
|
|
||||||
}
|
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(if0_off){
|
CUSTOM_COMMAND_SIG(if0_off){
|
||||||
View_Summary view;
|
View_Summary view;
|
||||||
Buffer_Summary buffer;
|
Buffer_Summary buffer;
|
||||||
|
|
||||||
char text1[] = "\n#if 0";
|
char text1[] = "#if 0";
|
||||||
int size1 = sizeof(text1) - 1;
|
int size1 = sizeof(text1) - 1;
|
||||||
|
|
||||||
char text2[] = "#endif\n";
|
char text2[] = "#endif";
|
||||||
int size2 = sizeof(text2) - 1;
|
int size2 = sizeof(text2) - 1;
|
||||||
|
|
||||||
Range range;
|
Range range;
|
||||||
|
|
198
4ed.cpp
198
4ed.cpp
|
@ -3467,6 +3467,82 @@ update_cli_handle_with_file(System_Functions *system, Models *models,
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Input_Types{
|
||||||
|
Input_AnyKey,
|
||||||
|
Input_Esc,
|
||||||
|
Input_MouseMove,
|
||||||
|
Input_MouseLeftButton,
|
||||||
|
Input_MouseRightButton,
|
||||||
|
Input_MouseWheel,
|
||||||
|
Input_Count
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Available_Input{
|
||||||
|
Key_Summary *keys;
|
||||||
|
Mouse_State *mouse;
|
||||||
|
b32 consumed[Input_Count];
|
||||||
|
};
|
||||||
|
|
||||||
|
Available_Input
|
||||||
|
init_available_input(Key_Summary *keys, Mouse_State *mouse){
|
||||||
|
Available_Input result = {0};
|
||||||
|
result.keys = keys;
|
||||||
|
result.mouse = mouse;
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
Key_Summary
|
||||||
|
get_key_data(Available_Input *available){
|
||||||
|
Key_Summary result = {0};
|
||||||
|
|
||||||
|
if (!available->consumed[Input_AnyKey]){
|
||||||
|
result = *available->keys;
|
||||||
|
}
|
||||||
|
else if (!available->consumed[Input_Esc]){
|
||||||
|
i32 i = 0;
|
||||||
|
i32 count = available->keys->count;
|
||||||
|
Key_Event_Data key = {0};
|
||||||
|
|
||||||
|
for (i = 0; i < count; ++i){
|
||||||
|
key = get_single_key(available->keys, i);
|
||||||
|
if (key.keycode == key_esc){
|
||||||
|
result.count = 1;
|
||||||
|
result.keys[0] = key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mouse_State
|
||||||
|
get_mouse_state(Available_Input *available){
|
||||||
|
Mouse_State mouse = *available->mouse;
|
||||||
|
if (available->consumed[Input_MouseLeftButton]){
|
||||||
|
mouse.l = 0;
|
||||||
|
mouse.press_l = 0;
|
||||||
|
mouse.release_l = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (available->consumed[Input_MouseRightButton]){
|
||||||
|
mouse.r = 0;
|
||||||
|
mouse.press_r = 0;
|
||||||
|
mouse.release_r = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (available->consumed[Input_MouseWheel]){
|
||||||
|
mouse.wheel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(mouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
consume_input(Available_Input *available, i32 input_type){
|
||||||
|
available->consumed[input_type] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
App_Step_Sig(app_step){
|
App_Step_Sig(app_step){
|
||||||
Application_Step_Result app_result = *result;
|
Application_Step_Result app_result = *result;
|
||||||
app_result.animating = 0;
|
app_result.animating = 0;
|
||||||
|
@ -3551,12 +3627,12 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): prepare input information
|
// NOTE(allen): prepare input information
|
||||||
Key_Summary key_data = {};
|
Key_Summary key_summary = {0};
|
||||||
for (i32 i = 0; i < input->press_count; ++i){
|
for (i32 i = 0; i < input->press_count; ++i){
|
||||||
key_data.keys[key_data.count++] = input->press[i];
|
key_summary.keys[key_summary.count++] = input->press[i];
|
||||||
}
|
}
|
||||||
for (i32 i = 0; i < input->hold_count; ++i){
|
for (i32 i = 0; i < input->hold_count; ++i){
|
||||||
key_data.keys[key_data.count++] = input->hold[i];
|
key_summary.keys[key_summary.count++] = input->hold[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse->wheel = -mouse->wheel;
|
mouse->wheel = -mouse->wheel;
|
||||||
|
@ -3746,7 +3822,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): process the command_coroutine if it is unfinished
|
// NOTE(allen): process the command_coroutine if it is unfinished
|
||||||
b8 consumed_input[6] = {0};
|
Available_Input available_input = init_available_input(&key_summary, mouse);
|
||||||
|
|
||||||
// NOTE(allen): Keyboard input to command coroutine.
|
// NOTE(allen): Keyboard input to command coroutine.
|
||||||
if (models->command_coroutine != 0){
|
if (models->command_coroutine != 0){
|
||||||
|
@ -3757,6 +3833,8 @@ App_Step_Sig(app_step){
|
||||||
get_flags |= abort_flags;
|
get_flags |= abort_flags;
|
||||||
|
|
||||||
if ((get_flags & EventOnAnyKey) || (get_flags & EventOnEsc)){
|
if ((get_flags & EventOnAnyKey) || (get_flags & EventOnEsc)){
|
||||||
|
Key_Summary key_data = get_key_data(&available_input);
|
||||||
|
|
||||||
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
|
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
|
||||||
Key_Event_Data key = get_single_key(&key_data, key_i);
|
Key_Event_Data key = get_single_key(&key_data, key_i);
|
||||||
View *view = cmd->view;
|
View *view = cmd->view;
|
||||||
|
@ -3783,13 +3861,13 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
if (EventOnAnyKey & get_flags){
|
if (EventOnAnyKey & get_flags){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consumed_input[0] = 1;
|
consume_input(&available_input, Input_AnyKey);
|
||||||
}
|
}
|
||||||
if (key.keycode == key_esc){
|
if (key.keycode == key_esc){
|
||||||
if (EventOnEsc & get_flags){
|
if (EventOnEsc & get_flags){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
}
|
}
|
||||||
consumed_input[1] = 1;
|
consume_input(&available_input, Input_Esc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass_in){
|
if (pass_in){
|
||||||
|
@ -3824,7 +3902,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnMouseMove){
|
if (get_flags & EventOnMouseMove){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consumed_input[2] = 1;
|
consume_input(&available_input, Input_MouseMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse->press_l || mouse->release_l || mouse->l){
|
if (mouse->press_l || mouse->release_l || mouse->l){
|
||||||
|
@ -3833,7 +3911,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnLeftButton){
|
if (get_flags & EventOnLeftButton){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consumed_input[3] = 1;
|
consume_input(&available_input, Input_MouseLeftButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3843,7 +3921,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnRightButton){
|
if (get_flags & EventOnRightButton){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consumed_input[4] = 1;
|
consume_input(&available_input, Input_MouseRightButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3853,7 +3931,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnWheel){
|
if (get_flags & EventOnWheel){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consumed_input[5] = 1;
|
consume_input(&available_input, Input_MouseWheel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3884,37 +3962,10 @@ App_Step_Sig(app_step){
|
||||||
Input_Summary active_input = {};
|
Input_Summary active_input = {};
|
||||||
active_input.mouse.x = mouse->x;
|
active_input.mouse.x = mouse->x;
|
||||||
active_input.mouse.y = mouse->y;
|
active_input.mouse.y = mouse->y;
|
||||||
if (!consumed_input[0]){
|
|
||||||
active_input.keys = key_data;
|
|
||||||
}
|
|
||||||
else if (!consumed_input[1]){
|
|
||||||
for (i32 i = 0; i < key_data.count; ++i){
|
|
||||||
Key_Event_Data key = get_single_key(&key_data, i);
|
|
||||||
if (key.keycode == key_esc){
|
|
||||||
active_input.keys.count = 1;
|
|
||||||
active_input.keys.keys[0] = key;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Mouse_State mouse_state = *mouse;
|
active_input.keys = get_key_data(&available_input);
|
||||||
|
|
||||||
if (consumed_input[3]){
|
Mouse_State mouse_state = get_mouse_state(&available_input);
|
||||||
mouse_state.l = 0;
|
|
||||||
mouse_state.press_l = 0;
|
|
||||||
mouse_state.release_l = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consumed_input[4]){
|
|
||||||
mouse_state.r = 0;
|
|
||||||
mouse_state.press_r = 0;
|
|
||||||
mouse_state.release_r = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consumed_input[5]){
|
|
||||||
mouse_state.wheel = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Panel *panel, *used_panels;
|
Panel *panel, *used_panels;
|
||||||
|
@ -3961,8 +4012,10 @@ App_Step_Sig(app_step){
|
||||||
update_command_data(vars, cmd);
|
update_command_data(vars, cmd);
|
||||||
|
|
||||||
// NOTE(allen): command execution
|
// NOTE(allen): command execution
|
||||||
if (!consumed_input[0] || !consumed_input[1]){
|
{
|
||||||
b32 consumed_input2[2] = {0};
|
Key_Summary key_data = get_key_data(&available_input);
|
||||||
|
b32 hit_something = 0;
|
||||||
|
b32 hit_esc = 0;
|
||||||
|
|
||||||
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
|
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
|
||||||
if (models->command_coroutine != 0) break;
|
if (models->command_coroutine != 0) break;
|
||||||
|
@ -3971,39 +4024,36 @@ App_Step_Sig(app_step){
|
||||||
case APP_STATE_EDIT:
|
case APP_STATE_EDIT:
|
||||||
{
|
{
|
||||||
Key_Event_Data key = get_single_key(&key_data, key_i);
|
Key_Event_Data key = get_single_key(&key_data, key_i);
|
||||||
b32 hit_esc = (key.keycode == key_esc);
|
|
||||||
cmd->key = key;
|
cmd->key = key;
|
||||||
|
|
||||||
if (hit_esc || !consumed_input[0]){
|
View *view = cmd->view;
|
||||||
View *view = cmd->view;
|
|
||||||
|
|
||||||
Command_Map *map = 0;
|
Command_Map *map = 0;
|
||||||
if (view) map = view->map;
|
if (view) map = view->map;
|
||||||
if (map == 0) map = &models->map_top;
|
if (map == 0) map = &models->map_top;
|
||||||
Command_Binding cmd_bind = map_extract_recursive(map, key);
|
Command_Binding cmd_bind = map_extract_recursive(map, key);
|
||||||
|
|
||||||
if (cmd_bind.function){
|
if (cmd_bind.function){
|
||||||
if (hit_esc){
|
if (key.keycode == key_esc){
|
||||||
consumed_input2[1] = 1;
|
hit_esc = 1;
|
||||||
}
|
|
||||||
else{
|
|
||||||
consumed_input2[0] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert(models->command_coroutine == 0);
|
|
||||||
Coroutine *command_coroutine = system->create_coroutine(command_caller);
|
|
||||||
models->command_coroutine = command_coroutine;
|
|
||||||
|
|
||||||
Command_In cmd_in;
|
|
||||||
cmd_in.cmd = cmd;
|
|
||||||
cmd_in.bind = cmd_bind;
|
|
||||||
|
|
||||||
models->command_coroutine = system->launch_coroutine(models->command_coroutine,
|
|
||||||
&cmd_in, models->command_coroutine_flags);
|
|
||||||
models->prev_command = cmd_bind;
|
|
||||||
|
|
||||||
app_result.animating = 1;
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
hit_something = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(models->command_coroutine == 0);
|
||||||
|
Coroutine *command_coroutine = system->create_coroutine(command_caller);
|
||||||
|
models->command_coroutine = command_coroutine;
|
||||||
|
|
||||||
|
Command_In cmd_in;
|
||||||
|
cmd_in.cmd = cmd;
|
||||||
|
cmd_in.bind = cmd_bind;
|
||||||
|
|
||||||
|
models->command_coroutine = system->launch_coroutine(models->command_coroutine,
|
||||||
|
&cmd_in, models->command_coroutine_flags);
|
||||||
|
models->prev_command = cmd_bind;
|
||||||
|
|
||||||
|
app_result.animating = 1;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
|
@ -4016,8 +4066,12 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
consumed_input[0] |= consumed_input2[0];
|
if (hit_something){
|
||||||
consumed_input[1] |= consumed_input2[1];
|
consume_input(&available_input, Input_AnyKey);
|
||||||
|
}
|
||||||
|
if (hit_esc){
|
||||||
|
consume_input(&available_input, Input_Esc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_command_data(vars, cmd);
|
update_command_data(vars, cmd);
|
||||||
|
@ -4521,6 +4575,8 @@ App_Step_Sig(app_step){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view_record_prev_cursor(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): send style change messages if the style has changed
|
// NOTE(allen): send style change messages if the style has changed
|
||||||
|
|
|
@ -3206,8 +3206,10 @@ view_get_cursor_view_change_state(View *view){
|
||||||
cursor_change = (view->prev_cursor_pos != view->file_data.cursor.pos);
|
cursor_change = (view->prev_cursor_pos != view->file_data.cursor.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_updated)){
|
if (view->current_scroll){
|
||||||
view_change = 1;
|
if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_updated)){
|
||||||
|
view_change = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor_change){
|
if (cursor_change){
|
||||||
|
@ -3230,6 +3232,13 @@ view_get_cursor_view_change_state(View *view){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
view_record_prev_cursor(View *view){
|
||||||
|
if (view->gui_target.did_file){
|
||||||
|
view->prev_cursor_pos = view->file_data.cursor.pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active){
|
file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active){
|
||||||
i32 is_animating = 0;
|
i32 is_animating = 0;
|
||||||
|
@ -3240,8 +3249,6 @@ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active)
|
||||||
|
|
||||||
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated;
|
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated;
|
||||||
|
|
||||||
view->prev_cursor_pos = view->file_data.cursor.pos;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (!gui_id_eq(view->gui_target.active, gui_id_scrollbar())){
|
if (!gui_id_eq(view->gui_target.active, gui_id_scrollbar())){
|
||||||
view_move_view_to_cursor(view);
|
view_move_view_to_cursor(view);
|
||||||
|
|
|
@ -22,8 +22,8 @@ popd
|
||||||
|
|
||||||
pushd ..\build
|
pushd ..\build
|
||||||
REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp
|
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_experiments.cpp
|
||||||
call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp
|
REM call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp
|
||||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||||
|
|
||||||
set EXPORTS=/EXPORT:app_get_functions
|
set EXPORTS=/EXPORT:app_get_functions
|
||||||
|
|
Loading…
Reference in New Issue