Domanda

I'm writing a text editor, and I seem to be not understanding something about gtksourceview and undo. I would like the undo operation to undo a single operation with each call, but it seems to want to do more than that.

Here is an example:

I type two lines:

first line

second line

then I go up and delete the "r" in first, I then hit ctrl+z to perform an undo. What results is this:

first line

second

The documentation says:

Actions are defined as groups of operations between a call to gtk_text_buffer_begin_user_action() and gtk_text_buffer_end_user_action(), or sequences of similar edits (inserts or deletes) on the same line.

I don't see how restoring the "r" and deleting the word "line" are "similar edits (inserts or deletes) on the same line."

It is very disorienting to hit undo and have to remember to hit redo, because more was undone than was expected. Other editors don't act this way, so am I just implementing it wrong?

Here is my undo code: 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);
            }
È stato utile?

Soluzione

Undo is "free" with GtkSourceView, and from your description it sounds like two undo operations are occurring, so it's likely that you are failing to inform Gtk that you handled an event (by returning true), and it is going ahead with its own undo as well. But in any case, the behavior you are seeing isn't normal. You can try the same with e.g. gedit to show this.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top