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 673760 - middle-button paste into a GtkTextView leaves the cursor in the wrong place
middle-button paste into a GtkTextView leaves the cursor in the wrong place
Status: RESOLVED DUPLICATE of bug 631195
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.24.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-04-09 01:55 UTC by bob_hepple
Modified: 2013-04-05 13:17 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description bob_hepple 2012-04-09 01:55:14 UTC
In any app with a GtkTextBuffer compare the behaviour of middle-button pasting into a GtkEntry and a GtkTextView. I tried: 

gedit-3.2.6-1.fc16.x86_64 
sylpheed-3.2.0-0.4.beta6.fc16.x86_64 and 
gjots2-2.3.15 which is pygtk.

In GtkEntry it does the right thing IMO ie after the paste, the cursor is positioned at the end of the new selection text.

In GtkTextView it leaves the cursor where it was before the paste.

This is incredibly annoying and just plain wrong.

firefox manages to get it right - as I can attest while I'm typing this - but maybe it's not using GtkTextView.

kate (and presumably the entire kde world) also gets it right.

All this on Fedora-16
Comment 1 bob_hepple 2012-04-15 02:09:42 UTC
Here's a hack for pygtk to fix this:

def on_textView_button_release_event(self, widget, key_event):
	if  key_event.button == 2:
		x, y = self.textView.window_to_buffer_coords(
			self.textView.get_window_type(
				self.textView.get_window(gtk.TEXT_WINDOW_TEXT)),
			int(key_event.x),
			int(key_event.y))
		hit_iter = self.textView.get_iter_at_location(x, y)
		self.textBuffer.place_cursor(hit_iter)
	return 0

This needs binding to the appropriate signal:

"on_textView_button_release_event": self.on_textView_button_release_event,

and in the gtkbuilder file (foobar.ui):

  <object class="GtkTextView" id="textView">
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="wrap_mode">word</property>
    <signal handler="on_textView_button_press_event" name="button_press_event"/>
    <signal handler="on_textView_move_cursor" name="move_cursor"/>
    <signal handler="on_textView_key_press_event" name="key_press_event"/>
    <signal handler="on_textView_button_release_event" name="button_release_event"/>
Comment 2 bob_hepple 2012-04-15 13:13:17 UTC
Hmmm - this is worse than I originally thought. When the PRIMARY is consumed by a middle-button click in a TextView/TextBuffer, the contents of the PRIMARY is wiped. This is wrong. You should be able to paste multiple times with the middle button.

Here is an amended chunk of pygtk which fixes up this behaviour completely as far as I can see - on middle-button click, the cursor is positioned correctly and the PRIMARY buffer contents are still available:

# here's a callback which will be used on middle-button click:
def _insert_primary_callback(clipboard, text, user_data):
	self, x, y = user_data
	hit_iter = self.textView.get_iter_at_location(x, y)
	self.textBuffer.place_cursor(hit_iter)
	self.textBuffer.insert_at_cursor(text)
	clipboard.set_text(text, -1)
	self.msg(_("Text pasted"))

... later in the gui object:

	def on_textView_button_press_event(self, widget, key_event):
		if key_event.button == 2:
			x, y = self.textView.window_to_buffer_coords(
				self.textView.get_window_type(
					self.textView.get_window(gtk.TEXT_WINDOW_TEXT)),
				int(key_event.x),
				int(key_event.y))
			self.primary.request_text(_insert_primary_callback, (self, x, y))
			return 1
Comment 3 Sébastien Wilmet 2013-04-05 13:17:24 UTC

*** This bug has been marked as a duplicate of bug 631195 ***