[evolution-patches] [gtkhtml] cursor movement on line boundaries without white space fix




Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2093
diff -u -p -r1.2093 ChangeLog
--- ChangeLog	18 Feb 2005 13:11:44 -0000	1.2093
+++ ChangeLog	18 Feb 2005 16:25:00 -0000
@@ -1,3 +1,16 @@
+2005-02-18  Radek Doulik  <rodo novell com>
+
+	* htmlcursor.c (html_cursor_down): copy cursor to orig_cursor on
+	the begin to avoid crashes when copying it back
+
+	* test-suite.c
+	(test_cursor_left_right_on_lines_boundaries_wo_white): added new
+	test for moving cursor accros line boundary without white space
+
+	* htmltextslave.c (html_text_slave_get_left_edge): move right in
+	case we are on line boundary without white space
+	(html_text_slave_get_right_edge): as above, but move left
+
 2005-02-15  Radek Doulik  <rodo novell com>
 
 	* htmltextslave.c (draw_text): scale down run_width to engine
Index: htmlcursor.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlcursor.c,v
retrieving revision 1.70
diff -u -p -r1.70 htmlcursor.c
--- htmlcursor.c	2 Feb 2005 16:32:18 -0000	1.70
+++ htmlcursor.c	18 Feb 2005 16:25:03 -0000
@@ -423,6 +423,8 @@ html_cursor_down (HTMLCursor *cursor,
 	else
 		dir = HTML_DIRECTION_LTR;
 
+	html_cursor_copy (&orig_cursor, cursor);
+
 	html_object_get_cursor_base (cursor->object,
 				     engine->painter, cursor->offset,
 				     &x, &y);
Index: htmltextslave.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltextslave.c,v
retrieving revision 1.186
diff -u -p -r1.186 htmltextslave.c
--- htmltextslave.c	18 Feb 2005 13:11:44 -0000	1.186
+++ htmltextslave.c	18 Feb 2005 16:25:35 -0000
@@ -1382,26 +1382,42 @@ static gboolean
 html_text_slave_get_left_edge (HTMLTextSlave *slave, HTMLCursor *cursor)
 {
 	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	int old_offset = cursor->offset;
+	int old_position = cursor->position;
 
 	cursor->offset = html_text_slave_get_left_edge_offset (slave);
 
-	if (pi->attrs [cursor->offset].is_cursor_position)
+	if (pi->attrs [cursor->offset].is_cursor_position && old_offset != cursor->offset)
 		return TRUE;
-	else
-		return html_text_slave_cursor_right (slave, cursor);
+	else {
+		if (html_text_slave_cursor_right (slave, cursor)) {
+			/* we should preserve position here as caller function correct position themselves */
+			cursor->position = old_position;
+			return TRUE;
+		} else
+			return FALSE;
+	}
 }
 
 static gboolean
 html_text_slave_get_right_edge (HTMLTextSlave *slave, HTMLCursor *cursor)
 {
 	HTMLTextPangoInfo *pi = html_text_get_pango_info (slave->owner, NULL);
+	int old_offset = cursor->offset;
+	int old_position = cursor->position;
 
 	cursor->offset = html_text_slave_get_right_edge_offset (slave);
 
-	if (pi->attrs [cursor->offset].is_cursor_position)
+	if (pi->attrs [cursor->offset].is_cursor_position && old_offset != cursor->offset)
 		return TRUE;
-	else
-		return html_text_slave_cursor_left (slave, cursor);
+	else {
+		if (html_text_slave_cursor_left (slave, cursor)) {
+			/* we should preserve position here as caller function correct position themselves */
+			cursor->position = old_position;
+			return TRUE;
+		} else
+			return FALSE;
+	}
 }
 
 gboolean
Index: test-suite.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/test-suite.c,v
retrieving revision 1.9
diff -u -p -r1.9 test-suite.c
--- test-suite.c	11 Feb 2005 14:28:50 -0000	1.9
+++ test-suite.c	18 Feb 2005 16:25:37 -0000
@@ -29,6 +29,7 @@ static int test_cursor_beol_rtl (GtkHTML
 static int test_cursor_left_right_on_items_boundaries (GtkHTML *html);
 static int test_cursor_left_right_on_lines_boundaries (GtkHTML *html);
 static int test_cursor_left_right_on_lines_boundaries_rtl (GtkHTML *html);
+static int test_cursor_left_right_on_lines_boundaries_wo_white (GtkHTML *html);
 static int test_cursor_around_containers (GtkHTML *html);
 
 static int test_quotes_in_div_block (GtkHTML *html);
@@ -43,6 +44,7 @@ static Test tests[] = {
 	{ "left/right on items boundaries", test_cursor_left_right_on_items_boundaries },
 	{ "left/right on lines boundaries", test_cursor_left_right_on_lines_boundaries },
 	{ "left/right on lines boundaries (RTL)", test_cursor_left_right_on_lines_boundaries_rtl },
+	{ "left/right on line boundaries - without white space", test_cursor_left_right_on_lines_boundaries_wo_white },
 	{ "begin/end of line", test_cursor_beol },
 	{ "begin/end of line (RTL)", test_cursor_beol_rtl },
 	{ "around containers", test_cursor_around_containers },
@@ -305,6 +307,27 @@ static int test_cursor_left_right_on_lin
 	return TRUE;
 }
 
+static int test_cursor_left_right_on_lines_boundaries_wo_white (GtkHTML *html)
+{
+	load_editable (html, "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo%next line");
+
+	html_cursor_jump_to_position (html->engine->cursor, html->engine, 81);
+
+	if (html->engine->cursor->offset != 81
+	    || html->engine->cursor->position != 81
+	    || !html_cursor_left (html->engine->cursor, html->engine)
+	    || html->engine->cursor->offset != 80
+	    || html->engine->cursor->position != 80
+	    || !html_cursor_right (html->engine->cursor, html->engine)
+	    || html->engine->cursor->offset != 81
+	    || html->engine->cursor->position != 81)
+		return FALSE;
+
+	printf ("test_cursor_left_right_on_lines_boundaries_wo_white: passed\n");
+
+	return TRUE;
+}
+
 static int test_cursor_beol (GtkHTML *html)
 {
 	load_editable (html, "<pre>simple line\nsecond line\n");
@@ -524,6 +547,8 @@ int main (int argc, char *argv[])
 	gtk_html_set_editable (html, TRUE);
 	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 	gtk_container_add (GTK_CONTAINER (win), html_widget);
+
+	/* gtk_widget_show_all (win); */
 
 	n_all = n_successful = 0;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]