node-editor: Make Ctrl-Shift-V undoable

This commit is contained in:
Matthias Clasen 2024-08-18 21:45:25 -04:00
parent 16e764b402
commit 22860389de

View File

@ -1631,17 +1631,39 @@ edit_action_cb (GtkWidget *widget,
node_editor_window_edit (self, &start);
}
static void
text_received (GObject *source,
GAsyncResult *result,
gpointer data)
{
GdkClipboard *clipboard = GDK_CLIPBOARD (source);
NodeEditorWindow *self = NODE_EDITOR_WINDOW (data);
char *text;
text = gdk_clipboard_read_text_finish (clipboard, result, NULL);
if (text)
{
GtkTextBuffer *buffer;
GtkTextIter start, end;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->text_view));
gtk_text_buffer_begin_user_action (buffer);
gtk_text_buffer_get_bounds (buffer, &start, &end);
gtk_text_buffer_delete (buffer, &start, &end);
gtk_text_buffer_insert (buffer, &start, text, -1);
gtk_text_buffer_end_user_action (buffer);
g_free (text);
}
}
static void
paste_node_cb (GtkWidget *widget,
const char *action_name,
GVariant *parameter)
{
NodeEditorWindow *self = NODE_EDITOR_WINDOW (widget);
GtkTextBuffer *buffer;
GdkClipboard *clipboard = gtk_widget_get_clipboard (widget);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->text_view));
gtk_text_buffer_set_text (buffer, "", 0);
gtk_text_buffer_paste_clipboard (buffer, gtk_widget_get_clipboard (widget), NULL, TRUE);
gdk_clipboard_read_text_async (clipboard, NULL, text_received, widget);
}
static void