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 590459 - Text is sometimes not pasted at the right location
Text is sometimes not pasted at the right location
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.99.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-08-01 13:30 UTC by Michael Tenenbaum
Modified: 2011-04-19 17:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
this is my ~/.gnome2/gedit (66.95 KB, application/x-compressed-tar)
2011-01-27 22:17 UTC, maxxedout
Details
Screencast illustrating the steps to reproduce the bug (945.62 KB, video/ogg)
2011-01-28 08:01 UTC, Jean-Philippe Fleury
Details

Description Michael Tenenbaum 2009-08-01 13:30:23 UTC
Anyway you do it.. ctrl-v, through the menu or via right click, paste is done in a random location 50% of the time.

Paste is more reliable if Ctrl-v is entered after entering text.  Moving the cursor with left click or arrow keys immediately prior to paste places the text in a random location in the document.
Comment 1 Jean-Philippe Fleury 2009-11-23 14:30:59 UTC
I think it's a duplicate of bug 401194:

https://bugzilla.gnome.org/show_bug.cgi?id=401194
Comment 2 maxxedout 2011-01-27 18:00:10 UTC
I can confirm that this still happens in 2.30.3, from Linux Mint 9 (Ubuntu 10.04.) This makes programming an absolute hell. Unfortunately, I can't give any advice to duplicate this-- just start using Gedit as your every-day programming editor if you don't already, and you *will* run into it.
Comment 3 Michael Tenenbaum 2011-01-27 20:36:21 UTC
Does anyone really care if gedit works or not?  

What do we users need to do to get gedit working?  

I mean no other similar product exhibits this crazy behavior.  

Thus far, the copy-paste functionality is most reliable when the cursor is moved with arrow keys and extremely unreliable when the cursor is moved with the mouse.

So what would it take to get this fixed?
Comment 4 Paolo Borelli 2011-01-27 20:40:12 UTC
Well, I use gedit dayly and never experience this problem and the same is true for all the other gedit developers, so it is very hard to fix it... Beside if this problem was more common we'd have been flooded with duplicate reports, so I fear it may be something very specific to your system.
Comment 5 jessevdk@gmail.com 2011-01-27 21:01:02 UTC
I do have this problem occasionally. There is also another problem, which is that when you Ctrl+C then select some whitespace and you Ctrl+V you're actually pasting the whitespace (as if the primary and secondary clipboard are conflicting). I strongly believe this is a bug in gtk+ though (we don't do anything special afaik). The problem is that it is almost impossible to reproduce in a reliable way, indicating that there is some race condition (intuitively I would think this is because of the asynchronous behavior of the clipboard).
Comment 6 Michael Tenenbaum 2011-01-27 21:17:31 UTC
It's starting to sound like I am speaking to a customer service rep from Asus. 

Instead of just writing us off how about just hearing me out for a minute, please.  

OK?

Other editors do copy-paste fine, so it's not the HW.  Why do you think other editors have no copy-paste issues?

The issue is settling time when the cursor is relocated. 

If one wishes to PASTE and the cursor is relocated by use of the mouse, there is a 50% chance the PASTE will occur at the cursor location and 50% chance the paste will be done at a random location.

But...

If we relocate the cursor with the mouse, then hit left or right arrow keys, then bring the cursor back using arrow keys, the operation becomes more reliable.  Why do you suppose that is?

It then works because the SW finally caught up with the HW. It's an issue that goes back to the 4MHz Z80 days when trying to input an entire screen's worth of data to the UART.  The serial input was faster than the Z80 could handle it.  This cursor issue just smells of the same problem.

Here's a possible solution:

After a relocation via mouse, put in a debounce or a timing loop and things will be cool.  I am almost sure that will work.
Comment 7 maxxedout 2011-01-27 22:17:47 UTC
Created attachment 179473 [details]
this is my ~/.gnome2/gedit
Comment 8 maxxedout 2011-01-27 22:18:48 UTC
Michael, how about if we try to figure out what our gedit configurations have in common?

I've got the following plugins configured at the moment:
* code comment
* document statistics
* file browser pane
* insert date/time
* modelines
* right pane (3rd party plugin)a
* smart spaces
* symbol browser (3rd party)
* tabswitch (3rd party)

