Text not copied to clipboard correctly / Weird clipboard behavior

I have opened a Windows link file (.lnk) in Kate to copy command line parameters out of it (seemed easier than to research anew information that already lies on my disk). Unfortunately, the text isn’t copied to the clipboard. Kate, somehow, still “knows” it has been copied so I can paste it in the same or other documents in Kate itself, but nowhere else. I could observe the same behaviour in KWrite.

Upon further testing, it seems I can copy some text, but I’m not sure how that is determined. Text from the first full path seems fine (even tested other .lnk files), second full path not. I’d understand if the mangled characters in between (due to not being supposed to be characters at all) couldn’t be copied, but it even happens with actual text.

When trying to copy everything (ctrl+a, ctrl+c), only the first character (“L”) is copied to the clipboard, everything else is cut off. Hitting ctrl+v in another document of the same program (i.e. Kate), everything is pasted, not only the first character.
At other times, a failed copy doesn’t modify the clipboard at all.

Considering copying seems to work fine within an application (like Kate and KWrite), I don’t see a reason it shouldn’t work into the system clipboard and other programs.
If I open a terminal and type “cat file.lnk” then I can copy all the text, including paths and parameters, without issue. I would prefer using a text editor, though - copying from terminal is still a bit unfamiliar.

Is it a bug? Is it a feature? How can I copy text from arbitrary files into other programs? This won’t be the first time I might need to copy text from a seemingly binary file.

I can’t help you but I can try to give an explanation:

Copy and paste and drag and drop are complicated functions

When transferring something to the clipboard, the program needs to specify what kind of data to transfer

  • Image data
  • A link to a file
  • ASCII text
  • UTF8 text

Kate may say “This is a link to a file” (but the file does not exist on your system)
Then the clipboard has problems receiving the data.
If Kate says, “That’s plain text”, there’s no problem.

Is Klipper enabled ?

If the binary data you copy has any NULL characters (0) in it then it will be truncated at those characters. It’s how NULL-terminated strings work.

If you need to copy binary data use something like Bless hex editor.

Sorry for the late reply, and thanks for your replies!
I fear it might be related to NULL characters.
“But it works on Windows” :stuck_out_tongue:
I think using cat might be easier than getting another program, but I’ll experiment.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.