After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 339539 - Ctrl-C, Ctrl-V changes tags
Ctrl-C, Ctrl-V changes tags
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
3.9.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-04-24 09:17 UTC by Yevgen Muntyan
Modified: 2013-09-16 07:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
textbuffer: fix selection replacement when pasting (4.23 KB, patch)
2013-04-10 15:47 UTC, Sébastien Wilmet
none Details | Review
textbuffer: add unit tests for the clipboard (4.30 KB, patch)
2013-09-14 23:11 UTC, Sébastien Wilmet
none Details | Review
Improve doc of gtk_text_buffer_paste_clipboard() (1.76 KB, patch)
2013-09-14 23:11 UTC, Sébastien Wilmet
accepted-commit_now Details | Review

Description Yevgen Muntyan 2006-04-24 09:17:16 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.
Comment 1 Yevgen Muntyan 2006-04-24 09:22:41 UTC
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.
   */
Comment 2 Patrik Fimml 2007-05-18 18:49:49 UTC
Bug 170664 is related.
Comment 3 Sébastien Wilmet 2013-04-10 15:47:09 UTC
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.
Comment 4 Sébastien Wilmet 2013-09-14 23:11:37 UTC
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.
Comment 5 Sébastien Wilmet 2013-09-14 23:11:43 UTC
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 6 Ignacio Casal Quinteiro (nacho) 2013-09-16 06:25:14 UTC
Comment on attachment 254952 [details] [review]
Improve doc of gtk_text_buffer_paste_clipboard()

Looks good.
Comment 7 Ignacio Casal Quinteiro (nacho) 2013-09-16 06:27:48 UTC
The rest of the patches look good to me. Specially since they are coming with unit tests. I'd say go ahead.
Comment 8 Sébastien Wilmet 2013-09-16 07:51:14 UTC
The commits are pushed, thanks for the review.