changeset 16028:26e519aad395

merge of 'd36941e443b528a93bedee123adfcef05776a8c4' and 'd62256b61a542163041106f71bfb45189710d363'
author Nathan Walp <nwalp@pidgin.im>
date Mon, 09 Apr 2007 12:30:27 +0000
parents 3d29a7353672 (current diff) 326e6a503724 (diff)
children 36722ac9cbe4 00a4de6880da
files
diffstat 1 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gnttextview.c	Mon Apr 09 12:28:46 2007 +0000
+++ b/finch/libgnt/gnttextview.c	Mon Apr 09 12:30:27 2007 +0000
@@ -483,9 +483,12 @@
 	start = end = view->string->str + len;
 
 	while (*start) {
+		GntTextLine *oldl;
 		GntTextSegment *seg = NULL;
 
 		if (*end == '\n' || *end == '\r') {
+			if (!strncmp(end, "\r\n", 2))
+				end++;
 			end++;
 			start = end;
 			gnt_text_view_next_line(view);
@@ -501,8 +504,8 @@
 			view->list = g_list_prepend(view->list, line);
 		}
 
-		if ((end = strchr(start, '\n')) != NULL ||
-			(end = strchr(start, '\r')) != NULL) {
+		if ((end = strchr(start, '\r')) != NULL ||
+			(end = strchr(start, '\n')) != NULL) {
 			len = gnt_util_onscreen_width(start, end - 1);
 			if (len >= widget->priv.width - line->length - 1) {
 				end = NULL;
@@ -527,15 +530,25 @@
 			seg->flags = fl;
 			line->segments = g_list_append(line->segments, seg);
 		}
-		seg->end = end - view->string->str;
-		line->length += len;
 
-		start = end;
+		oldl = line;
 		if (*end && *end != '\n' && *end != '\r') {
+			const char *tmp = end;
+			while (end && *end != '\n' && *end != '\r' && !g_ascii_isspace(*end)) {
+				end = g_utf8_find_prev_char(seg->start + view->string->str, end);
+			}
+			if (!end || !g_ascii_isspace(*end))
+				end = tmp;
+			else
+				end++; /* Remove the space */
+
 			line = g_new0(GntTextLine, 1);
 			line->soft = TRUE;
 			view->list = g_list_prepend(view->list, line);
 		}
+		seg->end = end - view->string->str;
+		oldl->length += len;
+		start = end;
 	}
 
 	view->list = list;