diff --git a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp index f908907..edc45a5 100644 --- a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp @@ -24,6 +24,8 @@ bool TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { auto& a = static_cast(comp->obj->get_comp()); Toolbar& t = drawP.world.main.toolbar; + auto& currentMods = *currentModsPtr; + t.gui.push_id("edit tool text"); t.gui.text_label_centered("Edit Text"); @@ -264,6 +266,8 @@ uint8_t TextBoxEditTool::get_new_decoration_value() { } void TextBoxEditTool::set_styles_at_selection(TextBoxCanvasComponent& a) { + auto& currentMods = *currentModsPtr; + TextPosition start = std::min(a.cursor->selectionBeginPos, a.cursor->selectionEndPos); TextPosition end = std::max(a.cursor->selectionBeginPos, a.cursor->selectionEndPos); if(start == end) @@ -325,7 +329,7 @@ void TextBoxEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::O .autocorrect = true, .multiline = true, .androidInputType = InputManager::AndroidInputType::ANDROIDTEXT_TYPE_CLASS_TEXT - }); + }, currentModsPtr); } bool TextBoxEditTool::edit_update(CanvasComponentContainer::ObjInfo* comp) { diff --git a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.hpp b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.hpp index b857d67..f211733 100644 --- a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.hpp +++ b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.hpp @@ -46,7 +46,7 @@ class TextBoxEditTool : public DrawingProgramEditToolBase { std::unordered_map> undoHeldData; - RichText::TextStyleModifier::ModifierMap currentMods; + std::shared_ptr currentModsPtr = std::make_shared(); std::vector sortedFontList; diff --git a/src/InputManager.cpp b/src/InputManager.cpp index c72d4f6..7b1cd8a 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -30,6 +30,13 @@ extern "C" { #include "MainProgram.hpp" +template std::optional shared_ptr_to_opt(const std::shared_ptr o) { + if(o) + return *o; + else + return std::nullopt; +} + InputManager::InputManager(MainProgram& initMain): main(initMain) { frame_reset({0, 0}); @@ -88,7 +95,7 @@ InputManager::InputManager(MainProgram& initMain): keyAssignments = defaultKeyAssignments; } -void InputManager::set_rich_text_box_input_front(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::optional& nModMap) { +void InputManager::set_rich_text_box_input_front(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr& nModMap) { Text::TextBoxInfo textBoxInfo; textBoxInfo.textBox = nTextBox; textBoxInfo.cursor = nCursor; @@ -100,7 +107,7 @@ void InputManager::set_rich_text_box_input_front(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::optional& nModMap) { +void InputManager::set_rich_text_box_input_back(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr& nModMap) { Text::TextBoxInfo textBoxInfo; textBoxInfo.textBox = nTextBox; textBoxInfo.cursor = nCursor; @@ -123,7 +130,7 @@ void InputManager::Text::add_text_to_textbox(const std::string& inputText) { if(!textBoxes.empty() && !inputText.empty()) { auto& frontTextBox = textBoxes.front(); do_textbox_operation_with_undo([&]() { - frontTextBox.textBox->process_text_input(*frontTextBox.cursor, inputText, frontTextBox.modMap); + frontTextBox.textBox->process_text_input(*frontTextBox.cursor, inputText, shared_ptr_to_opt(frontTextBox.modMap)); }); } } @@ -859,7 +866,7 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) { std::shared_ptr textBox = text.textBoxes.empty() ? nullptr : text.textBoxes.front().textBox; std::shared_ptr cursor = text.textBoxes.empty() ? nullptr : text.textBoxes.front().cursor; - std::optional modMap = text.textBoxes.empty() ? std::nullopt : text.textBoxes.front().modMap; + std::optional modMap = text.textBoxes.empty() ? shared_ptr_to_opt(text.textBoxes.front().modMap) : std::nullopt; switch(kPress) { case SDLK_UP: @@ -1043,10 +1050,10 @@ void InputManager::process_text_paste(const std::string& plainClipboardStr) { if(lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(plainClipboardStr)) text.textBoxes.front().textBox->process_rich_text_input(*text.textBoxes.front().cursor, lastCopiedRichText.value()); else - text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, text.textBoxes.front().modMap); + text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, shared_ptr_to_opt(text.textBoxes.front().modMap)); } else - text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, text.textBoxes.front().modMap); + text.textBoxes.front().textBox->process_text_input(*text.textBoxes.front().cursor, plainClipboardStr, shared_ptr_to_opt(text.textBoxes.front().modMap)); } } diff --git a/src/InputManager.hpp b/src/InputManager.hpp index ffd3e99..787c449 100644 --- a/src/InputManager.hpp +++ b/src/InputManager.hpp @@ -158,8 +158,8 @@ struct InputManager { int androidInputType; }; - void set_rich_text_box_input_front(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::optional& nModMap = std::nullopt); - void set_rich_text_box_input_back(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::optional& nModMap = std::nullopt); + void set_rich_text_box_input_front(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr& nModMap = nullptr); + void set_rich_text_box_input_back(const std::shared_ptr& nTextBox, const std::shared_ptr& nCursor, bool isRichTextBox, const std::shared_ptr>& textboxRect, const TextInputProperties& inputProps, const std::shared_ptr& nModMap = nullptr); void remove_rich_text_box_input(const std::shared_ptr& nTextBox); struct Text { @@ -176,7 +176,7 @@ struct InputManager { std::shared_ptr textBox; std::shared_ptr cursor; std::shared_ptr> rect; - std::optional modMap; + std::shared_ptr modMap; TextInputProperties textInputProperties; UndoManager textboxUndo; };