diff --git a/include/Helpers/StringHelpers.cpp b/include/Helpers/StringHelpers.cpp index b4c72c9..c3baf43 100644 --- a/include/Helpers/StringHelpers.cpp +++ b/include/Helpers/StringHelpers.cpp @@ -77,3 +77,8 @@ bool is_valid_http_url(const std::string& str) { return std::regex_match(str, pattern); } + +std::string remove_carriage_returns_from_str(std::string s) { + std::erase(s, '\r'); + return s; +} diff --git a/include/Helpers/StringHelpers.hpp b/include/Helpers/StringHelpers.hpp index 7eed591..006067a 100644 --- a/include/Helpers/StringHelpers.hpp +++ b/include/Helpers/StringHelpers.hpp @@ -10,5 +10,5 @@ std::vector split_string_by_token(std::string str, std::string toke uint8_t ascii_hex_char_to_number_no_checks(char asciiHex); std::string byte_vector_to_hex_str(const std::vector& byteVec); std::string read_file_to_string(const std::filesystem::path& filePath); -void remove_whitespaces_from_str(std::string& str); bool is_valid_http_url(const std::string& str); +std::string remove_carriage_returns_from_str(std::string s); diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 76281b0..e432ff8 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -389,7 +389,7 @@ void InputManager::process_text_paste(const std::string& plainClipboardStr) { if(text.textBox) { // Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself if(text.isRichTextBox && text.isNextPasteRich && lastCopiedRichText.has_value()) { - if(lastCopiedRichText.value().get_plain_text() == plainClipboardStr) + if(lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(plainClipboardStr)) text.textBox->process_rich_text_input(*text.cursor, lastCopiedRichText.value()); else text.textBox->process_text_input(*text.cursor, plainClipboardStr, text.modMap); diff --git a/src/RichText/TextBox.cpp b/src/RichText/TextBox.cpp index 09fd015..784c2c7 100644 --- a/src/RichText/TextBox.cpp +++ b/src/RichText/TextBox.cpp @@ -994,7 +994,8 @@ TextPosition TextBox::insert(TextPosition pos, std::string_view textToInsert, co TextPosition oldPos = pos = move(Movement::NOWHERE, pos); for(char c : textToInsert) { - if(c == '\n') { + if(c == '\r') {} + else if(c == '\n') { if(newlinesAllowed) { for(auto& [p, tStylesInPos] : tStyleMods) { if(p.fParagraphIndex > pos.fParagraphIndex) diff --git a/src/RichText/TextBox.hpp b/src/RichText/TextBox.hpp index 8ad0dd5..2212381 100644 --- a/src/RichText/TextBox.hpp +++ b/src/RichText/TextBox.hpp @@ -45,9 +45,13 @@ class TextData { struct Paragraph { std::string text; ParagraphStyleData pStyleData; - template void serialize(Archive& a) { + template void save(Archive& a) const { a(text, pStyleData); } + template void load(Archive& a) { + a(text, pStyleData); + std::erase(text, '\r'); // Remove \r characters from older versions + } }; std::string get_serialized() const; static TextData deserialize_string(std::string& s);