However, I happen to know that this problem was still there *before* I added the three 3rd-party plugins, so they have nothing to do with it. 

I have seen an Ubuntu bug report where this bug was blamed on Compiz, however *do not be fooled.* I'm using Metacity without composite enabled. 

I am attaching my ~/.gnome2/gedit, that may help...
Comment 9 Michael Tenenbaum 2011-01-27 22:35:42 UTC
Max, I have been debugging stuff before most of the developers' parents were even conceived.  Forty-six years of debugging stuff tells me that if smells of timing issues, it's a timing issue.  It is NOT configuration.  No way, no how.

What should be done is ALWAYS validate the the cursor location before a paste is done.  Loop around the location function until the function output is identical say ten consecutive times.  That will fix it.
Comment 10 Steve Frécinaux 2011-01-27 22:38:01 UTC
Are you really more than 90 years old?
Comment 11 Ignacio Casal Quinteiro (nacho) 2011-01-27 22:38:12 UTC
As Paolo says we non of the current developers have this problem, so please if you want this fixed, just try to debug GtkTextView and make a patch for it.
Comment 12 Michael Tenenbaum 2011-01-27 22:51:34 UTC
(In reply to comment #10)
> Are you really more than 90 years old?

Just a youthful 62.  And as proof of that, I just shoveled 14 inches of snow off my driveway this morning.  

I started programming as a high school junior when the NSF offered a summer course in Fortran at NYU.
Comment 13 maxxedout 2011-01-27 22:58:38 UTC
Okay, here is one conceivable scenario in which plugins could exacerbate a timing issue-- (and I say this without really knowing how plugins in Gedit are implemented.) Suppose that the "hooks" for each plugin will add some extra execution time to gedit's main loop. Could this not change the timing and induce a race condition where there was none, or something like that? 

So what I will try to do this afternoon is create a simple plugin for gedit that just calls sleep(0.1) a lot or something like that, see if I can make the bug happen more often.
Comment 14 Michael Tenenbaum 2011-01-27 23:31:44 UTC
(In reply to comment #11)
> As Paolo says we non of the current developers have this problem, so please if
> you want this fixed, just try to debug GtkTextView and make a patch for it.

Ignacio:

IMO, it has little to do with debugging GtkTextView.  It has to do with gedit's understanding that data returned from GtkTextView can be unstable for a few milliseconds.  Your developers can solve this in a few hours by just treating the returned data from  GtkTextView as data that needs to be db-bounced while it would take me several months to go through the logic.
Comment 15 Michael Tenenbaum 2011-01-27 23:33:10 UTC
should be de-bounced (not db-bounced)  sorry
Comment 16 maxxedout 2011-01-28 00:36:02 UTC
The problem with the "few milliseconds" thing is that sometimes it happens even if you wait a nontrivial amount of time before pasting.
Comment 17 Michael Tenenbaum 2011-01-28 03:17:25 UTC
(In reply to comment #16)
> The problem with the "few milliseconds" thing is that sometimes it happens even
> if you wait a nontrivial amount of time before pasting.


You can wait decades before pasting but that does not alter the fact that GtkTextView had already supplied the unstable data to gedit immediately after the left mouse click.  

The bug still remains that the cursor location obtained from GtkTextView needs to be de-bounced. Without de-bouncing, the results, as I extrapolate from Ignacio's comments, are hardware dependent.
Comment 18 maxxedout 2011-01-28 06:03:11 UTC
Makes sense.

If that is indeed what the bug is, then this could be fixed either in GtkTextView or in Gedit. Since the documentation for GtkTextView says nothing about debouncing being necessary (or at least [1], which I skimmed,) it may be reasonable to say that this is a TextView bug and not a Gedit bug. 

[1]http://library.gnome.org/devel/gtk/unstable/GtkTextView.html
Comment 19 Ignacio Casal Quinteiro (nacho) 2011-01-28 06:39:51 UTC
gedit inherits from GtkTextView and when we have this kind of issues we do the fixes in GtkTextView directly so everybody can get the fix. As said before either debug GtkTextView or provide a workaround in gedit for now. But really without being able to reproduce we cannot do anything about it.
Comment 20 Jean-Philippe Fleury 2011-01-28 08:00:34 UTC
I also have this bug from time to time and I've just found a way to always reproduce it (I'll attach a screencast to illustrate the following steps):

1) Select text (in the screencast: "projet GNU" on the line 12) and copy it with "Ctrl+c".

2) Deselect the copied text. The cursor is still on the same line (in the screencast: line 12).

