[Users] Undo for "Insert file" not working as expected

Michael Gmelin freebsd at grem.de
Fri May 24 15:48:28 CEST 2013

Are there any GTK/claws hackers who could answer this?



After inserting the wrong file into the message compose window by
accident through Message->Insert File, Edit->Undo won't undo this
action in one step, but line by line instead. I can imagine why this is
happening, but I think it's pretty counter intuitive. In fact it
appears to the user that nothing is happening at all, since the cursor
stays at the top of the inserted text after the insert file operation
and therefore removal of lines at the bottom through undo is not

The code in question is (compose.c: compose_insert_file):

  while (fgets(buf, sizeof(buf), fp) != NULL) {
    gchar *str;

    if (g_utf8_validate(buf, -1, NULL) == TRUE)
      str = g_strdup(buf);
      str = conv_codeset_strdup
        (buf, cur_encoding, CS_INTERNAL);
    if (!str) continue;

    /* strip <CR> if DOS/Windows file,
       replace <CR> with <LF> if Macintosh file. */
    len = strlen(str);
    if (len > 0 && str[len - 1] != '\n') {
      while (--len >= 0)
        if (str[len] == '\r') str[len] = '\n';

    gtk_text_buffer_insert(buffer, &iter, str, -1);

So every single gtk_text_buffer_insert call is regarded as one user
action to undo.

If I'm reading the gtk documentation correctly, wrapping this block
(plus the following compose auto wrap action) into


*might* do the trick (I'm not in a position to test this myself right
now, but I assume that the claws developers know gtk pretty well at
this point).


Michael Gmelin

More information about the Users mailing list