GNOME Bugzilla – Bug 339539
Ctrl-C, Ctrl-V changes tags
Last modified: 2013-09-16 07:51:14 UTC
If something is selected in a GtkTextView, and you press Ctrl-C, Ctrl-V, then it copies selection and pastes it, with tags. The problem is that if start of selection was in the middle of a range with some tag applied, then this tag will be applied to whole inserted chunk of text, so Ctrl-C, Ctrl-V will leave text the same, but tags will change. To reproduce, start gtk-demo, "Multiple Views" thing; in the second paragraph select "styles. For example"; press Ctrl-C, Ctrl-V. Result: whole copied piece of text becomes bold and big.
Looks like the problem is this (gtktextbuffer.c: pre_paste_prep()): /* If we're going to replace the selection, we insert before it to * avoid messing it up, then we delete the selection after inserting. */
Bug 170664 is related.
Created attachment 241177 [details] [review] textbuffer: fix selection replacement when pasting It is more logical to first delete the selection and then pasting the text. When the selection and the text contain tags, the new behavior is more natural. A segfault in paste_from_buffer() is also avoided. The segfault occurs when the text to paste is deleted because it is the selection.
Created attachment 254951 [details] [review] textbuffer: add unit tests for the clipboard It tests gtk_text_buffer_paste_clipboard(), gtk_text_buffer_copy_clipboard() and gtk_text_buffer_cut_clipboard() in various situations, including when GtkTextTags are applied to the selection. The last test didn't pass.
Created attachment 254952 [details] [review] Improve doc of gtk_text_buffer_paste_clipboard() It didn't explain the behavior when there is a non-empty buffer selection.
Comment on attachment 254952 [details] [review] Improve doc of gtk_text_buffer_paste_clipboard() Looks good.
The rest of the patches look good to me. Specially since they are coming with unit tests. I'd say go ahead.
The commits are pushed, thanks for the review.