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 492794 - Pasting external text at end of view yields wrong scrolling to mark
Pasting external text at end of view yields wrong scrolling to mark
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.12.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 566450 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-11-02 18:26 UTC by Martin Szulecki
Modified: 2009-01-23 21:04 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20


Attachments
patch (4.48 KB, patch)
2007-11-17 15:16 UTC, Yevgen Muntyan
needs-work Details | Review
paste_done (5.93 KB, patch)
2009-01-12 16:13 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
tested patch (5.94 KB, patch)
2009-01-12 16:55 UTC, Paolo Borelli
committed Details | Review

Description Martin Szulecki 2007-11-02 18:26:45 UTC
Please describe the problem:
First noticed in gedit, afterwards verified for GTK.TextView.

If you copy text from an external source (such as browser) and paste it into a TextView which will require scrolling to the cursor position due to lines reaching window height, the paste operation completes however the insert cursor is hidden.

Steps to reproduce:
1. Open some website in a browser window.
2. Copy some text with newlines.
3. Paste text into a TextView component (even gedit) until the number of lines exceed the height of the view.

Repeat 1) but this time copy the same text from within the TextView and compare the scrolling behaviour after having pasted.


Actual results:
Cursor is hidden.

Expected results:
The same behaviour which occours when using text copied from within a TextView with the view scrolling to make the cursor be on the last line in the view.

Does this happen every time?
Yes.

Other information:
Related to BNC https://bugzilla.novell.com/show_bug.cgi?id=181588
Comment 1 Yevgen Muntyan 2007-11-16 13:54:28 UTC
Funny bug, caused by asynchronous paste - gtktextview scrolls immediately after gtk_text_buffer_paste_clipboard() call, but that gets clipboard contents asynchronously (two times since first it requests GtkTextBuffer, then text), so scrolling wins.

Is there an objection to making paste synchronous (using gtk_clipboard_wait_for_everything)? I've never had problems with it, except kind-of-freezing ui during paste when X server is slow; but it didn't seem to be a problem to me (since the whole ui is slow like a dead turtle).
Comment 2 Owen Taylor 2007-11-17 14:35:48 UTC
gtk_clipboard_wait_for_contents() runs the main loop ... so it a) won't block the UI b) doesn't fix any problems with asynchronicity except sometimes makes the code a little more convenient.

However, it can also introduce problems because it runs the main loop. An app might be able to handle a menu item being selected, an incoming network call. So that means gtk_text_buffer_paste_clipboard() can't be changed to use it. It's not possible to take a public API that didn't run the main loop and make it run the main loop.

So, I think a GtkTextBuffer API addition is needed. Possibilities:

gtk_text_buffer_paste_clipboard_and_wait(): 
 - easy to use
 - moderately easy to implement
 - applications users of gtk_text_buffer_paste_clipboard() would need 
   adaption or they'd still have that bug
 - run-the-main-loop functions are never supposed to be the only way
   to do things.

gtk_text_buffer_paste_clipboard_with_callback(, ..., callback, data)
 - A little harder to use
 - moderately easy to implement
 - application users need adaption
 - functions that take function pointers take manual language binding

GtkTextBuffer::paste-received signal
 - easy to use for GtkTextView
 - easy to implement
 - no application adaption needed
 - maybe a little less flexible
Comment 3 Yevgen Muntyan 2007-11-17 15:16:29 UTC
Created attachment 99254 [details] [review]
patch

"paste-done" (you invent a nice name) signal. It seems to be the best (simplest and easiest) option.
Comment 4 Owen Taylor 2007-11-17 18:04:55 UTC
Looks good to me. I'm fine with paste-done as the name. Two suggestions:

 - Would it be useful to pass the GtkClipboard as an argument, so so someone could do something different on middle-button-paste as compared to C-v paste?

 - I think you might as well use one of the padding slots on GtkTextBufferClass instead of using 0 for the default handler offset. If there were only 1-2 left, I'd say differently, but there's 6 at the moment.
Comment 5 Ignacio Casal Quinteiro (nacho) 2009-01-12 16:13:33 UTC
Created attachment 126290 [details] [review]
paste_done

I suppose this is what you wanted.
Comment 6 Paolo Borelli 2009-01-12 16:32:52 UTC
sorry there was a bit of miscommunication between me and nacho about the above patch (he asked me to test since I could not do it and I said "it looks ok", but I just mean that by looking at the patch and I didn't test it).

The patch needs a couple of fixes since it puts the new signal in the middle of the class struct and thus breaks abi. I'll attach a /tested/ patch in a bit
Comment 7 Paolo Borelli 2009-01-12 16:55:23 UTC
Created attachment 126292 [details] [review]
tested patch

This one seems to work fine here
Comment 8 Matthias Clasen 2009-01-12 17:01:01 UTC
Looks fine, please commit. 

It would be good to point out the intended use caes (i.e. scrolling) in the signal docs. 
Comment 9 Paolo Borelli 2009-01-12 17:09:23 UTC
*** Bug 566450 has been marked as a duplicate of this bug. ***
Comment 10 Jean-Philippe Fleury 2009-01-23 19:45:03 UTC
I don't know if it's related to this current bug, but there's the same comportment with Snippets (Edit > Preferences > Plugins > Snippets).

To reproduce the bug with Snippets:

1. Add a new Global Snippet with this content:

/* Line 1: $1
Line 2: $2
Line 3: $3
Line 4: $4
Line 5: $5 */
$0

2. Create a new file in gedit and write enough text to make the right scrollbar appear.

3. Put the cursor to the end of the file and get expanded the previous Global Snippet.

Actual result: we see only the first line of the added comment:

/* Line 1: $1

The scrollbar didn't move to the bottom to allow us to see all the comment.
Comment 11 Paolo Borelli 2009-01-23 19:48:52 UTC
That's a snippets bug, please file a separate reports. Thanks!
Comment 12 Jean-Philippe Fleury 2009-01-23 21:04:59 UTC
(In reply to comment #11)
> That's a snippets bug, please file a separate reports. Thanks!

Done: bug 568916