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

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3014 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2008-09-27 14:06:43 +00:00
parent 8f94954706
commit 72cbba79f7
2 changed files with 20 additions and 12 deletions

View File

@ -5,6 +5,8 @@
Enable wrapping of messages to avoid horizontal scrolling. Enable wrapping of messages to avoid horizontal scrolling.
Automatically scroll to the end of the messages when showing the Automatically scroll to the end of the messages when showing the
dialog or updating its contents. 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> 2008-09-26 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -346,7 +346,7 @@ static void on_update_ui(GeanyEditor *editor, G_GNUC_UNUSED SCNotification *nt)
static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c) static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c)
{ {
ScintillaObject *sci = editor->sci; ScintillaObject *sci = editor->sci;
gint line, lstart; gint line, lstart, col;
if (!editor->line_breaking) if (!editor->line_breaking)
return; return;
@ -355,9 +355,12 @@ static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c)
pos--; /* Look for previous space, not the new one */ pos--; /* Look for previous space, not the new one */
line = sci_get_current_line(sci); line = sci_get_current_line(sci);
lstart = sci_get_position_from_line(sci, line); 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; return;
/* look for the last space before line_break_column */ /* look for the last space before line_break_column */
@ -368,20 +371,20 @@ static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c)
c = sci_get_char_at(sci, --pos); c = sci_get_char_at(sci, --pos);
if (c == GDK_space) if (c == GDK_space)
{ {
gint col, len, diff; gint diff, last_pos, last_col;
const gchar *eol = editor_get_eol_char(editor); 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 */ /* break the line after the space */
sci_insert_text(sci, pos + 1, eol); sci_insert_text(sci, pos + 1, eol);
line++; 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 */ /* set position as if user had pressed return */
pos = sci_get_position_from_line(sci, line); pos = sci_get_position_from_line(sci, line);
sci_set_current_position(sci, pos, FALSE); sci_set_current_position(sci, pos, FALSE);
@ -389,9 +392,12 @@ static void check_line_breaking(GeanyEditor *editor, gint pos, gchar c)
on_new_line_added(editor); on_new_line_added(editor);
/* correct cursor position (might not be at line end) */ /* correct cursor position (might not be at line end) */
pos = sci_get_position_from_line(sci, line); last_pos = sci_get_line_end_position(sci, line);
pos += sci_get_line_length(sci, line) - diff; 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); sci_set_current_position(sci, pos, FALSE);
return; return;
} }
} }