Recent

Author Topic: Lazarus Copy and Paste  (Read 17512 times)

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: Lazarus Copy and Paste
« Reply #15 on: February 18, 2017, 11:32:58 am »
@BBasile Using laz release 1.6.2, I pasted to ide.one, and no red dot. As you suspected, I never saw the red dot whatever lazarus revision used.

Can we rule out that you dont have a third party clipboard, or any other software installed in your linux that changes the pasted content? Have you tried pasting from other machines with a fresh install of linux? It is Debian?

I think its best to discuss here, maybe others also read and can contribute to a fix.

Try copy & paste using Lazarus 1.6.2 Vanilla (as distributed or after checkout the tag in the repo) and tell me if you see the red dot on ideone.

Currently I suspect that for a reason or another you've never been affected by the bug. If it's the case then we have a serious problem. The Gtk documentation states clearly that it adds automatically the null terminator.
I you want to discuss about the bug I'm on IRC today (DotBatch), even if, tbh, I really don't want to spent my day to recompile Laz.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Lazarus Copy and Paste
« Reply #16 on: February 18, 2017, 11:40:02 am »
Important:
Can somebody please explain why copy / paste between 2 Lazarus instances does not work now?
As BBasile says the NULL terminator is copied by GTK2. Copy / paste to any other application works. The data clearly is correct!
Another Lazarus instance is the only app that does not accept the data. Why?
There may be a hack of some sort for pasting data. Then another extra NULL hack was added to work around that hack. Who knows? ...

I am asking for a group effort to solve this. I am not a GTK2 expert and I have many other things to do.

Just tested it a bit, and my conclusion is that cut #0 terminator is ok. Problem is with synedit (lcl clipboard formats, not gkt2 ones).
Another instance accepts paste if you paste into native gtk2 control, eg GtkEdit or into Qt app.
There's more problems than just Ctrl + C , Ctrl + V. Try mouse selection and middle click. Even in same app you cannot paste text into another synedit with middle mouse click. But, if you do middle click into GtkEdit (TEdit) , and then into second synedit everything works ok, until you select another text in synedit and try to paste it with middle click into another synedit. But note that middle click paste WORKS into another qt or gtk2 app, just not into another synedit in current or another app instance.
This is pretty complex problem and IMO it does not have anything with terminator, but with clipboard callbacks which are buggy.


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Lazarus Copy and Paste
« Reply #17 on: February 18, 2017, 01:47:19 pm »
This is pretty complex problem and IMO it does not have anything with terminator, but with clipboard callbacks which are buggy.
The bugs in clipboard callbacks should be isolated and fixed. However I don't know of any other problems with clipboard. This is the only one.
zeljko, the patch you uploaded to Mantis does not work.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Lazarus Copy and Paste
« Reply #18 on: February 18, 2017, 02:56:02 pm »
I've explained http://bugs.freepascal.org/view.php?id=21453 what's the root of problem and howto
easy reproduce it.
LCL implementation of clipboard for TCustomControl (tested with TSynEdit only) is not ok at some point.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Lazarus Copy and Paste
« Reply #19 on: February 22, 2017, 12:28:45 am »
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.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: Lazarus Copy and Paste
« Reply #20 on: February 22, 2017, 02:45:03 am »
Don't know where to start, but while browsing the files in /interfaces/gtk2/ I found a file called gtk2callback.inc. For no good reason I searched for "clip" and found the 3 functions below.

There is a typo inside function gtkPasteFromClip: 'lcl-delay-cm_textchaged'. Not sure if that is relevant. But could the problem be within the routines below? Perhaps function gtkPasteFromClip, since it was pasting that didn't work?

Code: Pascal  [Select][+][-]
  1. function gtkPasteFromClip( widget: PGtkWidget; data: gPointer) : GBoolean; cdecl;
  2. var
  3.   Mess : TLMessage;
  4.   Info: PWidgetInfo;
  5. begin
  6.   EventTrace('Paste from clip', data);
  7.  
  8.   // we must update cursor pos with delay otherwise selStart is wrong.issue #7243
  9.   if (Widget <> nil) and (GTK_IS_ENTRY(Widget)) then
  10.   begin
  11.     Info := GetWidgetInfo(Widget, False);
  12.     Include(Info^.Flags, wwiInvalidEvent);
  13.     // happy end is inside gtkchanged_editbox() above.
  14.     g_object_set_data(PGObject(Widget),'lcl-delay-cm_textchaged', data);
  15.   end;
  16.   Mess.msg := LM_PASTE;
  17.   Result:= DeliverMessage(Data, Mess) = 0;
  18. end;
  19.  
  20. function gtkCutToClip( widget: PGtkWidget; data: gPointer) : GBoolean; cdecl;
  21. var
  22.   Mess : TLMessage;
  23.   Info: PWidgetInfo;
  24. begin
  25.   EventTrace('Cut to clip', data);
  26.   if (Widget <> nil) and (GTK_IS_ENTRY(Widget)) then
  27.   begin
  28.     Info := GetWidgetInfo(Widget, False);
  29.     include(Info^.Flags, wwiInvalidEvent);
  30.   end;
  31.   Mess.msg := LM_CUT;
  32.   Result:= DeliverMessage(Data, Mess) = 0;
  33. end;
  34.  
  35. function gtkCopyToClip( {%H-}widget: PGtkWidget; data: gPointer) : GBoolean; cdecl;
  36. var
  37.   Mess : TLMessage;
  38. begin
  39.   EventTrace('Copy to Clip', data);
  40.   Mess.msg := LM_COPY;
  41.   Result:= DeliverMessage(Data, Mess) = 0;
  42. end;
  43.  
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Lazarus Copy and Paste
« Reply #21 on: February 22, 2017, 01:50:31 pm »
Don't know where to start, ...
Start from TGtk2WidgetSet.ClipboardGetOwnerShip() as Zeljko explained.

