Opened 10 years ago

Last modified 7 years ago

#390 assigned defect

Copy and Paste onto highlighted text

Reported by: waxhead Owned by:
Priority: critical Milestone:
Component: editor Version: 0.95
Keywords: Cc: yakudzo@…, bramble.andrew@…


v5.10.0 built for i486-linux-gnu-thread-multi

Wx Version: 0.91 wxWidgets 2.8.9

This is trunk after 0.36 was released.

I'm running trunk at the moment.

To replicate the bug, have more than one tab open, highlight the text in the editor copy. In the other tab, hight the text you want to replace and paste.

The highlight disappears and no text is pasted in place.

This does appear to be something 'internal' to Padre. Copying and pasting text externally to Padre works fine.

Attachments (2)

Editor.dif (2.9 KB) - added by code4pay 10 years ago.
Attempted fix for Pasting isssue
390-submersible.patch (1.4 KB) - added by submersible_toaster 10 years ago.

Download all attachments as: .zip

Change History (29)

comment:1 Changed 10 years ago by therek

Gave it a try on my FreeBSD box (i386-freebsd-thread-multi-64int) with exact same versions of Perl/Wx? running r5249 and couldn't reproduce the problem.

comment:2 Changed 10 years ago by waxhead

Interesting, I've updated trunk again tonight.

To test this out I open a new file typed some text and then opened another editor tab and typed some more. Did a copy from one, highlighted some text and did a paste.

It worked as it should.

So to make sure I'm not going mad, I opened a perl script.

I then copied some test from "unsaved 1". I went back to the perlscript, and then highlighted some test and pasted it in, and it failed.

No text was pasted into the file.

I wonder if it's something odd with opening the file?

comment:3 Changed 10 years ago by therek

Alright. I managed to reproduce your problem this time. It appears only when you:

  • first select and copy text,
  • then double click to mark text that's to be replace
  • and then try to paste it.

It does not happen when you select text to be replaced with keyboard (as I usually do).

The source of problem here is that UNIX graphical environments actually utilize two different clipboards for copy/pasting. One is your WM's clipboard (GTK in case of wxGTK) accessible through CTRL-C/CTRL-V, the other one is X11's accessible through mouse text selection for copying and middle button for pasting. This actually allows you to store two different strings in clipboards (try first double clicking, and CTRL-C different texts, then middle-click and CTRL-V).

It appears that wxGTK/STC cripples the content of CTRL-C clipboard when it pulls double-click selection into the clipboard, though it does not happen when you do it the other way around.

A solution to this issue might be grabbing clipboard content on EVT_TEXT_COPY, storing is somewhere (for example in Padre::DB::History) and retrieving it from there on EVT_TEXT_PASTE. Though it might introduce a bit of overhead, that might not be really needed--IMHO it's not a big problem afterall.

comment:4 Changed 10 years ago by patspam

This bug is more extensive for me (Padre 0.37, 0.91 and wxWidgets 2.8.9, Ubuntu 9.04).

Steps to reproduce:
*) Copy some text
*) Select text with the mouse <- immediately clears paste buffer

Does not happen if you select text with the keyboard instead.
Regardless of whether you double-click or not.
Regardless of how many tabs are open.

Perhaps this is a separate bug altogether?

comment:5 Changed 10 years ago by Sewi

The bug is solved (r6885) but unfortunatly the solution has another bug:
When using the middle button for pasting, the (correct) result is sometimes mixed. It seems that another event fires on the middle button, but I can't find it.

comment:6 Changed 10 years ago by Sewi

Update: The 2nd event inserts the content of the X11 clipboard (and not the "regular" filled using Ctrl+C/Ctrl+V).

