Forum > Editor
Unable to paste into Lazarus editor from another application
fedkad:
* Copy and paste within Lazarus editor works.
* Copy from Lazarus editor and paste into another application (like gedit) works.
* Copy from another application (like Firefox, gedit, etc.) and paste into Lazarus editor most of the time does not work.
I haven't isolated the rare case that it works. It looks pretty random. But, I can say that 90 percent it does not work.
My environment:
Lazarus 2.0.2 x86_64-linux-gtk2
Ubuntu Linux 19.04
Desktop: Gnome
lucamar:
Strange. I use various various versions of (K|L)Ubuntu and it has always worked Indeed, I use an external editor frequently to store or edit pieces of code in some specific ways and copy/paste from/to the Lazarus editor without problems.
Martin_fr:
Can you test with a new project?
- Add a memo and a button to a form.
- In the button OnClick do
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Memo1.Text := ClipBoard.AsText
You need
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ClipBrd;
Copy something, from either of those Apps, and press the button.
Try to copy using the menu (or contextmenu) labeled "Copy".
Note GTK has more than one ClipBoard. Selected text can often be pasted with the middle mouse. This uses a different ClipBoard
For this try
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PrimarySelection.AsText
And for good measure see what SecondarySelection does (if anything)
fedkad:
Hello Martin_fr.
I did what you suggested. As you say: ClipBoard.AsText pastes data which was copied to the clipboard before. PrimarySelection.AsText "pastes" data that is selected in another application. SecondarySelection.AsText does nothing (empty string). However, these have nothing to do with my problem. And actually when the problem occurs with the Lazarus editor, the same happens with the program: ClipBoard.AsText and PrimarySelection.AsText paste empty string; I verified this by using: Label1.Caption := IntToStr(Length(ClipBoard.AsText)).
I think Lazarus and the simple test program use the same code (libraries etc.), so they behave the same. Please note that, when this problem occurs (that is, when I cannot paste anything to Lazarus editor or in the test program), I can paste the data to another application, like LO Writer, Atom editor, Firefox, etc.
BTW; when this problem occurs, the context menu's Paste command or Ctrl+V on the test program's Memos works. But, the context menu's Paste command or Ctrl+V on Lazarus editor does not work.
Martin_fr:
Memo context menu paste, is handled by gtk/qt. Because Memo is a native control.
Clipboard.AsText is the LCL access to the clipboard.
SynEdit (the source editor) is not a native control. It uses Clipboard.AsText (with some additions).
After your test, the problem is in Clipboard.AsText and not in the "some additions" part.
Clipboard can contain text and other formats. AsText obviously will not return an image from the clipboard.
It is possible that some of the apps you use, store their text to the clipboard with a format the lcl does not understand.
You can report a bug, but without further info, I don't know if anyone will be able to do much about it.
I am not particularly familiar with the clipboard code. (Not tested any of the below)
But you could have a look at
property FormatCount: Integer read GetFormatCount;
property Formats[Index: Integer]: TClipboardFormat read GetFormats;
When you copy the unknown text, iterate through the formats, and list them.
There is a function ClipboardFormatToMimeType that may map the format to a string...
Maybe that turns out something useful.
Navigation
[0] Message Index
[#] Next page