diff --git a/core/src/km_core_processevent_api.cpp b/core/src/km_core_processevent_api.cpp index 8ccf0e4fa7..93ba9afbe4 100644 --- a/core/src/km_core_processevent_api.cpp +++ b/core/src/km_core_processevent_api.cpp @@ -52,8 +52,14 @@ km_core_process_event(km_core_state *state, } km_core_status status = state->processor().process_event(state, vk, modifier_state, is_key_down, event_flags); - if (state_should_clear_context(state, vk, modifier_state, is_key_down, event_flags)) { + if (state_should_invalidate_context(state, vk, modifier_state, is_key_down, event_flags)) { state->context().clear(); + // we are already committed. So we need to un-commit (remove the end of the vector) + if (state->actions().back().type == KM_CORE_IT_END) { + state->actions().pop_back(); + } + state->actions().push_invalidate_context(); + state->actions().commit(); } state->apply_actions_and_merge_app_context(); diff --git a/core/src/km_core_state_api.cpp b/core/src/km_core_state_api.cpp index a777321939..abc835fd52 100644 --- a/core/src/km_core_state_api.cpp +++ b/core/src/km_core_state_api.cpp @@ -373,15 +373,17 @@ state_has_action_type(km_core_state *state, uint8_t type) { } bool -state_should_clear_context(km_core_state *state, +state_should_invalidate_context(km_core_state *state, km_core_virtual_key vk, uint16_t modifier_state, uint8_t is_key_down, uint16_t event_flags) { // if emit_keystroke is present, check if a context reset is needed if (state_has_action_type(state, KM_CORE_IT_EMIT_KEYSTROKE)) { - if (vk == KM_CORE_VKEY_BKSP && state_has_action_type(state, KM_CORE_IT_BACK)) { - return true; + if (vk == KM_CORE_VKEY_BKSP) { + if (!state_has_action_type(state, KM_CORE_IT_BACK)) { + return true; + } } else if (vkey_to_contextreset[vk]) { return true; } diff --git a/core/src/state.hpp b/core/src/state.hpp index d2840fe49c..38795cd232 100644 --- a/core/src/state.hpp +++ b/core/src/state.hpp @@ -188,7 +188,7 @@ struct km_core_state : public km::core::state /** * Evaluate the state and vkey used. - * Determine whether the context should be cleared. + * Determine whether the context should be invalidated. * @param state A pointer to the opaque state object. * @param vk A virtual key that was processed. * @param modifier_state The combinations of modifier keys set at the time key `vk` was pressed, bitmask @@ -198,7 +198,7 @@ struct km_core_state : public km::core::state * @return true if this is a state which should clear the context */ bool -state_should_clear_context(km_core_state *state, +state_should_invalidate_context(km_core_state *state, km_core_virtual_key vk, uint16_t modifier_state, uint8_t is_key_down, diff --git a/core/tests/unit/ldml/invalid-keyboards/ik_000_null_invalid.xml b/core/tests/unit/ldml/invalid-keyboards/ik_000_null_invalid.xml index a16eb61346..6e10b734e9 100644 --- a/core/tests/unit/ldml/invalid-keyboards/ik_000_null_invalid.xml +++ b/core/tests/unit/ldml/invalid-keyboards/ik_000_null_invalid.xml @@ -1,4 +1,4 @@ -