Recent

Author Topic: Unable to paste into Lazarus editor from another application  (Read 8892 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: Unable to paste into Lazarus editor from another application
« Reply #15 on: May 04, 2019, 04:37:28 pm »
I can confirm the issue happens with trunk too.

It seems to be something in the lcl interface code. At least my guess after some debugging.

https://bugs.freepascal.org/view.php?id=35482
« Last Edit: May 04, 2019, 04:46:59 pm by Martin_fr »

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: Unable to paste into Lazarus editor from another application
« Reply #16 on: May 04, 2019, 07:19:35 pm »
I downloaded and compiled the latest trunk of Lazarus (61136).
(No docked IDE here as far as know. I use Lazarus as it is.)
I can confirm that this problem is present in the latest trunk too.

Please, test with Gedit as follows:
  • Open Gedit. Enter some text. Select some text in Gedit. Copy to Clipboard.
  • Switch to Lazarus editor or a Lazarus program that uses ClipBoard.AsText to import some text from Clipboard.
  • The first try will return True for Clipboard.HasFormat(CF_TEXT), but a 0 length string for ClipBoard.AsText.
  • The second try will return False for Clipboard.HasFormat(CF_TEXT).

« Last Edit: May 04, 2019, 07:44:08 pm by fedkad »
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Unable to paste into Lazarus editor from another application
« Reply #17 on: May 04, 2019, 07:22:51 pm »
Works fine for me with trunk of today on Mint 18.2-64.

Bart

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: Unable to paste into Lazarus editor from another application
« Reply #18 on: May 04, 2019, 07:26:57 pm »
Do you have gnome-text-editor (gedit - Version 3.32.0) installed in your system?
Please, test with it as detailed in my previous post.
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9874
  • Debugger - SynEdit - and more
    • wiki
Re: Unable to paste into Lazarus editor from another application
« Reply #19 on: May 04, 2019, 07:40:37 pm »
Copy from gedit to lazarus also does not work.

I tested what happens when I copy from Lazarus to Lazarus vs gedit to lazarus.

xclip reports the same in both cases. It gets Utf8 from the clipboard (see related issue)

In both cases (as in the issue)
  IsFormatSupported =>   RequestSelectionData =>     gtk_selection_convert in
returns false.

So it falls back to the only format, that it does not test with IsFormatSupported: COMPOUND_TEXT

The difference is probably that lazarus does deliver this (on request?).
gedit obviously does not.

simonm

  • Newbie
  • Posts: 3
Re: Unable to paste into Lazarus editor from another application
« Reply #20 on: November 04, 2019, 09:48:47 am »
Without meaning to revive an old thread, I did run into the same problem after going to Fedora 31 where I couldn't paste from any other application into the Lazarus editor.

I recalled that Fedora runs Wayland by default and then logged out and switched to Xorg. Problem solved for me!

I can now paste from other applications into the editor. Hope this helps someone.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Unable to paste into Lazarus editor from another application
« Reply #21 on: November 04, 2019, 01:07:37 pm »
Pasting from geany (on Raspbian Buster) works! which  uses wayland....

This has some interesting info https://stackoverflow.com/questions/39616066/wayland-clipboard-api  and https://wiki.gnome.org/Initiatives/Wayland/PrimarySelection
« Last Edit: November 04, 2019, 01:12:52 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: Unable to paste into Lazarus editor from another application
« Reply #22 on: November 04, 2019, 08:10:06 pm »
Without meaning to revive an old thread, I did run into the same problem after going to Fedora 31 where I couldn't paste from any other application into the Lazarus editor.
I recalled that Fedora runs Wayland by default and then logged out and switched to Xorg. Problem solved for me!
I can now paste from other applications into the editor. Hope this helps someone.

It seems that the same thing happened here. Lately, I upgraded to Ubuntu 19.10 and it uses GNOME on Xorg by default. The problem does not occur here.
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Unable to paste into Lazarus editor from another application
« Reply #23 on: September 09, 2023, 08:57:46 am »
Tested using fpc 3.2.2 and Lazarus 2.2.6 (stable / stable) on Xubuntu 20.04 and MXLinux (debian 10 / buster).

I am having this same issue with Lazarus GTK2 editors (synedit, cudatext, ATsynedit).  Clipboard.AsText sometimes does not return the UTF8_STRING clipboard contents.  Other apps like gedit, geany, xclip, and even Lazarus TMemo (gtk2) all work correctly.

I turned on clipboard debugging ({$DEFINE DEBUG_CLIPBOARD}) and captured two logging sessions.

WORKING EXAMPLE DEBUG LOG:
Using gedit, I copied the text "bla bla bla" to the clipboard and then in a simple Lazarus app call Clipboard.AsText:
Code: [Select]
[TGtk2WidgetSet.ClipboardGetData] A ClipboardWidget=000000000156E400 FormatID=text/plain Now=45177.9750512616
[RequestSelectionData] FormatID=131
[RequestSelectionData] TimeID=24436340 Type=CLIPBOARD FormatID=TARGETS
[ClipboardSelectionReceivedHandler] A TimeID=24436340 RequestIndex=0 selection=69=CLIPBOARD target=131=TARGETS theType=4=ATOM format=32 len=96
[ClipboardSelectionReceivedHandler] B DataLen=96
[ClipboardSelectionReceivedHandler] C FirstCharacter=134
IsFormatSupported A 69 00000045 SelData.Target=131 AllID=131 SelData.TheType=4 ATOM=4 Name="ATOM" SelData.Length=96 SelData.Format=32
 23 ""
 22 ""
 21 ""
 20 ""
 19 ""
 18 "GDK_SELECTION"
 17 ""
 16 ""
 15 ""
 14 ""
 13 ""
 12 ""
 11 "text/plain"
 10 "text/plain;charset=utf-8"
 9 "STRING"
 8 "TEXT"
 7 "COMPOUND_TEXT"
 6 "UTF8_STRING"
 5 "application/x-gtk-text-buffer-rich-text"
 4 "GTK_TEXT_BUFFER_CONTENTS"
 3 "SAVE_TARGETS"
 2 "MULTIPLE"
 1 "TARGETS"
 0 "TIMESTAMP"
[TGtk2WidgetSet.ClipboardGetData] B  Format=UTF8_STRING FormatAtom=71 Now=45177.9751306134
[RequestSelectionData] FormatID=71
[RequestSelectionData] TimeID=24436340 Type=CLIPBOARD FormatID=UTF8_STRING
[ClipboardSelectionReceivedHandler] A TimeID=24436340 RequestIndex=0 selection=69=CLIPBOARD target=71=UTF8_STRING theType=71=UTF8_STRING format=8 len=11
[ClipboardSelectionReceivedHandler] B DataLen=11
[ClipboardSelectionReceivedHandler] C FirstCharacter=98
[TGtk2WidgetSet.ClipboardGetData] C  Length=11 Now=45177.9751616435  SelData.Selection=69 SelData.Length=11
[TGtk2WidgetSet.ClipboardGetData] END  Now=45177.9751690278

NOT WORKING EXAMPLE DEBUG LOG:
Using Remote Viewer, I copied the text "This is a test" from a remote Windows notepad to the clipboard and then in a simple Lazarus app call Clipboard.AsText:
Code: [Select]
[TGtk2WidgetSet.ClipboardGetData] A ClipboardWidget=0000000002283400 FormatID=text/plain Now=45177.9765332523
[RequestSelectionData] FormatID=131
[RequestSelectionData] TimeID=24564910 Type=CLIPBOARD FormatID=TARGETS
[ClipboardSelectionReceivedHandler] A TimeID=24564910 RequestIndex=0 selection=69=CLIPBOARD target=131=TARGETS theType=4=ATOM format=32 len=64
[ClipboardSelectionReceivedHandler] B DataLen=64
[ClipboardSelectionReceivedHandler] C FirstCharacter=134
IsFormatSupported A 69 00000045 SelData.Target=131 AllID=131 SelData.TheType=4 ATOM=4 Name="ATOM" SelData.Length=64 SelData.Format=32
 15 ""
 14 ""
 13 ""
 12 ""
 11 ""
 10 ""
 9 ""
 8 ""
 7 "text/plain"
 6 "TEXT"
 5 "STRING"
 4 "text/plain;charset=utf-8"
 3 "UTF8_STRING"
 2 "MULTIPLE"
 1 "TARGETS"
 0 "TIMESTAMP"
[TGtk2WidgetSet.ClipboardGetData] B  Format=UTF8_STRING FormatAtom=71 Now=45177.9765464815
[RequestSelectionData] FormatID=71
[RequestSelectionData] TimeID=24564910 Type=CLIPBOARD FormatID=UTF8_STRING
[TGtk2WidgetSet.ClipboardGetData] C  Length=0 Now=45177.9765604167  SelData.Selection=0 SelData.Length=0
[TGtk2WidgetSet.ClipboardGetData] REQUESTED FORMAT NOT SUPPORTED  Length=0
[ClipboardSelectionReceivedHandler] A TimeID=24564910 RequestIndex=-1 selection=69=CLIPBOARD target=71=UTF8_STRING theType=71=UTF8_STRING format=8 len=14

In both examples, the listing of formats works (although the list is different), and both call:
Code: [Select]
[TGtk2WidgetSet.ClipboardGetData] B  Format=UTF8_STRING FormatAtom=71 Now=45177...
[RequestSelectionData] FormatID=71
[RequestSelectionData] TimeID=24436340 Type=CLIPBOARD FormatID=UTF8_STRING

Following that, in the NON working example, there seems to be a timing issue with the reception or matching of clipboard events. gtk_clipboard_wait_for_contents returns before ClipboardSelectionReceivedHandler processes the clipboard event and subsequently TGtk2WidgetSet.ClipboardGetData thinks there is no data.  When ClipboardSelectionReceivedHandler does finally process the event it gets ignored since it is too late.
« Last Edit: September 09, 2023, 09:32:18 am by WayneSherman »

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Unable to paste into Lazarus editor from another application
« Reply #24 on: September 09, 2023, 09:52:02 am »
I just tested again with fpc trunk and Lazarus trunk.  This issue is fixed in trunk for my tests.

It is also fixed in the latest cudatext.  :-)
« Last Edit: September 09, 2023, 10:04:38 am by WayneSherman »

 

TinyPortal © 2005-2018