gboolean is_new_line = TRUE, do_delete = FALSE;
guint i_len = 0;
gboolean linewrap_quote = TRUE;
+ gboolean set_editable_pos = FALSE;
+ gint editable_pos = 0;
guint linewrap_len = prefs_common.linewrap_len;
gchar *qfmt = prefs_common.quotemark;
gchar cbuf[MB_LEN_MAX];
gtk_stext_freeze(text);
- /* make text buffer contiguous */
- /* gtk_stext_compact_buffer(text); */
-
tlen = gtk_stext_get_length(text);
for (; cur_pos < tlen; cur_pos++) {
is_new_line = FALSE;
p_pos = cur_pos;
#ifdef WRAP_DEBUG
- printf("new line i_len=%d p_pos=", i_len);
+ g_print("new line i_len=%d p_pos=", i_len);
dump_text(text, p_pos, tlen, 1);
#endif
}
guint tab_offset = line_len % tab_width;
#ifdef WRAP_DEBUG
- printf("found tab at pos=%d line_len=%d ", cur_pos,
+ g_print("found tab at pos=%d line_len=%d ", cur_pos,
line_len);
#endif
if (tab_offset) {
do_delete = FALSE;
#ifdef WRAP_DEBUG
- printf("found CR at %d do_del is %d next line is ",
+ g_print("found CR at %d do_del is %d next line is ",
cur_pos, do_delete);
dump_text(text, cur_pos + 1, tlen, 1);
#endif
do_delete = FALSE;
#ifdef WRAP_DEBUG
- printf("l_len=%d wrap_len=%d do_del=%d\n",
+ g_print("l_len=%d wrap_len=%d do_del=%d\n",
line_len, linewrap_len, do_delete);
#endif
/* should we delete to perform smart wrapping */
((clen > 1) || isalnum(cb[0]))) {
gtk_stext_insert(text, NULL, NULL,
NULL, " ", 1);
- /* gtk_stext_compact_buffer(text); */
tlen++;
}
do_delete = FALSE;
is_new_line = TRUE;
#ifdef WRAP_DEBUG
- printf("after delete l_pos=");
+ g_print("after delete l_pos=");
dump_text(text, line_pos, tlen, 1);
#endif
continue;
gint clen;
#ifdef WRAP_DEBUG
- printf("should wrap cur_pos=%d ", cur_pos);
+ g_print("should wrap cur_pos=%d ", cur_pos);
dump_text(text, p_pos, tlen, 1);
dump_text(text, line_pos, tlen, 1);
#endif
(text, line_pos, tlen))
line_pos = cur_pos - 1;
#ifdef WRAP_DEBUG
- printf("new line_pos=%d\n", line_pos);
+ g_print("new line_pos=%d\n", line_pos);
#endif
GET_CHAR(line_pos - 1, cbuf, clen);
/* if next character is space delete it */
- if (clen == 1 && isspace(*cbuf)) {
+ if (clen == 1 && isspace(*cbuf)) {
if (p_pos + i_len != line_pos ||
!gtkut_stext_is_uri_string
(text, line_pos, tlen)) {
+ /* workaround for correct cursor
+ position */
+ if (set_editable_pos == FALSE) {
+ editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
+ if (editable_pos == line_pos)
+ set_editable_pos = TRUE;
+ }
gtk_stext_set_point(text, line_pos);
gtk_stext_backward_delete(text, 1);
tlen--;
if (p_pos + i_len == line_pos &&
gtkut_stext_is_uri_string(text, line_pos, tlen)) {
#ifdef WRAP_DEBUG
- printf("found URL at ");
+ g_print("found URL at ");
dump_text(text, line_pos, tlen, 1);
#endif
continue;
else
do_delete = FALSE;
#ifdef WRAP_DEBUG
- printf("after CR insert ");
+ g_print("after CR insert ");
dump_text(text, line_pos, tlen, 1);
dump_text(text, cur_pos, tlen, 1);
#endif
tlen += ins_len;
}
#ifdef WRAP_DEBUG
- printf("after quote insert ");
+ g_print("after quote insert ");
dump_text(text, line_pos, tlen, 1);
#endif
}
}
gtk_stext_thaw(text);
+
+ if (set_editable_pos && editable_pos <= tlen)
+ gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
}
#undef GET_CHAR