gtk_text_buffer_set_text is non-undoable
Steps to reproduce
- Call gtk_text_buffer_set_text with some text
- Call gtk_text_buffer_undo
Current behavior
Change won't be undone
Expected outcome
Change should be undone, you will get empty textview (deletion and insertion is different changes).
Code example
#!/usr/bin/env -S vala --pkg=gtk4
namespace TestTextBuffer {
class Application : Gtk.Application {
public static Gtk.ApplicationWindow? win = null;
public Application () {
Object (
flags: ApplicationFlags.FLAGS_NONE,
application_id: "com.example.TestTextBuffer"
);
}
protected override void activate () {
if (win == null) {
win = new Gtk.ApplicationWindow (this);
var textbuffer = new Gtk.TextBuffer (null);
var textview = new Gtk.TextView.with_buffer (textbuffer);
// Test buffer test
textbuffer.set_text ("Some text", -1);
textbuffer.set_text ("Test failed", -1);
textbuffer.undo ();
// You'll see `Test failed`. You also can press Ctrl+Z, but it won't work too
win.set_child (textview);
}
win.present ();
}
public static int main (string[] args) {
var app = new TestTextBuffer.Application ();
return app.run (args);
}
}
}
Version information
GTK: 4.2.1
OS: Fedora Workstation 34
Additional information
This worked in GTK3 GtkSourceView. Broken since GTK 4.
Edited by liferooter