How to detect CMD-V in the SE

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

How to detect CMD-V in the SE

Post by dunbarx » Fri Dec 22, 2023 5:40 pm

I have a little tool that sets the backColor of selected portions of the SE so I can find those areas again while debugging. Has worked fine for many years.

Code: Select all

   ...get the selectedLines
            put word 2 of it into startLine ; put word 4 of it into endLine ; put word 7 of it into tField --tField is the SE
            set the backColor of line startline to endLine of fld tField to "255,255,215"
The colored portions are robust in that if I add or delete lines within such a colored portion, the backColor adjusts to the extent of the new lines. But if I paste anything anywhere, the backColor of the entire SE reverts to the default empty.

I guess I can store the current text portions in a custom property somewhere and reColor every time the SE is in front and I paste something, but does anyone have a better idea? I am a little skittish about lightly hacking the SE in the first place.

The point of this query is really this: Dammit, why does pasting change the backColor of an SE field? It does not do so in an "ordinary" field, and isn't the SE just a stack with fields on it? What sort of baggage does this stack carry, and how can I bypass it instead of recoloring each time I paste?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How to detect CMD-V in the SE

Post by richmond62 » Fri Dec 22, 2023 8:29 pm

That 'SE' was not very helpful: took me a while to work out you mean the Script Editor . . . 8)

And, I must be missing something, as this:
-
Screenshot 2023-12-22 at 21.33.08.jpg
-
doesn't do anything.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to detect CMD-V in the SE

Post by FourthWorld » Fri Dec 22, 2023 11:13 pm

Exercise for the brave reader: start in the SE's File menu, and manually trace out the chain of calls from the case block in menuPick for the Save item.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to detect CMD-V in the SE

Post by dunbarx » Sat Dec 23, 2023 2:15 am

@ Richmond.

And I also did not, though years ago, know right away what the "SE" was when I first saw it.

But what on earth could that line of code of yours possibly do? The SE is a stack, and contains one or more fields for each control that one is working with. The "scriptEditor" is not, as you wrote it, a custom property of some button.

The "selectedLines" function returns a string that can be decomposed as I posted. It contains all the information I (or anyone) need to color a block of lines. Try it.

@ Richard.

I will try to dig though that. I assume, since you mentioned it, that there are perhaps front or back scripts that might do things to the properties of SE fields upon dealing with a paste. If I cannot safely work that, I will do plan B, save the selected lines in a custom property and recolor after each paste, trapping "rawKeyDown 118" with commandKey .

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to detect CMD-V in the SE

Post by jacque » Sat Dec 23, 2023 7:49 pm

My guess is that a paste requires the SE to recalculate the red dot breakpoints, the formatting, and the text coloration; basically the entire display, so it reverts to LC native script styling.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to detect CMD-V in the SE

Post by bn » Sun Dec 24, 2023 11:40 am

@Dunbarx,

You would probably like to look at handler

actionPaste in stack "com.livecode.scripteditor.behavior.editorcommon"
For me the easiest is to open the stack via the Properties Inspector with "Show IDE Stacks in Lists" turned on.
Whatever you do it will probably confuse the Script Editor.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to detect CMD-V in the SE

Post by dunbarx » Sun Dec 24, 2023 5:17 pm

Bernd.

I am used to confusing my betters.

I think I will do plan B. the reColorizing thing. I can do that in ten minutes in the plug-in I use for all my tools, including testing to see why it does not work.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to detect CMD-V in the SE

Post by bn » Mon Dec 25, 2023 4:49 pm

Craig,

in case you want to try to change 'actionPaste':

Code: Select all

   
   -- more code
   textEndGroup
   set the backColor of char tFrom to tFrom + length(the clipboardData["text"]) of field "Script" of me to "yellow" ## add this line
   unlock screen
end actionPaste
It sets the backColor, if you want to paste repeatedly you will have to turn "Auto Format" in Preferences off.

If you reformat the script your colorization will be gone but you know that already.

Saving stack "com.livecode.scripteditor.behavior.editorcommon" will make the changes permanent for that copy of LC.

I just wanted to know what it takes to implement your colorization when pasting in Script Editor.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to detect CMD-V in the SE

Post by dunbarx » Mon Dec 25, 2023 6:53 pm

Bernd.

I have not looked into any of the innards of the SE stack. My tool tallies up any tracts of selected lines and colorizes them, all from a keyboard shortcut.

I will just store the line data in a custom property of the SE every time I invoke the code that colorizes in the first place. Then upon CMD-V restore those lines.

Craig

Post Reply

Return to “Talking LiveCode”