View Issue Details

IDProjectCategoryView StatusLast Update
0021453LazarusWidgetsetpublic2019-08-20 17:04
ReportercobinesAssigned ToMartin Friebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux i386OSDebianOS VersionSid
Product Version0.9.31 (SVN)Product Build35868 
Target Version1.10Fixed in Version1.10 
Summary0021453: Remove trailing zero when copying to clipboard (gtk2)
DescriptionLCL adds trailing zero to anything copied to clipboard:

In TClipboard.SetAsText():
  SetBuffer(PredefinedClipboardFormat(pcfText),s[1],length(Value)+1);

Note, length(Value)+1 is used.

In Linux this seems to be unneccessary. LCLQT cuts the trailing zero as well. Attached patch makes the LCLGTK2 also remove the trailing zero.

Mailing list discussion:
http://lists.lazarus.freepascal.org/pipermail/lazarus/2012-March/072017.html
TagsNo tags attached.
Fixed in Revision58530 (r53376, r53380, r55180)
LazTarget1.10
WidgetsetGTK 2
Attached Files
  • clipzero.diff (657 bytes)
    Index: lcl/interfaces/gtk2/gtk2callback.inc
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2callback.inc	(wersja 35868)
    +++ lcl/interfaces/gtk2/gtk2callback.inc	(kopia robocza)
    @@ -3362,6 +3362,9 @@
                 if BufLength>0 then begin
                   GetMem(Buffer,BufLength);
                   MemStream.Read(Buffer^,BufLength);
    +              // LCL attaches trailing zero - remove it.
    +              if PByte(Buffer)[BufLength-1] = 0 then
    +                Dec(BufLength);
                   {SetLength(s,MemStream.Size);
                   MemStream.Position:=0;
                   MemStream.Read(s[1],MemStream.Size);
    
    clipzero.diff (657 bytes)
  • issue21453.patch (1,112 bytes)
    From 3ba3d9b44660621e69a6da7d391a37c8db666445 Mon Sep 17 00:00:00 2001
    From: Basile Burg <basile.b@gmx.com>
    Date: Thu, 17 Nov 2016 00:32:38 +0100
    Subject: [PATCH] fix issues 21453 and 30071
    
    Under gtk2, the clipboard content doesn't need a null terminator because
    it's added by GTK automatically
    ---
     lcl/interfaces/gtk2/gtk2callback.inc | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/lcl/interfaces/gtk2/gtk2callback.inc b/lcl/interfaces/gtk2/gtk2callback.inc
    index 51fd155..4ee068b 100644
    --- a/lcl/interfaces/gtk2/gtk2callback.inc
    +++ b/lcl/interfaces/gtk2/gtk2callback.inc
    @@ -3678,6 +3678,10 @@ begin
               {$IFDEF DEBUG_CLIPBOARD}
               DebugLn('[ClipboardSelectionRequestHandler] Len=',dbgs(BufLength));
               {$ENDIF}
    +          // workaround for issues 21453 and 30071.
    +          // gtk_selection_data_set auto adds the required null term.
    +          if PChar(Buffer + BufLength - 1)^ = #0 then
    +            dec(BufLength);
               gtk_selection_data_set(SelectionData,SelectionData^.Target,BitCount,
                 Buffer,BufLength);
               if Buffer<>nil then
    -- 
    2.1.4
    
    
    issue21453.patch (1,112 bytes)
  • gtk2callback.diff (714 bytes)
    Index: lcl/interfaces/gtk2/gtk2callback.inc
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2callback.inc	(revision 54167)
    +++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
    @@ -3571,8 +3571,8 @@
       Assert(Assigned(Buffer) and (BufLength>0), 'SetData: GTK2 clipboard Buffer=Nil or empty.');
       MemStream.Read(Buffer^,BufLength);
       // Issue #21453. gtk_selection_data_set adds the required null. Remove it here.
    -  if PChar(Buffer+BufLength-1)^ = #0 then
    -    dec(BufLength);
    +//  if PChar(Buffer+BufLength-1)^ = #0 then  //roger
    +//    dec(BufLength);
       gtk_selection_data_set(SelectionData,SelectionData^.Target,8,Buffer,BufLength);
       FreeMem(Buffer);
     end;
    
    gtk2callback.diff (714 bytes)
  • gtk2_selection_copy_paste.diff (1,409 bytes)
    Index: lcl/interfaces/gtk2/gtk2callback.inc
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2callback.inc	(revision 54155)
    +++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
    @@ -3564,16 +3564,29 @@
     procedure SetData(SelectionData: PGtkSelectionData; MemStream: TMemoryStream);
     var
       Buffer: Pointer;
    -  BufLength: integer;
    +  BufLength: gint;
    +  ALastByte: Byte;
     begin
    -  BufLength:=integer(MemStream.Size);
    -  GetMem(Buffer,BufLength);
    +  BufLength := gint(MemStream.Size);
    +  GetMem(Buffer, BufLength);
       Assert(Assigned(Buffer) and (BufLength>0), 'SetData: GTK2 clipboard Buffer=Nil or empty.');
    -  MemStream.Read(Buffer^,BufLength);
       // Issue #21453. gtk_selection_data_set adds the required null. Remove it here.
    -  if PChar(Buffer+BufLength-1)^ = #0 then
    +  if SelectionData^.length < 0 then
    +  begin
    +    SelectionData^.format := 8;
    +    SelectionData^.length := 0;
    +  end;
    +  MemStream.Read(Buffer^, BufLength - 1);
    +  ALastByte := MemStream.ReadByte;
    +  if ALastByte <> 0 then
    +  begin
    +    FreeMem(Buffer);
    +    GetMem(Buffer, BufLength);
    +    MemStream.Position := 0;
    +    MemStream.Read(Buffer^, BufLength);
    +  end else
         dec(BufLength);
    -  gtk_selection_data_set(SelectionData,SelectionData^.Target,8,Buffer,BufLength);
    +  gtk_selection_data_set(SelectionData,SelectionData^.Target, 8, Buffer, BufLength);
       FreeMem(Buffer);
     end;
     
    

Relationships

related to 0031547 closedJuha Manninen You can't paste text copied from other Lazarus instance 
has duplicate 0030071 closedJuha Manninen text copied from synedit and paste in Chrome includes a trailling null char 
has duplicate 0034116 resolvedJuha Manninen Setting clipboard text adds a character at the end of the text 
related to 0035984 resolvedDmitry Boyarintsev Clipboard.SetAsText includes an extra #0 character 

Activities

2012-03-10 14:53

 

clipzero.diff (657 bytes)
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(wersja 35868)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(kopia robocza)
@@ -3362,6 +3362,9 @@
             if BufLength>0 then begin
               GetMem(Buffer,BufLength);
               MemStream.Read(Buffer^,BufLength);
+              // LCL attaches trailing zero - remove it.
+              if PByte(Buffer)[BufLength-1] = 0 then
+                Dec(BufLength);
               {SetLength(s,MemStream.Size);
               MemStream.Position:=0;
               MemStream.Read(s[1],MemStream.Size);
clipzero.diff (657 bytes)

Zeljan Rikalo

2012-03-10 15:48

developer   ~0057464

According to discussion on mailing list: do we need trailing zero in lcl at all ?

cobines

2012-03-10 17:16

reporter   ~0057466

It seems to be required by Windows (as says in SVN commit message that added it). It doesn't seem to be required on Linux. But I can't check other systems.

Zeljan Rikalo

2012-03-10 18:03

developer   ~0057468

If it's required by windows it should be totally removed from LCL and added to wswin32 code if possible, if not add new LCLCapability which says eg. lclClipboardTextNeedTerminator

cobines

2012-03-13 04:15

reporter   ~0057545

In MSDN it says CF_OEMTEXT, CF_TEXT, CF_UNICODETEXT must be null-terminated. Copying to clipboard without the terminator causes the last character of the string to be cut when pasting to another application.

Juha Manninen

2013-04-29 11:46

developer   ~0067258

It seems the code should be cleaned as Zeljan suggested.
Could somebody please make a patch that moves the trailing zero handling to Windows binding code.

jamie philbrook

2016-04-28 23:25

reporter   ~0092282

Last edited: 2016-04-28 23:49

View 2 revisions

I think its a bad idea removing the NULL on the strings.

 All pointer operations depend on the Null character as the
terminating index ontop of tons of other things in the real world.

 Please don't remove it, I can guarantee it'll open up a whole can
of worms.
 
 ShortStrings is the only acception, but that too should have a
null added if placed on the clipboard with no leading size index.

 Shortstrings is more of an internal format..
Please think about It before doing it.

 The correct way to fix this is to correct the Windows implemention to have
it add a NULL in the window bindings for ctText and remove the +1 to the
length.
  This will even work for shortStrings which does not have a Null at the
end.

BBaz

2016-06-15 09:02

reporter   ~0093204

May I insist ? Nobody wants to make a patch ?

This bug is a real concern. It really happens often. A lot of web sites with dynamic content cut the content that's posted when they reach a null character.
Do when you

   write $1 - paste from a synedit - write $2

$2 is not included by those websites.

Thaddy de Koning

2016-06-15 11:23

reporter   ~0093207

Last edited: 2016-06-15 11:24

View 2 revisions

The problem is that linux strings are C strings, so terminated by the zero and not allowing any zero's in between!.
Pascal strings are fundamentally different, because they have a length prefix, so can contain zero's in between.

- Rip the zero's except the last one.
- Only then write as web content.

Seems to be the only real option.

BTW: this is not a bug imo.

BBaz

2016-06-15 14:26

reporter   ~0093219

Last edited: 2016-06-15 14:36

View 2 revisions

Of course this is a bug ;) I can use kwrite or any other text editor, copy and paste on the sites I talk about, add a paragraph after the paste, post, and the content will not contain the null sentinel.

- GTK adds in intern the null term
- Windows does not
- TCLipboard add a null for the windows version
=> under linux with GTK we have a bug because there's actually two null.

BBaz

2016-07-08 07:59

reporter   ~0093618

Last edited: 2016-07-08 08:00

View 2 revisions

Even your Mantis setup is affected, for example today I've reported this: http://bugs.freepascal.org/view.php?id=30359. The title contains a class name that's copied from Lazarus source code editor, so there was a #0 after the paste.

It was cut and I had to add a note... (the title might be corrected when you'll read this)...so, if it's still not clear enough for you that this is a serious bug I'll get on posting examples of how it hits in the every-day life, again and again.

BBaz

2016-08-23 15:33

reporter   ~0094285

Last edited: 2016-08-23 15:43

View 2 revisions

Yet another example: some stuff copied from Lazarus under linux then paste on a website, then some '?' are displayed:

http://www.programming-idioms.org/idiom/102/load-from-http-get-request-into-a-file/1802/pascal

BBaz

2016-09-21 14:52

reporter   ~0094752

Monthly reminder

Juha Manninen

2016-09-23 08:11

developer   ~0094786

Last edited: 2016-09-23 08:12

View 3 revisions

BBaz, the issue does not need reminders but it needs a patch to fix it.
It should be fixed in widgetset code.

BBaz

2016-11-17 00:36

reporter  

issue21453.patch (1,112 bytes)
From 3ba3d9b44660621e69a6da7d391a37c8db666445 Mon Sep 17 00:00:00 2001
From: Basile Burg <basile.b@gmx.com>
Date: Thu, 17 Nov 2016 00:32:38 +0100
Subject: [PATCH] fix issues 21453 and 30071

Under gtk2, the clipboard content doesn't need a null terminator because
it's added by GTK automatically
---
 lcl/interfaces/gtk2/gtk2callback.inc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lcl/interfaces/gtk2/gtk2callback.inc b/lcl/interfaces/gtk2/gtk2callback.inc
index 51fd155..4ee068b 100644
--- a/lcl/interfaces/gtk2/gtk2callback.inc
+++ b/lcl/interfaces/gtk2/gtk2callback.inc
@@ -3678,6 +3678,10 @@ begin
           {$IFDEF DEBUG_CLIPBOARD}
           DebugLn('[ClipboardSelectionRequestHandler] Len=',dbgs(BufLength));
           {$ENDIF}
+          // workaround for issues 21453 and 30071.
+          // gtk_selection_data_set auto adds the required null term.
+          if PChar(Buffer + BufLength - 1)^ = #0 then
+            dec(BufLength);
           gtk_selection_data_set(SelectionData,SelectionData^.Target,BitCount,
             Buffer,BufLength);
           if Buffer<>nil then
-- 
2.1.4

issue21453.patch (1,112 bytes)

BBaz

2016-11-17 00:42

reporter   ~0095942

The problem is clear now. The null terminator is indeed needed on all the platforms. What happens is that the GTK2 API adds the null terminator, it's documented:

https://developer.gnome.org/gtk3/stable/gtk3-Selections.html#gtk-selection-data-set

"Zero-terminates the stored data." This means that the function **does it automatically** and not that the user has to.

Unless someone wants to add a new LCL capability I think that the workaround proposed in 2012 can be applied. I'll just document this as a workaround/temp fix. It's almost 5 years now so this patch is better than nothing. At a certain point something has to be done. This is a issue that hits very often. We seriously should have something else to fill our brain with than "remember to hit backspace after you've paste".


Note that you should not use the first (2012) patch. A second patch is updated for the latest revision (http://bugs.freepascal.org/file_download.php?file_id=25415&type=bug)

Please, take a decision !
Thanks.

Juha Manninen

2016-11-17 14:43

developer   ~0095952

I applied your patch + added a check for (BufLength>0) in r53376.
Thanks.
I think it is OK to change only GTK2 code if the problem is only there. (Is it?)

Then I refactored ClipboardSelectionRequestHandler in 2 commits to make the code easier to understand and more encapsulated. I separated 2 procedures, Transform2CompoundText and SetData.
Please take a look.

Question: there are 2 calls to gtk_selection_data_set(). Your patch deals with only one of them. Is it correct?

BBaz

2016-11-18 01:14

reporter   ~0095976

> Question: there are 2 calls to gtk_selection_data_set(). Your patch deals with only one of them. Is it correct?

The first branch seems to be only related to internal LCL clipboard operation. For this branch i've never noticed any bug even if it's quite probable that the data terminates with 2 #0.

BBaz

2016-11-18 01:20

reporter   ~0095977

> I think it is OK to change only GTK2 code if the problem is only there. (Is it?)
Gtk2 always adds the null terminator. I seems to be a design choice related to security

BBaz

2016-11-18 01:33

reporter   ~0095978

I've looked at the commit. I think that adding a null terminator in "Transform2CompoundText" (line 3593 and 3595) is really not needed. The doc specifies well that it's added automatically.

Otherwise the issue is fixed. I'll test if you change "Transform2CompoundText", trusting gtk2 doc.

Juha Manninen

2016-11-18 17:04

developer   ~0096008

I removed the extra #0 in r53380.
Thanks.

Juha Manninen

2017-02-16 18:34

developer   ~0098230

Last edited: 2017-02-17 17:28

View 2 revisions

Reopening. Text cannot be copied between 2 Lazarus instances now.
http://forum.lazarus.freepascal.org/index.php/topic,35880

Roger Olsson

2017-02-17 13:43

reporter  

gtk2callback.diff (714 bytes)
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 54167)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -3571,8 +3571,8 @@
   Assert(Assigned(Buffer) and (BufLength>0), 'SetData: GTK2 clipboard Buffer=Nil or empty.');
   MemStream.Read(Buffer^,BufLength);
   // Issue #21453. gtk_selection_data_set adds the required null. Remove it here.
-  if PChar(Buffer+BufLength-1)^ = #0 then
-    dec(BufLength);
+//  if PChar(Buffer+BufLength-1)^ = #0 then  //roger
+//    dec(BufLength);
   gtk_selection_data_set(SelectionData,SelectionData^.Target,8,Buffer,BufLength);
   FreeMem(Buffer);
 end;
gtk2callback.diff (714 bytes)

Roger Olsson

2017-02-17 13:47

reporter   ~0098249

Last edited: 2017-02-17 13:57

View 3 revisions

Uploaded patch/diff file for trunk. My first, hope it is correct.

Cyrax

2017-02-17 14:10

reporter   ~0098250

My research on X clipboard reveals that it can support multiple formats. Rather than changing current fixed functionality, I would suggest adding special format for Lazarus only so it can process copying & pasting between two or more Lazarus instances.

Roger Olsson

2017-02-17 15:57

reporter   ~0098253

It's not acceptable to leave Copy & Paste between Lazarus instances broken. The patch should be applied so this functionality is restored. Then, when a solution is found that doesn't break copy/paste, the trailing zero can be removed. But not before that.

Juha Manninen

2017-02-17 17:27

developer   ~0098258

> Then, when a solution is found that doesn't break copy/paste,
> the trailing zero can be removed. But not before that.

Roger, that is not very helpful. Removing the trailing zero caused the problem in the first place. The goal is to make it work in every situation.
I would like to know if you can reproduce the original bug?
Can anybody reproduce it?
In fact I never could reproduce it. I believed it is a real issue because at least 2 people had it.
Your patch indeed solves the issue about 2 Lazarus instances. For me everything works after it.

As I told I want to "wash my hands" from this issue because I cannot even reproduce it.
Why I still have to analyse and ask questions? Can't you guys communicate and solve this?
I detach myself from this issue, maybe it helps ...

Roger Olsson

2017-02-17 20:33

reporter   ~0098261

@Juha I can't reproduce the original bug either. How many had this problem and was it really caused by Lazarus? I would like to wash my hands to, spent a number of hours finding and solving. Also I hope that this bug doesn't get into the next release of Lazarus (1.6.4) Because how are people then supposed to copy code from and old project to a new one? With some humour we could call this the "iron curtain bug". No big problem for us, but what about those who cant fix and recompile Lazarus.

@BBaz: have you commented out the two lines of code and recompiled? Does the pasting work for you?

BBaz

2017-02-18 07:09

reporter   ~0098271

Can you see the red dot symptom (on ideone.com) with a line copied from Lazarus 1.6.2 vanilla ?

BBaz

2017-02-18 07:14

reporter   ~0098272

For better communication, I'm on Lazarus IRC channel today

Roger Olsson

2017-02-18 11:41

reporter   ~0098277

Be aware that gtk2callback.diff only works for Lazarus trunk, not 1.6.2 to 1.6.4.

Zeljan Rikalo

2017-02-18 11:47

developer  

gtk2_selection_copy_paste.diff (1,409 bytes)
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 54155)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -3564,16 +3564,29 @@
 procedure SetData(SelectionData: PGtkSelectionData; MemStream: TMemoryStream);
 var
   Buffer: Pointer;
-  BufLength: integer;
+  BufLength: gint;
+  ALastByte: Byte;
 begin
-  BufLength:=integer(MemStream.Size);
-  GetMem(Buffer,BufLength);
+  BufLength := gint(MemStream.Size);
+  GetMem(Buffer, BufLength);
   Assert(Assigned(Buffer) and (BufLength>0), 'SetData: GTK2 clipboard Buffer=Nil or empty.');
-  MemStream.Read(Buffer^,BufLength);
   // Issue #21453. gtk_selection_data_set adds the required null. Remove it here.
-  if PChar(Buffer+BufLength-1)^ = #0 then
+  if SelectionData^.length < 0 then
+  begin
+    SelectionData^.format := 8;
+    SelectionData^.length := 0;
+  end;
+  MemStream.Read(Buffer^, BufLength - 1);
+  ALastByte := MemStream.ReadByte;
+  if ALastByte <> 0 then
+  begin
+    FreeMem(Buffer);
+    GetMem(Buffer, BufLength);
+    MemStream.Position := 0;
+    MemStream.Read(Buffer^, BufLength);
+  end else
     dec(BufLength);
-  gtk_selection_data_set(SelectionData,SelectionData^.Target,8,Buffer,BufLength);
+  gtk_selection_data_set(SelectionData,SelectionData^.Target, 8, Buffer, BufLength);
   FreeMem(Buffer);
 end;
 

Zeljan Rikalo

2017-02-18 11:48

developer   ~0098278

Please test with attached patch. Now it works as expected. Null terminator is off, and everything works as expected between two instances of lazarus and also between other apps and lazarus.

Juha Manninen

2017-02-18 12:07

developer   ~0098279

Last edited: 2017-02-18 12:16

View 2 revisions

Zeljko, interesting!
Could you earlier reproduce the original bug reported by cobines and BBaz? Now we only need a confirmation from them that the patch solves it.

Roger Olsson

2017-02-18 13:07

reporter   ~0098282

BBaz and I did some test today. The problem seems to be partly or mostly OS related. There is likely something specific in how Lazarus handles copy/paste that needs to be resolved. We could not find what it is. Until it is found, out we agreed the best is to revert the code so copy/paste between instances work again.

Roger Olsson

2017-02-18 13:11

reporter   ~0098284

I didnt notice Zeljans comment. Will try his patch now.

BBaz

2017-02-18 13:14

reporter   ~0098285

Last edited: 2017-02-18 13:14

View 2 revisions

the 4th patch works for me (http://bugs.freepascal.org/file_download.php?file_id=25995&type=bug)

No more 0 when pasting to other app but paste between two lazarus instances is broken.

Roger Olsson

2017-02-18 13:23

reporter   ~0098287

Last edited: 2017-02-18 13:24

View 2 revisions

Here pasting is not possible either.

Juha Manninen

2017-02-18 13:42

developer   ~0098288

Ok, I commented before I tested Zeljko's patch. Now I tested and it does not work. It makes no difference.
Zeljko, are you sure it fixes the problem for you?

Zeljan Rikalo

2017-02-18 14:11

developer   ~0098289

Yes, it works fine here (even without my patch, which is created just to check if pointer arithmetic fails for some reason, and to set default values of uninitialized gtkselection). Fedora 24 64bit, fpc-3.0.0, lazarus trunk. I'm afraid that problems arises from glib2 version since copy/paste between 2 lazarus instances and/or other apps qt/gtk2 works ok.

Zeljan Rikalo

2017-02-18 14:12

developer   ~0098290

Question: Does copy/paste works between 2 lazarus instances if you copy something from TEdit and paste to TEdit in another lazarus instance eg. from project options ? Do not look into SynEdit (SE) atm, so we can faster get into the source of the problem.

Zeljan Rikalo

2017-02-18 14:40

developer   ~0098291

Taking TSynEdit as example but this probably applies to all TCustomControls (non native gtk widgets for text)
ClipboardGetOwnerShip() is not triggered when you click into another TSynEdit inside same form, but IT IS triggered if you clicl into TEdit.
So, something is definitelly wrong with clipboard handling in lclgtk2.
ClipboardGetOwnerShip() changes clipboardwidget, so that's why it works when:
a) Select text with mouse in TSynEdit b) Press middle button in TEdit,
but it does not when b) = Press middle button in TSynEdit.
NOTE: second case TSynEdit->TSynEdit WORKS CORRECT IF you run first case:
a)Select text in TSynEdit b)Press middle mouse button in TEdit c) Press middle mouse button in TSynEdit.

