Remove carriage return characters from textboxes

This commit is contained in:
Yousef Khadadeh 2025-12-03 09:29:51 +03:00
parent 06d9fb68f3
commit 244a4fa718
5 changed files with 14 additions and 4 deletions

View file

@ -77,3 +77,8 @@ bool is_valid_http_url(const std::string& str) {
return std::regex_match(str, pattern); return std::regex_match(str, pattern);
} }
std::string remove_carriage_returns_from_str(std::string s) {
std::erase(s, '\r');
return s;
}

View file

@ -10,5 +10,5 @@ std::vector<std::string> split_string_by_token(std::string str, std::string toke
uint8_t ascii_hex_char_to_number_no_checks(char asciiHex); uint8_t ascii_hex_char_to_number_no_checks(char asciiHex);
std::string byte_vector_to_hex_str(const std::vector<uint8_t>& byteVec); std::string byte_vector_to_hex_str(const std::vector<uint8_t>& byteVec);
std::string read_file_to_string(const std::filesystem::path& filePath); 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); bool is_valid_http_url(const std::string& str);
std::string remove_carriage_returns_from_str(std::string s);

View file

@ -389,7 +389,7 @@ void InputManager::process_text_paste(const std::string& plainClipboardStr) {
if(text.textBox) { if(text.textBox) {
// Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself // 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(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()); text.textBox->process_rich_text_input(*text.cursor, lastCopiedRichText.value());
else else
text.textBox->process_text_input(*text.cursor, plainClipboardStr, text.modMap); text.textBox->process_text_input(*text.cursor, plainClipboardStr, text.modMap);

View file

@ -994,7 +994,8 @@ TextPosition TextBox::insert(TextPosition pos, std::string_view textToInsert, co
TextPosition oldPos = pos = move(Movement::NOWHERE, pos); TextPosition oldPos = pos = move(Movement::NOWHERE, pos);
for(char c : textToInsert) { for(char c : textToInsert) {
if(c == '\n') { if(c == '\r') {}
else if(c == '\n') {
if(newlinesAllowed) { if(newlinesAllowed) {
for(auto& [p, tStylesInPos] : tStyleMods) { for(auto& [p, tStylesInPos] : tStyleMods) {
if(p.fParagraphIndex > pos.fParagraphIndex) if(p.fParagraphIndex > pos.fParagraphIndex)

View file

@ -45,9 +45,13 @@ class TextData {
struct Paragraph { struct Paragraph {
std::string text; std::string text;
ParagraphStyleData pStyleData; ParagraphStyleData pStyleData;
template<typename Archive> void serialize(Archive& a) { template<typename Archive> void save(Archive& a) const {
a(text, pStyleData); a(text, pStyleData);
} }
template<typename Archive> void load(Archive& a) {
a(text, pStyleData);
std::erase(text, '\r'); // Remove \r characters from older versions
}
}; };
std::string get_serialized() const; std::string get_serialized() const;
static TextData deserialize_string(std::string& s); static TextData deserialize_string(std::string& s);