Recent

Author Topic: clipboard not working on first copy/paste  (Read 3451 times)

Basile-B

  • Sr. Member
  • ****
  • Posts: 457
    • GH...
clipboard not working on first copy/paste
« on: December 04, 2015, 01:56:44 am »
In a TSynEdit descendant, the first time I execute the action ecCopy followed by ecPaste, nothing is paste or what's paste comes from another software.

This only happens if the editor is created during main form construction (for example if the application reloads the last documents from the previous session), otherwise if I create a new document tab, no problem.

I guess that something is not activated because in this case, the application is not yet visible, but I can't figure out what.

After a quick debug session I can also say that in DoCopyToClipboard(), the source SText is valid. But when ecPaste is executed (so in PasteFromClipboard()), either nothing is paste or the text was copied from another application (just now for example, it has paste a word from this message while I copied from a synedit descendant instance). So, something clealy fails in DoCopyToClipboard.

Any idea ?

Basile-B

  • Sr. Member
  • ****
  • Posts: 457
    • GH...
Re: clipboard not working on first copy/paste
« Reply #1 on: December 04, 2015, 02:36:01 am »
This is clearly caused by the fact that the appli is not yet visible. If I move the code that reload the document in the DoShow override, then the clipboard is ok. However I'm still looking for a better solution...

There is probably something to add in the TSynEdit descendant SetVisible() method (which I already use to reload the position - fold - election cache), but what ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: clipboard not working on first copy/paste
« Reply #2 on: December 04, 2015, 02:42:11 am »
sounds to me more like an issue in the clipboard code, than synedit.

It is of course possible that synedit calls something in the clipboard that it should at that time not call....

1) Do you try to copy/paste before your app is visible (has a handle)?

2) Do you set/unset selection before your app is visible?
This causes calls to TCustomSynEdit.AquirePrimarySelection, maybe that causes an issue.

Basile-B

  • Sr. Member
  • ****
  • Posts: 457
    • GH...
Re: clipboard not working on first copy/paste
« Reply #3 on: December 04, 2015, 04:11:17 am »
1) no, the c/p is done by hand when a doc is visible. however several TSynEdit are created before the appli is visible, during the main form constructor.

2) no. It used to to but I've disabled the code that was doing this, result: still no c/p for a doc that's reloaded from previous session.

MHLZO

  • Newbie
  • Posts: 1
Re: clipboard not working on first copy/paste
« Reply #4 on: October 21, 2018, 10:50:35 am »
Okay, I know this is an old post, but I have encoutered this problem too. :(
I don't know why it doesn't work, on, windows it's Ok, on Linux Gnome 3 or Mate I have this problem.

A simple solution (I'am a beginner) is to Paste and Undo at the begin of the program :

Code: Pascal  [Select]
  1. procedure SynEditInit( Option : String);
  2.  
  3. begin
  4.  
  5.   if (Option = 'FormCreate') then
  6.     Form1.SynEdit1.PasteFromClipboard;
  7.     Form1.SynEdit1.Undo;
  8.   end;
  9.  
  10.  

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: clipboard not working on first copy/paste
« Reply #5 on: October 21, 2018, 11:13:55 am »
1)
Can you to a few tests please.

a) Copy the text from any app you want (gedit, browser, ...).
    Keep the app open, launch your synedit test, and check

b) Copy the text from another app with synedit.
    Keep the app open, launch your synedit test, and check

2)
At the start of your app (or in an onButtonPress), insert
  Caption := clipboard.AsText;

Does the caption get set correctly?

-------------------
Note that pasting with the middle mouse button, uses a different clipboard (PrimarySelection).

----
It works fine for me, with Fedora 28 / Gnome, under VirtualBox.
No clipboard helper, so the app from which I copy, must remain open.
« Last Edit: October 21, 2018, 02:26:50 pm by Martin_fr »