aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--include/Text.hpp2
-rw-r--r--src/Text.cpp4
-rw-r--r--src/plugins/Fourchan.cpp2
-rw-r--r--src/plugins/Matrix.cpp38
5 files changed, 30 insertions, 18 deletions
diff --git a/TODO b/TODO
index 4f5ca5d..492b9bf 100644
--- a/TODO
+++ b/TODO
@@ -5,7 +5,7 @@ Animate page navigation.
Add support for special formatting for posts by admins on imageboards.
For image boards, track (You)'s and show notification when somebody replies to your post.
Go to next chapter when reaching the end of the chapter in image endless mode.
-Make code blocks on matrix and 4chan use monospace and have a background of a different color, also syntax coloring?
+Make code blocks on matrix and 4chan use monospace and have a background of a different color.
Allow deleting watch history with delete key (and show confirmation).
Add navigation to nyaa.si submitter torrents.
Create a large texture and add downloaded images to it. This will save memory usage because sfml has to use power of two textures (and so does opengl internally) for textures, so if you have multiple textures they will use more memory than one large texture with the same texture data.
diff --git a/include/Text.hpp b/include/Text.hpp
index daf0d46..02a6b62 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -26,7 +26,7 @@ namespace QuickMedia
enum FormattedTextFlag : uint8_t {
FORMATTED_TEXT_FLAG_NONE = 0,
//FORMATTED_TEXT_FLAG_BOLD = 1 << 0,
- FORMATTED_TEXT_FLAG_MONOSPACE = 1 << 1,
+ FORMATTED_TEXT_FLAG_CODE = 1 << 1,
FORMATTED_TEXT_FLAG_COLOR = 1 << 2
};
diff --git a/src/Text.cpp b/src/Text.cpp
index 836651c..3ecf24c 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -695,7 +695,7 @@ namespace QuickMedia
if(!text_format_stack.empty()) {
if((text_format_stack.top().text_flags & FORMATTED_TEXT_FLAG_COLOR) && !force_color)
text_element_color = text_format_stack.top().color;
- if(text_format_stack.top().text_flags & FORMATTED_TEXT_FLAG_MONOSPACE)
+ if(text_format_stack.top().text_flags & FORMATTED_TEXT_FLAG_CODE)
monospace = true;
}
@@ -789,7 +789,7 @@ namespace QuickMedia
for(size_t i = 0; i < textElement.text.size();)
{
mgl::Color text_color = text_element_color;
- if(!force_color) {
+ if(!force_color && !monospace) {
if(url_range_index < url_ranges.size()) {
size_t string_offset = (textElement.text.data() + i) - str.data();
if(string_offset >= url_ranges[url_range_index].start && string_offset < url_ranges[url_range_index].start + url_ranges[url_range_index].length) {
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index c58d942..4a9d2d7 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -291,7 +291,7 @@ namespace QuickMedia {
break;
case CommentPiece::Type::CODEBLOCK:
// TODO: Use a different colored background
- comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_MONOSPACE);
+ comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_CODE);
break;
}
});
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 31aab76..82ca583 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -131,7 +131,7 @@ namespace QuickMedia {
return str;
}
- static std::string remove_reply_formatting(const Message *message) {
+ static std::string remove_reply_formatting(const Message *message, bool keep_formatted = false) {
if(!message->body_is_formatted && strncmp(message->body.c_str(), "> <@", 4) == 0) {
size_t index = message->body.find("> ", 4);
if(index != std::string::npos) {
@@ -141,7 +141,10 @@ namespace QuickMedia {
}
return message->body;
} else {
- return formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
+ if(keep_formatted)
+ return message->body;
+ else
+ return formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
}
}
@@ -2391,9 +2394,9 @@ namespace QuickMedia {
formatted_text_flags |= FORMATTED_TEXT_FLAG_COLOR;
if(parse_userdata.inside_source_highlight || !parse_userdata.supports_syntax_highlight || (parse_userdata.inside_code_tag && parse_userdata.code_tag_language.size() == 0)) {
- formatted_text_flags |= FORMATTED_TEXT_FLAG_MONOSPACE;
+ formatted_text_flags |= FORMATTED_TEXT_FLAG_CODE;
} else if(parse_userdata.inside_code_tag) {
- formatted_text_flags |= FORMATTED_TEXT_FLAG_MONOSPACE;
+ formatted_text_flags |= FORMATTED_TEXT_FLAG_CODE;
// TODO: guess language from code if no language is set.
// TODO: Allow the user to choose style in config file.
@@ -3622,14 +3625,18 @@ namespace QuickMedia {
return result;
}
- static std::string get_reply_message(const Message *message) {
+ static std::string get_reply_message(const Message *message, bool keep_formatted = false) {
std::string related_to_body;
switch(message->type) {
case MessageType::TEXT: {
- if(message->related_event_type != RelatedEventType::NONE)
- related_to_body = remove_reply_formatting(message);
- else
- related_to_body = message->body;
+ if(message->related_event_type != RelatedEventType::NONE) {
+ related_to_body = remove_reply_formatting(message, keep_formatted);
+ } else {
+ if(keep_formatted && message->body_is_formatted)
+ related_to_body = message->body;
+ else
+ related_to_body = message_to_qm_text(message, false);
+ }
break;
}
case MessageType::IMAGE:
@@ -3644,9 +3651,13 @@ namespace QuickMedia {
case MessageType::FILE:
related_to_body = "sent a file";
break;
- case MessageType::REDACTION:
- related_to_body = message->body;
+ case MessageType::REDACTION: {
+ if(keep_formatted && message->body_is_formatted)
+ related_to_body = message->body;
+ else
+ related_to_body = message_to_qm_text(message, false);
break;
+ }
}
return related_to_body;
}
@@ -3664,8 +3675,9 @@ namespace QuickMedia {
std::string Matrix::create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body) {
std::string formatted_body = body_to_formatted_body(room, body);
- std::string related_to_body = get_reply_message(message);
- html_escape_sequences(related_to_body);
+ std::string related_to_body = get_reply_message(message, true);
+ if(!message->body_is_formatted)
+ html_escape_sequences(related_to_body);
// TODO: Add keybind to navigate to the reply message, which would also depend on this formatting.
// Note: user id and event id is not url escaped here on purpose, because that messes up riot.im replies for certain user ids...
return "<mx-reply>"