aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_view.vala
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2021-08-22 16:34:24 +0300
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-04-13 13:46:32 +0200
commitf9d769883ca6de0d69309a2d09df8e2e63221e26 (patch)
tree5868d055412ae905e946e1c46988090ff843989c /main/src/ui/conversation_view.vala
parentaa57100aad62ae329faa66fc6abfdab70952eb33 (diff)
downloaddino-f9d769883ca6de0d69309a2d09df8e2e63221e26.tar.gz
Adds quote functionality
Diffstat (limited to 'main/src/ui/conversation_view.vala')
-rw-r--r--main/src/ui/conversation_view.vala27
1 files changed, 27 insertions, 0 deletions
diff --git a/main/src/ui/conversation_view.vala b/main/src/ui/conversation_view.vala
index af7e32c1..6015b2c9 100644
--- a/main/src/ui/conversation_view.vala
+++ b/main/src/ui/conversation_view.vala
@@ -17,6 +17,33 @@ public class ConversationView : Gtk.Overlay {
construct {
white_revealer.notify["child-revealed"].connect_after(on_child_revealed_changed);
+ conversation_frame.on_quote_text.connect((t, nick, text) => on_quote_text(nick, text));
+ }
+
+ public void on_quote_text(string nick, string text) {
+ unowned TextBuffer buffer = chat_input.chat_text_view.text_view.buffer;
+ string text_to_quote = text;
+
+ Regex quotes = new Regex("((?<=\n)>.*(\n|$))|(^>.*(\n|$))");
+ Regex whitespace = new Regex("(\n *){2,}");
+ Regex first_column = new Regex("(^|\n)(.+)");
+ Regex end = new Regex("\n*$");
+
+ text_to_quote = quotes.replace(text_to_quote, -1, 0, "");
+ text_to_quote = whitespace.replace(text_to_quote, -1, 0, "\n");
+ text_to_quote = "%s: %s".printf(nick, text_to_quote);
+
+ text_to_quote = first_column.replace(text_to_quote, -1, 0, "\\1> \\2");
+
+ string to_replace = "\n";
+ if(buffer.cursor_position > 0) {
+ to_replace = "";
+ text_to_quote = "\n" + text_to_quote;
+ }
+
+ text_to_quote = end.replace(text_to_quote, -1, 0, to_replace);
+
+ buffer.insert_at_cursor(text_to_quote, -1);
}
public void add_overlay_dialog(Widget widget) {