Zeljan Rikalo

2017-02-18 14:41

developer   ~0098292

So it is possible that ClipboardGetOwnerShip does not trigger when switching between two LCL apps but it should (again I'm talking about TCustomControl-mean our implementation of clipboard) - I'm pretty sure that cp between eg TEdit in different apps works fine.

Juha Manninen

2017-02-18 15:25

developer   ~0098293

> I'm pretty sure that cp between eg TEdit in different apps works fine.

Yes it does. But why copying between TSynEdits also works for you? You found an issue with ClipboardGetOwnerShip() call but still it works for you?

Zeljan Rikalo

2017-02-18 20:44

developer   ~0098299

Not for the first time. Mean start 1st app, start 2nd app select some text in 1st synedit by using mouse. Now middle click into 2nd app synedit - DOES NOT WORK.
BUT if you select text in synedit and middle click inside native gtk handle eg. TEdit then it works, and later middle click into synedit works.

Juha Manninen

2017-02-22 00:27

developer   ~0098363

Somebody please debug the code based on Zeljko's findings.
The copied text is now correct. The problem is in pasting. The fix must go to a right place.

Martin Friebe

2017-03-04 17:45

manager   ~0098636

Please read http://forum.lazarus-ide.org/index.php/topic,35880.msg240062.html#msg240062

That may explain.
If you first paste into TEdit, CF_Text is already set. But if you paste to SynEdit first, then it is not set.

Juha Manninen

2017-06-03 11:09

developer   ~0100820

Last edited: 2017-06-03 11:16

View 3 revisions

BBaz and others, please build Lazarus with GTK_REMOVE_CLIPBOARD_NULL.
The trailing NULL is now removed only when it is defined.

Removing the trailing NULL here was apparently a wrong way as it created a regression bug, preventing copy/paste between Lazarus instances.
That affected all GTK2 users but now it works again.

The trailing NULL bug appeared only in some machines, depending on window manager I guess. For example I have not experienced it.

I still hope somebody studies the issue and fixes it properly.

Martin Friebe

2018-07-15 12:55

manager   ~0109488

Should be fixed. Please test.

Test WITHOUT GTK_REMOVE_CLIPBOARD_NULL

To be tested:
- Copy one word from synedit to synedit
- Copy one word from synedit to TEdit or TMemo
- Copy one word from synedit to libre office (or other external app)


All of the above with multiline / full line
All of the above in reverse (copy TO synedit)

Copy text in "column mode selection"

Fold a begin/end (or any other) block in synedit. Copy a selection containing the entire folded block.
Paste it in SynEdit => the pasted text should have the block folded (assuming you did not disable this in options)

=====================
The old patch had a problem:

It removed the #0 from any clipboard data. Including Text, images, custom.
But the LCL only added the extra to text (and only if added via "AsText")

So any data added any other way, if it had a #0 (that was part of the data) would be mangled.

Issue History

Date Modified Username Field Change
2012-03-10 14:53 cobines New Issue
2012-03-10 14:53 cobines File Added: clipzero.diff
2012-03-10 14:53 cobines Widgetset => GTK 2
2012-03-10 15:48 Zeljan Rikalo Note Added: 0057464
2012-03-10 17:16 cobines Note Added: 0057466
2012-03-10 18:03 Zeljan Rikalo Note Added: 0057468
2012-03-13 04:15 cobines Note Added: 0057545
2012-03-13 08:00 Zeljan Rikalo LazTarget => 1.2
2012-03-13 08:00 Zeljan Rikalo Status new => acknowledged
2012-03-13 08:00 Zeljan Rikalo Target Version => 1.2.0
2013-04-29 11:46 Juha Manninen Note Added: 0067258
2014-01-20 13:36 Martin Friebe Target Version 1.2.0 => 1.4
2014-01-20 13:37 Martin Friebe LazTarget 1.2 => 1.4
2014-09-10 00:09 Juha Manninen LazTarget 1.4 => -
2014-09-10 00:09 Juha Manninen Target Version 1.4 =>
2016-04-27 19:05 Juha Manninen Relationship added related to 0030071
2016-04-28 23:25 jamie philbrook Note Added: 0092282
2016-04-28 23:49 jamie philbrook Note Edited: 0092282 View Revisions
2016-06-15 09:02 BBaz Note Added: 0093204
2016-06-15 11:23 Thaddy de Koning Note Added: 0093207
2016-06-15 11:24 Thaddy de Koning Note Edited: 0093207 View Revisions
2016-06-15 14:26 BBaz Note Added: 0093219
2016-06-15 14:36 BBaz Note Edited: 0093219 View Revisions
2016-07-08 07:59 BBaz Note Added: 0093618
2016-07-08 08:00 BBaz Note Edited: 0093618 View Revisions
2016-08-23 15:33 BBaz Note Added: 0094285
2016-08-23 15:43 BBaz Note Edited: 0094285 View Revisions
2016-09-21 14:52 BBaz Note Added: 0094752
2016-09-23 08:11 Juha Manninen Note Added: 0094786
2016-09-23 08:11 Juha Manninen Note Edited: 0094786 View Revisions
2016-09-23 08:12 Juha Manninen Note Edited: 0094786 View Revisions
2016-11-17 00:36 BBaz File Added: issue21453.patch
2016-11-17 00:42 BBaz Note Added: 0095942
2016-11-17 11:06 Juha Manninen Assigned To => Juha Manninen
2016-11-17 11:06 Juha Manninen Status acknowledged => assigned
2016-11-17 14:43 Juha Manninen Note Added: 0095952
2016-11-17 14:43 Juha Manninen Status assigned => feedback
2016-11-17 14:45 Juha Manninen Relationship replaced has duplicate 0030071
2016-11-18 01:14 BBaz Note Added: 0095976
2016-11-18 01:20 BBaz Note Added: 0095977
2016-11-18 01:33 BBaz Note Added: 0095978
2016-11-18 17:04 Juha Manninen Fixed in Revision => r53376, r53380
2016-11-18 17:04 Juha Manninen Note Added: 0096008
2016-11-18 17:04 Juha Manninen Status feedback => resolved
2016-11-18 17:04 Juha Manninen Resolution open => fixed
2017-02-16 18:34 Juha Manninen Note Added: 0098230
2017-02-16 18:34 Juha Manninen Status resolved => assigned
2017-02-16 18:34 Juha Manninen Resolution fixed => reopened
2017-02-17 13:43 Roger Olsson File Added: gtk2callback.diff
2017-02-17 13:47 Roger Olsson Note Added: 0098249
2017-02-17 13:55 Roger Olsson Note Edited: 0098249 View Revisions
2017-02-17 13:57 Roger Olsson Note Edited: 0098249 View Revisions
2017-02-17 14:10 Cyrax Note Added: 0098250
2017-02-17 15:57 Roger Olsson Note Added: 0098253
2017-02-17 17:27 Juha Manninen Note Added: 0098258
2017-02-17 17:28 Juha Manninen Assigned To Juha Manninen =>
2017-02-17 17:28 Juha Manninen Status assigned => new
2017-02-17 17:28 Juha Manninen Note Edited: 0098230 View Revisions
2017-02-17 20:33 Roger Olsson Note Added: 0098261
2017-02-17 21:14 Juha Manninen LazTarget - => 1.6.4
2017-02-17 21:14 Juha Manninen Target Version => 1.6.4
2017-02-18 07:09 BBaz Note Added: 0098271
2017-02-18 07:14 BBaz Note Added: 0098272
2017-02-18 11:41 Roger Olsson Note Added: 0098277
2017-02-18 11:47 Zeljan Rikalo File Added: gtk2_selection_copy_paste.diff
2017-02-18 11:48 Zeljan Rikalo Note Added: 0098278
2017-02-18 12:07 Juha Manninen Note Added: 0098279
2017-02-18 12:16 Juha Manninen Note Edited: 0098279 View Revisions
2017-02-18 13:07 Roger Olsson Note Added: 0098282
2017-02-18 13:11 Roger Olsson Note Added: 0098284
2017-02-18 13:14 BBaz Note Added: 0098285
2017-02-18 13:14 BBaz Note Edited: 0098285 View Revisions
2017-02-18 13:23 Roger Olsson Note Added: 0098287
2017-02-18 13:24 Roger Olsson Note Edited: 0098287 View Revisions
2017-02-18 13:42 Juha Manninen Note Added: 0098288
2017-02-18 14:11 Zeljan Rikalo Note Added: 0098289
2017-02-18 14:12 Zeljan Rikalo Note Added: 0098290
2017-02-18 14:40 Zeljan Rikalo Note Added: 0098291
2017-02-18 14:41 Zeljan Rikalo Note Added: 0098292
2017-02-18 15:25 Juha Manninen Note Added: 0098293
2017-02-18 20:44 Zeljan Rikalo Note Added: 0098299
2017-02-22 00:27 Juha Manninen Note Added: 0098363
2017-03-04 17:45 Martin Friebe Note Added: 0098636
2017-03-15 19:58 Juha Manninen Relationship added has duplicate 0031547
2017-04-30 10:50 Juha Manninen Relationship replaced related to 0031547
2017-06-03 11:09 Juha Manninen Fixed in Revision r53376, r53380 => r53376, r53380, r55180
2017-06-03 11:09 Juha Manninen Note Added: 0100820
2017-06-03 11:15 Juha Manninen Note Edited: 0100820 View Revisions
2017-06-03 11:16 Juha Manninen Note Edited: 0100820 View Revisions
2018-07-15 12:55 Martin Friebe Fixed in Revision r53376, r53380, r55180 => 58530 (r53376, r53380, r55180)
2018-07-15 12:55 Martin Friebe LazTarget 1.6.4 => 1.10
2018-07-15 12:55 Martin Friebe Note Added: 0109488
2018-07-15 12:55 Martin Friebe Status new => resolved
2018-07-15 12:55 Martin Friebe Fixed in Version => 1.10
2018-07-15 12:55 Martin Friebe Resolution reopened => fixed
2018-07-15 12:55 Martin Friebe Assigned To => Martin Friebe
2018-07-15 12:55 Martin Friebe Target Version 1.6.4 => 1.10
2018-08-12 00:04 Martin Friebe Relationship added related to 0034116
2018-08-12 12:03 Juha Manninen Relationship replaced has duplicate 0034116
2019-08-20 17:04 Dmitry Boyarintsev Relationship added related to 0035984