3) Move the graphical pointer with the mouse (in the screencast: over the line 28) and click on the scroll wheel. Nothing is copied because there's no selection, and the cursor stays to the same line (in the screencast: line 10).

4) Paste with "Ctrl+v".

Actual result: the previous copied text is pasted on the line clicked with the scroll wheel (in the screencast: line 28).

5) Paste again with "Ctrl+v".

Actual result: the second time we paste, it's OK: the text is pasted where the cursor is (in the screencast: line 12).
Comment 21 Jean-Philippe Fleury 2011-01-28 08:01:33 UTC
Created attachment 179494 [details]
Screencast illustrating the steps to reproduce the bug
Comment 22 Jean-Philippe Fleury 2011-01-28 08:06:39 UTC
(In reply to comment #20)
> Nothing is copied because there's no selection, and the cursor stays to the 
> same line (in the screencast: line 10).

Obviously, it's line 12 (not line 10) in the screencast. Sorry...
Comment 23 maxxedout 2011-01-28 08:35:26 UTC
Ah, so if you accidentally n00bed MOUSE3 due to over-enthusiastic scrolling (or, in my case, *all the time* due to the impreciseness of a touchpad,) it'll paste somewhere between where you started and where you want it to go. 

Note that this definitely does not explain *all* of the problems-- maybe it's a way to reliably generate an old stale position with which to confuse gedit.
Comment 24 Steve Frécinaux 2011-01-28 09:21:00 UTC
Jean-Philippe: you rock! This is indeed 100% reproducible here. It is also reproducible in gtk-demo using Gtk+ 3.0, so I'm reassigning to gtk+.

I'll try to have a look at this bug soon.
Comment 25 Andrew Cowie 2011-01-28 11:30:58 UTC
Is this a side effect of GtkTextView not knowing its own layout until after the signal handlers have run and the idle callback gets around to doing it's thing? That has driven me nuts for a while now, because we lack a programmatic way to say "Look, I know GtkTextView is trying to be smart, but I really need the line-height and y-range parameters to be accurate, so can you just go and do it? Don't worry, I'll wait."

If it is, then I just discovered something that is a bit of a kludge but seems to be serving as a workaround: cycle the main loop with while (gtk_events_pending()) { gtk_main_iteration_do(); } Much to my surprise, this allows the idle handler to run, when it comes back, the allocation has been done and line heights etc are available.

When Michael noted "unstable data from the text view" this came to mind. Position in the GdkWindow is a side effect of layout, and if that hasn't happened in the button press handler which is taking care of paste, then you could easily be getting wrong co-ordinates as a result.

Anyway, just a thought. Sorry for the noise otherwise.

AfC
Comment 26 Ignacio Casal Quinteiro (nacho) 2011-01-28 12:12:05 UTC
I'm working on this.
Comment 27 Ignacio Casal Quinteiro (nacho) 2011-01-28 12:25:56 UTC
Just pushed a patch that fixes this problem. Thanks for reporting it. Also the screencast was really helpful.

http://git.gnome.org/browse/gtk+/commit/?id=b7de18ab35e587df98032eaaa3d159d8f8fd64f4
Comment 28 Ignacio Casal Quinteiro (nacho) 2011-01-28 12:35:53 UTC
BTW, I fixed what I think it was the problem, feel free to reopen the bug or file a new one if you find out that this bug is not fixed.
Comment 29 Michael Tenenbaum 2011-02-26 17:56:14 UTC
Is this fix in gtk+-3.0.1??

Thanks.
Comment 30 Ignacio Casal Quinteiro (nacho) 2011-02-26 18:16:47 UTC
yes it is
Comment 31 maxxedout 2011-04-19 17:41:59 UTC
Has this fix been backported to older versions of GTK? I know the bug exists in older versions.