aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2018-03-11 06:13:45 -0300
committerdequis <dx@dxzone.com.ar>2018-03-11 16:28:38 -0300
commit8167346dd5d87b0bc53c7e396577e19e586954fe (patch)
treec52a11895ffd2da8d5952b632e926a2f64b7a4d8
parent16ea00d7e84a05703e047fa010e2b0621104220b (diff)
Try to join long spaceless lines in paste_buffer without a newline
Fixes trac ticket 1302 The main use case for this is pasting long URLs and not breaking them
-rw-r--r--irc_im.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/irc_im.c b/irc_im.c
index c6de8684..d03f39a8 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -445,6 +445,35 @@ void bee_irc_user_nick_reset(irc_user_t *iu)
}
+#define PASTEBUF_LONG_SPACELESS_LINE_LENGTH 350
+
+/* Returns FALSE if the last line of the message is near the typical irc length
+ * limit and the message has no spaces, indicating that it's probably desirable
+ * to join messages without the newline.
+ *
+ * The main use case for this is pasting long URLs and not breaking them */
+static gboolean bee_irc_pastebuf_should_start_with_newline(const char *msg)
+{
+ int i;
+ const char *last_line = strrchr(msg, '\n') ? : msg;
+
+ if (*last_line == '\n') {
+ last_line++;
+ }
+
+ for (i = 0; last_line[i]; i++) {
+ if (g_ascii_isspace(last_line[i])) {
+ return TRUE;
+ }
+ }
+
+ if (i < PASTEBUF_LONG_SPACELESS_LINE_LENGTH) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/* IRC->IM calls */
static gboolean bee_irc_user_privmsg_cb(gpointer data, gint fd, b_input_condition cond);
@@ -469,7 +498,10 @@ static gboolean bee_irc_user_privmsg(irc_user_t *iu, const char *msg)
iu->pastebuf = g_string_new(msg);
} else {
b_event_remove(iu->pastebuf_timer);
- g_string_append_printf(iu->pastebuf, "\n%s", msg);
+ if (bee_irc_pastebuf_should_start_with_newline(iu->pastebuf->str)) {
+ g_string_append_c(iu->pastebuf, '\n');
+ }
+ g_string_append(iu->pastebuf, msg);
}
if (set_getbool(&iu->irc->b->set, "paste_buffer")) {