delete character preceding cursor in a field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bergsy
Posts: 45
Joined: Mon Oct 28, 2013 10:51 pm

delete character preceding cursor in a field

Post by bergsy » Sat Jun 06, 2015 3:26 am

Hi,

I am trying to implement "Shift-del" on a Mac, which needs to delete the character immediately before the cursor in a field.

I am at a loss as to how to do this. I suspect it is really simple but I can't find anything posted that does it.

I have read through a number of posts and have come up with the code below but I can't get it to work as I get "no target found" when executing "put word 2...."

on rawKeyDown theKeyNumber
if theKeyNumber is 65535 and the selectedField is not empty and the platform is "MacOS" then
-- delete or shift delete hit, so delete the previous character
put word 2 of the selectedChunk of the selectedField into tSelectionStart
put word 4 of the selectedChunk of the selectedField into tSelectionEnd
delete the char tSelectionStart of the selectedField
else
pass rawKeyDown
end if
end rawKeyDown

Thanks

Greg

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

Re: delete character preceding cursor in a field

Post by dunbarx » Sat Jun 06, 2015 1:53 pm

Um, Hi.

I am on a Mac laptop currently, so I do not have an extended keyboard. My only delete option is the backspace key 65288.

Your code seems sound, though I did not test it, but I do not understand why you need it. The delete and backspace keys already do just what you asked, they delete the preceding char and set the cursor at that point. Did you mean you wanted to delete the preceding word? Or some other chunk or chunk "fragment" within or around the current selection?

Craig Newman

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

Re: delete character preceding cursor in a field

Post by dunbarx » Sat Jun 06, 2015 4:33 pm

Hi again.

Are you saying that you want to delete ONLY when shift-delete is pressed? If so, play with this sort of thing:

Code: Select all

on rawKeyDown theKeyNumber
   get word 2 of the selectedChunk
   switch 
      case theKeyNumber is 65288 and the shiftKey is down
         delete char it - 1 of me
         break
      case theKeyNumber is not 65288 
         pass rawkeyDown
         break
   end switch
end rawKeyDown
Now this is pretty verbose, but I wanted you to see how to separate functionality into well defined clauses. Your homework is to rewrite this as an if/then construction. And maybe to extend or separate the functionality of key 65335.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7403
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: delete character preceding cursor in a field

Post by jacque » Sat Jun 06, 2015 5:55 pm

I'm not sure why shift delete is needed either. Did you mean to implement forward delete?

At any rate, the reason your handler is erroring is because there are duplicate field references:

Code: Select all

put word 2 of the selectedChunk of the selectedField into tSelectionStart
put word 4 of the selectedChunk of the selectedField into tSelectionEnd
The selectedChunk already contains a field reference (see the dictionary entry) so adding the selectedField after it breaks the syntax.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10066
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: delete character preceding cursor in a field

Post by FourthWorld » Sat Jun 06, 2015 6:33 pm

I thought Apple's Delete key already supported forward delete when used with the Function key - does this no longer work?:

http://lifehacker.com/5803041/the-mac-o ... -both-ways
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7403
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: delete character preceding cursor in a field

Post by jacque » Sat Jun 06, 2015 8:27 pm

FourthWorld wrote:I thought Apple's Delete key already supported forward delete when used with the Function key - does this no longer work?:
It still works. I haven't tested to see if LC does anything with the raw key code without a script though. It does work in the IDE.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bergsy
Posts: 45
Joined: Mon Oct 28, 2013 10:51 pm

Re: delete character preceding cursor in a field

Post by bergsy » Sun Jun 07, 2015 6:15 am

Hi all,

Thanks for the comments. I know the user can use the Delete key but my Mac users are insisting that Shift-Del does the same thing. I have tried just telling them to just Delete, but I am getting an "out way or the highway" from them! As long as they are flexible I guess ;-(...not

Anyway, Craig your solution works when I replace "Of me" with "of the selectedField"

Thanks again

Cheers

Greg

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7403
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: delete character preceding cursor in a field

Post by jacque » Mon Jun 08, 2015 7:35 pm

Here are the standard recognized Mac keyboard shortcuts: https://support.apple.com/en-us/HT201236 Shift-delete is not there.

Shift-delete is sometimes used in particular apps to delete whole units of something; for example, Thunderbird uses shift-delete to permanently delete an email message without sending it to the trash folder. On Windows, shift-delete does the same thing with files in Explorer. The shift key generally indicates a permanent removal as opposed to an undo-able action. I have never seen it implemented as a normal Mac editing function when working strictly with text though.

So while you may want to implement this feature because of user demand, it is definitely not standard and I think your Mac users are wrong. There are several deletion shortcuts in the web page above, but they all control forward-delete, or whole word deletions, or similar.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply