SF.net SVN: geany:[3014] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sat Sep 27 14:06:43 UTC 2008


Revision: 3014
          http://geany.svn.sourceforge.net/geany/?rev=3014&view=rev
Author:   eht16
Date:     2008-09-27 14:06:43 +0000 (Sat, 27 Sep 2008)

Log Message:
-----------
Make 'Line Breaking' UTF-8 safe (to work with non-ASCII characters).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/editor.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-09-27 14:06:22 UTC (rev 3013)
+++ trunk/ChangeLog	2008-09-27 14:06:43 UTC (rev 3014)
@@ -5,6 +5,8 @@
    Enable wrapping of messages to avoid horizontal scrolling.
    Automatically scroll to the end of the messages when showing the
    dialog or updating its contents.
+ * src/editor.c:
+   Make 'Line Breaking' UTF-8 safe (to work with non-ASCII characters).
 
 
 2008-09-26  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2008-09-27 14:06:22 UTC (rev 3013)
+++ trunk/src/editor.c	2008-09-27 14:06:43 UTC (rev 3014)
@@ -346,7 +346,7 @@
 static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c)
 {
 	ScintillaObject *sci = editor->sci;
-	gint line, lstart;
+	gint line, lstart, col;
 
 	if (!editor->line_breaking)
 		return;
@@ -355,9 +355,12 @@
 		pos--;	/* Look for previous space, not the new one */
 
 	line = sci_get_current_line(sci);
+
 	lstart = sci_get_position_from_line(sci, line);
 
-	if (pos - lstart < editor_prefs.line_break_column)
+	/* use column instead of position which might be different with multibyte characters */
+	col = sci_get_col_from_position(sci, pos);
+	if (col < editor_prefs.line_break_column)
 		return;
 
 	/* look for the last space before line_break_column */
@@ -368,20 +371,20 @@
 		c = sci_get_char_at(sci, --pos);
 		if (c == GDK_space)
 		{
-			gint col, len, diff;
+			gint diff, last_pos, last_col;
 			const gchar *eol = editor_get_eol_char(editor);
 
+			/* remember the distance between the current column and the last column on the line
+			 * (we use column position in case the previous line gets altered, such as removing
+			 * trailing spaces or in case it contains multibyte characters) */
+			last_pos = sci_get_line_end_position(sci, line);
+			last_col = sci_get_col_from_position(sci, last_pos);
+			diff = last_col - col;
+
 			/* break the line after the space */
 			sci_insert_text(sci, pos + 1, eol);
 			line++;
 
-			/* remember distance from end of line (we use column position in case
-			 * the previous line gets altered, such as removing trailing spaces). */
-			pos = sci_get_current_position(sci);
-			len = sci_get_line_length(sci, line);
-			col = sci_get_col_from_position(sci, pos);
-			diff = len - col;
-
 			/* set position as if user had pressed return */
 			pos = sci_get_position_from_line(sci, line);
 			sci_set_current_position(sci, pos, FALSE);
@@ -389,9 +392,12 @@
 			on_new_line_added(editor);
 
 			/* correct cursor position (might not be at line end) */
-			pos = sci_get_position_from_line(sci, line);
-			pos += sci_get_line_length(sci, line) - diff;
+			last_pos = sci_get_line_end_position(sci, line);
+			last_col = sci_get_col_from_position(sci, last_pos); /* get last column on line */
+			/* last column - distance is the desired column, then retrieve its document position */
+			pos = SSM(sci, SCI_FINDCOLUMN, line, last_col - diff);
 			sci_set_current_position(sci, pos, FALSE);
+
 			return;
 		}
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list