diff --git a/core/src/mock/mock_processor.cpp b/core/src/mock/mock_processor.cpp index d014716c87..c56f1f40dd 100644 --- a/core/src/mock/mock_processor.cpp +++ b/core/src/mock/mock_processor.cpp @@ -130,7 +130,9 @@ namespace km { } // For this mock processor we only support queuing PERSIST_OPT action items. if (action_item->type == KM_CORE_IT_PERSIST_OPT && action_item->option) { - state->actions().push_persist(update_option(static_cast(action_item->option->scope), action_item->option->key, action_item->option->value)); + state->actions().push_persist(update_option(static_cast(action_item->option->scope), + action_item->option->key, + action_item->option->value)); return true; } else { @@ -175,6 +177,18 @@ namespace km { u"F2 pressed test save.")); break; } + case KM_CORE_VKEY_F3: + { + state->actions().push_persist( + update_option(KM_CORE_OPT_KEYBOARD, + u"__test_point_3", + u"F3 pressed test save 1.")); + state->actions().push_persist( + update_option(KM_CORE_OPT_KEYBOARD, + u"__test_point_4", + u"F3 pressed test save 2.")); + break; + } case KM_CORE_VKEY_F4: state->context().push_marker(KM_CORE_VKEY_QUOTE); diff --git a/core/src/state.cpp b/core/src/state.cpp index c354d3434b..cf5a00c1da 100644 --- a/core/src/state.cpp +++ b/core/src/state.cpp @@ -40,17 +40,16 @@ actions::actions(actions const &other) : std::vector(other) , _option_items_stack(other._option_items_stack) { - // Update all option pointers to point to the new stack + // Update all option pointers to point to the new stack. + + size_t opt_index = 0; for (auto &item : *this) { - if (item.type == KM_CORE_IT_PERSIST_OPT && item.option) { - // Find the corresponding option in the new stack - // The pointers in the original point to positions in other._option_items_stack - // We need to find the equivalent position in our _option_items_stack - auto original_ptr = item.option; - auto original_base = reinterpret_cast(other._option_items_stack.data()); - auto offset = original_ptr - original_base; - if (offset >= 0 && static_cast(offset) < _option_items_stack.size()) { - item.option = &_option_items_stack[offset]; + if (item.type == KM_CORE_IT_PERSIST_OPT) { + if (opt_index < _option_items_stack.size()) { + item.option = &_option_items_stack[opt_index++]; + } else { + // no matching item in the stack; clear pointer. + item.option = nullptr; } } } diff --git a/core/src/state.hpp b/core/src/state.hpp index 098aad93da..0cd452e7fc 100644 --- a/core/src/state.hpp +++ b/core/src/state.hpp @@ -10,6 +10,7 @@ #include #include +#include #include "keyman_core.h" @@ -27,7 +28,7 @@ using action = km_core_action_item; class actions : public std::vector { - std::vector