delete character preceding cursor in a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
delete character preceding cursor in a field
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
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
Re: delete character preceding cursor in a field
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
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
Re: delete character preceding cursor in a field
Hi again.
Are you saying that you want to delete ONLY when shift-delete is pressed? If so, play with this sort of thing:
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
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 rawKeyDownCraig
Re: delete character preceding cursor in a field
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:
The selectedChunk already contains a field reference (see the dictionary entry) so adding the selectedField after it breaks the syntax.
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 tSelectionEndJacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10066
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: delete character preceding cursor in a field
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
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: delete character preceding cursor in a field
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.FourthWorld wrote:I thought Apple's Delete key already supported forward delete when used with the Function key - does this no longer work?:
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: delete character preceding cursor in a field
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
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
Re: delete character preceding cursor in a field
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.
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
HyperActive Software | http://www.hyperactivesw.com