Quote
There is a typo inside function gtkPasteFromClip: 'lcl-delay-cm_textchaged'. Not sure if that is relevant.
No it is not relevant.
The same cmd string is used everywhere and the right spelling is not used at all, as can easily be seen with a "Find in Files" search.
Anyway, I fixed the spelling in r54251.

Quote
But could the problem be within the routines below? Perhaps function gtkPasteFromClip, since it was pasting that didn't work?
If somebody knew the answer, the problem would be solved already.
Why don't you debug the code?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9877
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus Copy and Paste
« Reply #22 on: March 04, 2017, 04:44:25 am »
I havent looked at the issue, but a few observations.

1) Does it make a difference if text is copied from
 a) some TEdit concrol
 b) SourceEdit/SynEdit?
2) Does it make a difference into what control is pasted?

-------------
Code: Pascal  [Select][+][-]
  1. //  if PChar(Buffer+BufLength-1)^ = #0 then
  2. //    dec(BufLength);
That code is in SetData.

Does that apply to text data only, or to all types of data that go into the clipboard?

If that applies to all kind of data, and if there was none text data going into the clipboard, then the extra #0 might be needed.

And on that note: SynEdit is adding none text data to the clipboard.
Code: Pascal  [Select][+][-]
  1.    ClipboardRegisterFormat(SYNEDIT_CLIPBOARD_FORMAT_TAGGED);

One of the binary extra data, has a comment
Code: Pascal  [Select][+][-]
  1. procedure TSynClipboardStream.SetInternalText(const AValue: String);
  2. begin
  3.   FIsPlainText := False;
  4.   // Text, if we don't need CF_TEXT // Must include a zero byte
  5.  

SynEdit stores, if it was a column mode selection, or if there were folded parts in the text.

the trailing #0 is only for the bin data, SynEdit does afaik not add it to CF_TEXT

« Last Edit: March 04, 2017, 04:56:59 am by Martin_fr »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Lazarus Copy and Paste
« Reply #23 on: March 04, 2017, 10:13:18 am »
1) Does it make a difference if text is copied from
 a) some TEdit concrol
 b) SourceEdit/SynEdit?
2) Does it make a difference into what control is pasted?
Yes it makes a difference. See Zeljko's research here which I also confirmed:
 http://bugs.freepascal.org/view.php?id=21453#c98291

Quote
Does that apply to text data only, or to all types of data that go into the clipboard?
If that applies to all kind of data, and if there was none text data going into the clipboard, then the extra #0 might be needed.
I don't know about data types but an extra #0 should not be needed. The pasted data is clearly OK now. Every other application accepts it and so does TEdit. Only pasting to TSynEdit and maybe to other TCustomControls fails. The problem is in paste, not in copy.

I am not planning to do more research on this issue. I have many other open source "itches to scratch", this is not one of them.
Kapibara started to study the code but stopped although he apparently had an "itch" with this bug.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Lazarus Copy and Paste
« Reply #24 on: March 04, 2017, 10:25:29 am »
I move a valid question by BBasile here from 1.6.4 release thread:
Copying between two Coedit instances works so it has to be something really specific to Lazarus.
In a first place, why didn't you use the simple clipboard operations (.AsText) ?


Martin knows the internals of TSynEdit in Lazarus.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9877
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus Copy and Paste
« Reply #25 on: March 04, 2017, 05:40:10 pm »
I move a valid question by BBasile here from 1.6.4 release thread:
Copying between two Coedit instances works so it has to be something really specific to Lazarus.
In a first place, why didn't you use the simple clipboard operations (.AsText) ?


As I said SynEdit puts additional info on the clipboard. (column mode (if active), folded lines / so pasting into another SynEdit restores folds, if option is set)

For that SynEdit registers a special clipboard format, and puts binary info in there (like an image editor can put an image (binary) on the clipboard).

Normally this is done in ADDITION to CF_TEXT. So other controlls ignore the unknown data.
Normally the SynEdit blob does NOT contain a copy of the text, except for the special case below.

But if you copy SynEdit to SynEdit (Afaik at least mouse middle click) then it works different.

The source SynEdit does AquireClipboard, but does not put anything on it.
The target SynEdit will (on paste) ask, and it will ask by sending which formats it does accept.
So the source SynEdit only puts its special format on the clipboard. If that is stripped of #0 it may become invalid. And the target synedit will have nothing to go.

So if #0 get  stripped of not text date (images, audio, synedits-data), when those go on the clipboard, then they may become invalid.

comingnine

  • New Member
  • *
  • Posts: 25
Re: Lazarus Copy and Paste
« Reply #26 on: November 18, 2017, 12:54:54 pm »
The same bug is still in FPC 3.1.1.54189M & Lazarus 1.7 x86_64-linux-gtk2.

 

TinyPortal © 2005-2018