2

I've just stumbled upon a subtle problem with my insert comment and undo functions. Steps to reproduce:

  1. open editor
  2. insert comment somewhere in the sourcebuffer
  3. hit ctrl+z to undo
  4. insert another comment, the comment is inserted ok, but the following error shows up in the stdout:

    GtkSourceView-CRITICAL **: modified_changed_handler: assertion `action != NULL' failed

  5. insert another comment, which also works

  6. try to undo by hitting ctrl+z, undo does not work, and the following error shows up in stdout:

    GtkSourceView-CRITICAL **: gtk_source_undo_manager_undo_impl: assertion `undo_action != NULL' failed

From here on undo does not work.

Here is my insert_comment():

    ...
tbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(txtinput[current_tab]));
gtk_text_buffer_get_selection_bounds (tbuffer, &start, &end);

gtk_text_iter_set_line_offset (&start, 0);
gtk_text_buffer_insert (tbuffer, &start, "// \0", -1);
    ...

and my undo keypress definition:

    case GDK_KEY_z:
        if (event -> state & GDK_CONTROL_MASK)
        {

            GtkSourceBuffer *sbuffer;

            sbuffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(txtinput[current_tab])));

            if (gtk_source_buffer_can_undo(sbuffer))
            {
                gtk_source_buffer_undo(sbuffer);
            }

            return TRUE;
        }

        break;

I saw one other person who had this same problem, but no solution was presented. Has anyone else had this problem?

I tried commenting out the "modified-changed" signal connection as a troubleshooting step, but the problem persists.

Any ideas on what I might be doing wrong? Thanks.

nomadicME
  • 1,389
  • 5
  • 15
  • 35
  • 1
    Have you tried putting begin_user_action, end_user_action (gtkTextBuffer methods) around the buffer modifications? – ergosys Dec 22 '12 at 00:08
  • @ergosys, I had my doubts, but I gave it a try and what do you know the problem disappeared. Thanks again. – nomadicME Dec 22 '12 at 02:55
  • Actually I'm surprised, I didn't know if was really needed. I think the view objects must do the same around granular user modifications, but you'll have to examine the source to be sure. Wish this stuff was better documented in any case. – ergosys Dec 22 '12 at 03:52
  • The solution proposed seems to work for many (all?) cases where the buffer is modified outside of GTK-expected methods. It solved a similar issue for me as well. This should be posted as an answer. GTK's view of the stack seems to get out of sync with the actual undo-stack when unconventional modifications are used. – BlackVegetable Jul 30 '13 at 20:53

0 Answers0