How to make a text field "copyable" but not editable?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to make a text field "copyable" but not editable?

Post by bogs » Thu May 30, 2019 8:36 pm

I thought of that myself Jacque (scary, isn't it? :shock: ) but, I also see two similar instances where it goes either way outside of Lc.

*IF* you have the Thunderbird mail client, for instance, and have an rss feed setup in it, and you click in the text of a feed, you get no cursor like what is proposed, and that is expected as Craig mentioned.

However, if you also have Firefox, and you come here to say, post a reply, and you click in the text of the topic review area below the reply field, you *do* see a cursor :shock: :shock:
mxgkg6adEQ.png
confusing, isn't it?
So, in 2 different programs by the same group of dev's (more or less) you have 2 different behaviors where the cursor is concerned in a locked field.

*Edit - I should point out that FF also displays that cursor if you are just reading a thread, and click in the middle of any text on the page.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: How to make a text field "copyable" but not editable?

Post by kaveh1000 » Thu May 30, 2019 9:49 pm

My use case is that I want to be able to move around a field, highlight text using arrow keys and shift key etc, and pressing a key or button to set off an action, for instance:

• Copy text to another field
• Change the backgroundcolor of selection
• etc

But not be able to change the text.
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: How to make a text field "copyable" but not editable?

Post by dunbarx » Thu May 30, 2019 10:48 pm

Kaveh.

Cummon. Make this more fun.

In a locked field with some text:

Code: Select all

on mouseMove x,y
   if the mouseLoc is within the rect of me then select the mouseText
end mouseMove

on mouseUp
   set the clipboardData to the mouseText
end mouseUp
I can think of lots more additional gadgetry to make all your dreams come true. :wink:

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: How to make a text field "copyable" but not editable?

Post by kaveh1000 » Thu May 30, 2019 11:06 pm

Thanks Craig. Just when I think I have seen all the magic that LiveCode can come up with you give me new ones. ;-)

I also need to be able to see cursor so that shift right selects next char.

Actually the first approach I tried was to use an unlocked text, but stop changes to it with a number of handlers, e.g.

Code: Select all

on deletekey
  exit deletekey
end deletekey

on backspacekey
  exit backspacekey
end backspacekey
Perhaps that is a better approach to take...
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: How to make a text field "copyable" but not editable?

Post by dunbarx » Fri May 31, 2019 3:05 pm

Well, you can:

Code: Select all

on mouseEnter
set the cursor to iBeam
lock cursor
But you will bump into the interface guidelines, as Jacque and I discussed above.

And you can select the actual character the mouse is hovering over with;

Code: Select all

  if the mouseLoc is within the rect of me then select char word 2 of the mouseCharchunk of me
If you only determine what char that is, whether selected or not, you can use that information to allow an arrowKey to select either of its neighbors.

Cummon. Have some fun :wink:

Craig

Post Reply