Recent

Author Topic: Selecting text in code editor copies to clipboard, why?  (Read 725 times)

BosseB

  • Full Member
  • ***
  • Posts: 198
Selecting text in code editor copies to clipboard, why?
« on: February 16, 2020, 06:34:53 pm »
I am trying to edit my code by replacing literals with constant name references.
So I copy the constant's name from the declaration and then I select the literal string at the target to Ctrl-V paste it.
But it fails every time, the target stays put.
It turns out that selecting a code section seems to also copy it into the clipboard, replacing what has already been put there.
So now I have to add the operation of delete the target, then go to the source document and copy the identifier, then go back and put the cursor in place without selecting anything before the paste.
Then it works.

How can I switch off this bogus copy operation?

Lazarus 2.0.6, Fpc 3.0.4 on Raspberry Pi4 via VNC on a Windows10 laptop.
Source document is on the PC target is in Lazarus on the RPi4.
--
Bo Berglund
Sweden

winni

  • Hero Member
  • *****
  • Posts: 1452
Re: Selecting text in code editor copies to clipboard, why?
« Reply #1 on: February 16, 2020, 07:15:38 pm »
Hi!

In the find / replace dialog is a selection

* Selected Text
* Global

Did you choose the right one?

Winni

BosseB

  • Full Member
  • ***
  • Posts: 198
Re: Selecting text in code editor copies to clipboard, why?
« Reply #2 on: February 16, 2020, 08:28:35 pm »
In the find / replace dialog is a selection

* Selected Text
* Global

Did you choose the right one?
I am not talking about the find/replace here. What I am saying is that if I have a text snippet (a variable name for example) in the clipboard and want to replace a literal text with it my usual method is this:
- Select the text that is to be replaced
- Use Ctrl-V to paste the clipboard content
But in Lazarus what happens seems to be that when I select the existing text it copies itself into the clipboard so when I paste with Ctrl-V nothing seems to happen because the text is pasted on top of itself. And what I originally copied is lost.

I have a lot of instances where I have used literal identifiers for things that go into config files, like so:
Code: Pascal  [Select][+][-]
  1. WriteIniString(Section, 'CommandFile', CmdFileName, TaskFile);

Then the corresponding ReadIniString needs to be:
Code: Pascal  [Select][+][-]
  1. CmdFileName := ReadIniString(Section, 'CommandFile', CmdFileName, TaskFile);

But these identifiers are also used in other places like on website form declarations and they need to be exactly the same everywhere so I have decided to set them as constant strings which are used everywhere instead of the literal strings:
So in a common used file:
Code: Pascal  [Select][+][-]
  1. const
  2.   dnCmdFile = 'commandfile';

And in the places where it is used:
Code: Pascal  [Select][+][-]
  1. WriteIniString(Section, dnCmdFile, CmdFileName, TaskFile);
  2. CmdFileName := ReadIniString(Section, dnCmdFile, CmdFileName, TaskFile);

Now, when I am going to clean up my code I use the defined constant names by copying the name and then pasting it on top of the text in all the various places it has been used. And now it is very inconvenient that Lazarus keeps copying the text I select so the paste does nothing. I want my copied text to remain in the clipboard so I can move to all the different places where it must be pasted in...

There must be a setting somewhere to enable/disable this automatic copying into the clipboard...
But where do I look?

--
Bo Berglund
Sweden

winni

  • Hero Member
  • *****
  • Posts: 1452
Re: Selecting text in code editor copies to clipboard, why?
« Reply #3 on: February 16, 2020, 08:43:04 pm »
Hi!

Raspberry  is Linux and Linux has two different Clipboard buffers:

* The one you know from Windows: mark text, Ctrl-C or Ctrl-X and then Ctrl- V
* Mark text and then insert it with the middle mouse key

Don't mix the two ways of clipboard!

Winni

BosseB

  • Full Member
  • ***
  • Posts: 198
Re: Selecting text in code editor copies to clipboard, why?
« Reply #4 on: February 16, 2020, 11:40:49 pm »
Raspberry  is Linux and Linux has two different Clipboard buffers:

* The one you know from Windows: mark text, Ctrl-C or Ctrl-X and then Ctrl- V
* Mark text and then insert it with the middle mouse key

Don't mix the two ways of clipboard!

The select + middle-button click case works in a terminal window to RPi4 (with Raspbian Buster).
It could be PuTTY from Windows or a Terminal started in the RPi4 desktop.
In such a situation I use it often, but this is without Lazarus involved.

I have noted that a selection in the GUI terminal on Raspbian can be pasted within the terminal itself, and in Lazarus using middle button.
In Lazarus the clipboard content stays the same as before, but if I right click in the terminal I can select copy.
After this it is possible to paste in Lazarus too with Ctrl-V.

But this is not the case I am asking about...

I am copying within Lazarus and I have found now that if I double-click a word inside Lazarus it gets selected and also copied into the clipboard that allows middle button pasting both inside Lazarus and in the terminal window.
But if I select a word in Lazarus without doubleclicking then it will not middle-button-paste.

The plot thickens...
If I select a word inside Lazarus I can paste it with the middle button, but if I use ctrl-V instead an older clipboard entry gets pasted.

Oh Boy!!!!

I need to create a matrix of all the combinations now and enter how paste works in all situations.
Very strange.
--
Bo Berglund
Sweden

winni

  • Hero Member
  • *****
  • Posts: 1452
Re: Selecting text in code editor copies to clipboard, why?
« Reply #5 on: February 16, 2020, 11:55:16 pm »
Dont  make it too complicated.

DoubleClick: Word select. Ctrl-C or Ctrl-X : it is in the Windows Clipboard.

Ctrl-V : paste  it everywhere you want .

But perhaps you should write a small program or app to replace all you want in your source.
Not a big trick.

Winni

dbannon

  • Hero Member
  • *****
  • Posts: 1070
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Selecting text in code editor copies to clipboard, why?
« Reply #6 on: February 17, 2020, 04:07:16 am »
Don't mix the two ways of clipboard!

......

I am copying within Lazarus and I have found now that if I double-click a word inside Lazarus it gets selected and also copied into the clipboard that allows middle button pasting both inside Lazarus and in the terminal window.
But if I select a word in Lazarus without doubleclicking then it will not middle-button-paste.

The plot thickens...
If I select a word inside Lazarus I can paste it with the middle button, but if I use ctrl-V instead an older clipboard entry gets pasted.

Oh Boy!!!!

I need to create a matrix of all the combinations now and enter how paste works in all situations.
Very strange.

As winni says, there are two quite different copy and paste methods in Linux. They should not interact at all and you should not confuse them.

On my linux box, in Lazarus and else where, if I double click a word, it becomes selected, that triggers the primary copy mechanism, its not the double clicking that does it, its the word becoming selected. A wipe selection does the same thing.  I can then paste that primary content somewhere with a middle button click (or three finger tap on touch pad).  But you cannot select something first to paste over because the action of selecting triggers another primary copy, you end up with the wrong content in the primary clipboard.

The primary paste does not require to click on the desired destination, just have the mouse in the spot you want it to paste.

So, to do what you want, you must use the 'other' copy and paste mechanism. Thats copy with Crtl-C, or RightClick-> Copy and then either selecting a target word or clicking on a destination and Ctrl-V or RightClick->Paste.

EDIT: When I say the two models don't interact, I need point out that they do appear to interact.  Using the secondary model, when you select something to copy, you also trigger a primary copy.  And when you select another something to paste over, again, you trigger a primary copy.

Davo
« Last Edit: February 17, 2020, 04:26:34 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018