Open a terminal/shell window, select something and copy it using Ctrl+Shift+C. Go to padre, select something and copy it using Ctrl+C. Now press the middle button (it doesn't happen every time, you may need to try some times): Your padre-selection is being inserted and sometimes also the terminal/shell selection follows.

Maybe, a workaround could backup and clear the X11 buffer on the middle_up event and restore it when the event is done or shortly (~50ms?) after it is done.

comment:7 Changed 10 years ago by code4pay

  • Owner set to code4pay
  • Status changed from new to assigned

comment:8 Changed 10 years ago by code4pay

  • Status changed from assigned to accepted

Hopefully the attached diff fixes this issue. Needs some testing by other people and on Windows

Commit Comment: Fix for Bug #390. Now chooses which clipboard to use selecting and pasting in X11.

Changed 10 years ago by code4pay

Attempted fix for Pasting isssue

comment:9 Changed 10 years ago by Sewi

Patch results:

  • New, empty editor window
  • Write "foo", next line "bar"
  • Select "foo" by double clicking it
  • Select "bar" by double clicking it
  • Press middle button


  • "bar" is replaced by "foo"

What happens:

  • "bar" is (depending on exact cursor position) replaced by "bbarar" or "babarr"


  • Text copied to clipboard by selecting is not usable on other apps (tried using shell window).

comment:10 Changed 10 years ago by yakudzo

  • Cc yakudzo@… added
  • Version changed from trunk to 0.52

This is perl, v5.8.8 built for i686-linux-thread-multi
Wx Version=(0,94) wxWidgets 2.8.10 unicode=(1)
Padre 0.52
KDE 4.3

bug still exist. Steps to reproduce:

1) select some text(e.g New, empty editor window ) and copy to buffer with ctrl+c
2) open padre document and paste it with middle mouse button
3) you will get the result:
NeNew?, empty editor windoww, empty editor window

comment:11 Changed 10 years ago by submersible_toaster

  • Cc bramble.andrew@… added

There are a horde of bugs hiding in here, and working nicely with the X11 implied selection buffer AND a real clipboard seems difficult.

Desired behaviour for users WITHOUT a middle-button-pastes-my-last-selection-addiction..,

  • control-c and select,context click,copy share the same clipboard
  • select text followed by paste replaces the selection with the clipboard buffer

For middle button users, as above and also

Middle button should replace the current selection with the so called 'PrimarySelection?'. The problem this raises is how to distinguish when a selection buffer should be written to the PrimarySelection? or not.

Driving me crazy now...

Changed 10 years ago by submersible_toaster

comment:12 Changed 10 years ago by code4pay

Looks like the patch was not included I will chase that up. Patch was tested by Sewi IRC log from 2009-11-11 Shows the discussion

	Tried it using Gnome texteditor but it doesn't support mid-button at all :-)
	yes though I think you can copy from a terminal and paste to it using middle mouse

	So I guess we need to work out exactly what functionality we want the middle mouse button to perform

	I'd be happy with it working like it would in say a terminal session

	on X11 not sure about windows

	will try with other tools, but currently writing a test :-)


	kdevelop looks like it works pretty well the same as my patch does. ie allows the middle mouse to work as it would in a terminal

	All tests successful :-)


	OK great

	Openoffice: Replace selection does work, but it replaces the selection by the last selected value (the thing being replaced), so it does nothing at all. Won't expect this

	same for poedit


comment:13 Changed 10 years ago by Sewi

  • Version changed from 0.52 to 0.53

Sorry, submersible, but this patch doesn't work for me.
Applied it on r10022.

Middle button pasting doesn't work at all with this patch (for me), nothing is pasted but the current selection (if there is any) is removed (probably replaced by nothing).

comment:14 Changed 10 years ago by Sewi

PS: Using this patch seems to clear the X PrimarySelection? buffer. I used middle-button-paste in a shell window just before starting Padre and now the shell's paste buffer is empty.

comment:15 Changed 10 years ago by submersible_toaster

Folks please ignore the 390-submersible patch (you do you delete attachments in trac?), it's broken.

comment:16 Changed 10 years ago by code4pay

I made a commit, which makes the middle mouse button on X11 work in a way similar to some other editing apps nedit, kate, kdevelop, komodo edit etc. This is achieved by basically letting the Wxcontrol just handle it (we don't call paste at all). However some devs would prefer to keep the old behavior, (which would be my preference as well).

The problem with trying to implement the previous middle button paste functionality is that on X11 the middle mouse will perform an X11 paste not matter what other actions you take in the code (If you remove all copy and paste statements X11 will still do the select and middle button paste). Therefore if we do a paste and there is text in the X11 clipboard it will also perform a paste and you get 2 different texts pasted.

One thought I had was to empty the X11 clipboard before we perform a paste. Problem with this is it seems you can not replace the content of the X11 clipboard by sending it a null value. I tried "" and undef with no luck. There is also a clear function for the clipboard but this seems to only work on the primary clipboard.

The other thought was to copy the content of the primary clipboard to the X11 clipboard. Then when X11 does its paste it will paste only our copied content. This would prevent being able to copy on select from other apps and paste into Padre. And it would also mean that Padre would do an insert when pasting on highlighted text rather than an overwrite defeating the purpose.

I will commit another change that will let the user choose between the
10023 style or the previous style but the previous style will still remain broken, until some one can work out a way around the X11 pasting.

comment:17 Changed 10 years ago by Sewi

It seems that you already tried some things. I'll share my thoughts here without trying them first:

  • Save the clipboard content to a temporary variable
  • Save the current selection start and length
  • Set the current selection length to 0
  • Copy the current selection to the clipboard
  • Restore the current selection start and length
  • Paste
  • (Maybe delayed) restore the clipboard content

The 2nd paste event which occurs in Padre doesn't seem to be a X11 event as it doesn't happen in many other X11 apps. Restoring the pre-r10023 state and debugging which code is actually being run may help. The Devel::Trace module from CPAN might help with this but I never tried it myself.

comment:18 Changed 10 years ago by patspam

Sewi++, code4pay++, submersible_toaster++, ..

Just wanted to say thanks to everyone who's working on squashing this tricky one.. it's far and above the most annoying bug that bites me when using Padre for daily dev. You guys rock!

comment:19 Changed 10 years ago by code4pay

@Sewi, If you look at the example file /Padre/share/examples/wx/ and use the editor you will note on X11 it provides copy and paste using the middle button. Therefore I think my assumption (that X11 will paste regardless) still stands.

comment:20 Changed 10 years ago by submersible_toaster

As I have discovered with several other Wx events... ->Skip can be very important if your event handler is manipulating things that the default handler also manipulates. code4pay is correct in saying that for X11 platforms, NOT performing a padre Paste but allowing the event to propagate results in the generally expected (not always desirable) selection buffer paste that X11 people are familiar with.

The documentation for WxEvent? regarding Skip is somewhat confusing. What it boils down to in my opinion is ; If you want an event to stop propagating because you have handled it, Skip by all means - but be certain you have taken the default event handlers behaviour in mind. On the flip side , if you are being notified of the event but choosing NOT to Skip the propagation to other handlers, be certain you are not mutating things that subsequent handlers would also mutate.

Gives me a headache!

comment:21 Changed 10 years ago by Sewi

Possible fix in r10036.

Thank you, submersible. I tried to change the ->Skip to (1) (on the pre-r10023 state) and was unable to reproduce the duplicate-paste error during ~50 tries.

The PerlMonks? survey got two results (in my opinion):

  1. There is no X11 default
  2. The pre-10023 behavior is what most people like

Please re-check if the error still occurs on your system.

comment:22 Changed 10 years ago by code4pay

  • Owner code4pay deleted
  • Status changed from accepted to assigned

comment:23 Changed 10 years ago by waxhead

How's it going with this? Will this be ready for a release in a few days time?

comment:24 Changed 9 years ago by adamk


comment:25 Changed 8 years ago by bowtie

I have just had the pleasure of reading this, and links.

my I suggest that, as long as Padre response is consistent, the rest is down to education, hence this should be closed,

comment:26 Changed 7 years ago by bowtie

  • Priority changed from major to critical
  • Version changed from 0.53 to 0.95

I Concure

comment:27 Changed 7 years ago by SvenDowideit

This issue annoys the daylights out of me. Every editor except Padre works well, but Padre can't manage to copy&paste 'correctly' on X11.

So i'd much rather not have it closed until it works (especially as i don't use windows much atm)

Note: See TracTickets for help on using tickets.