Delete Character In Field.

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 226
Joined: Tue Aug 05, 2014 10:07 am

Delete Character In Field.

Post by Googie85 » Mon Dec 09, 2024 10:09 am

Hi Guys, I have a quick question.

Let's say I have a field with the contents "Tester". If I was to generate the message "backspaceKey", how would I delete the "s" when the cursor is behind the "s"? Is there a way I can see the char number that the cursor is at so that I can delete the character that precedes the cursor?

I hope I explained myself clearly!!!

Many Thanks,

Googie.

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

Re: Delete Character In Field.

Post by dunbarx » Mon Dec 09, 2024 4:47 pm

Hi.

On a new card with a field 1 containing your text and a button, put this in the button script:

Code: Select all

on mouseUp
   if char (word 2 of the selectedChunk) of fld 1 = "s" then answer "You have an S!"
end mouseUp
If the cursor is blinking just behind an "s" you will get a dialog. I assume you can expand on this with your deletion thing.

Craig

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

Re: Delete Character In Field.

Post by dunbarx » Mon Dec 09, 2024 4:52 pm

I had an extra minute.

Code: Select all

on mouseUp
   get word 2 of the selectedChunk
   if char it of fld 1 = "s" then delete char it of fld 1
end mouseUp
Craig

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

Re: Delete Character In Field.

Post by dunbarx » Mon Dec 09, 2024 5:18 pm

Googie.

Just a question. Does "Googie" possibly derive from an old Theodore Sturgeon science fiction story?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Delete Character In Field.

Post by richmond62 » Mon Dec 09, 2024 6:19 pm

This is slightly off-topic, but what is the logic behind 'word 2'?

If I do this:

Code: Select all

on mouseUp
   put word 1 of the selectedChunk
end mouseUp
I get 'char'

and if I do this:

Code: Select all

on mouseUp
   put word 2 of the selectedChunk
end mouseUp
I get a number (the number of the letter just before the cursor in the field), and if
I do this:

Code: Select all

on mouseUp
   put word 3 of the selectedChunk
end mouseUp
I will always get 'to'.

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

Re: Delete Character In Field.

Post by dunbarx » Mon Dec 09, 2024 6:30 pm

Richmond.

I do not understand your question. Make a quick stack as I described but in the button script only retrieve the selectedChunk itself. Place the cursor somewhere in the text of the field and click the button .

See?

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delete Character In Field.

Post by Klaus » Mon Dec 09, 2024 6:46 pm

OH BOY, Richmond...

Code: Select all

put the selectedchunk
Will surely enlighten you, if not, get another hobby. :-D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Delete Character In Field.

Post by richmond62 » Mon Dec 09, 2024 6:52 pm

With the cursor between 2 letters (i.e. NO text is selected) I get nothing.

That still does not explain word 1, word 2, or word 3.

A single character before the cursor insertion point is not a word.
Last edited by richmond62 on Mon Dec 09, 2024 6:54 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delete Character In Field.

Post by Klaus » Mon Dec 09, 2024 6:52 pm

Some hints...

Button script:

Code: Select all

put the selectedchunk
No text selected, cursor is blinking after the 2nd character in the field:
selectedchunk2.png
selectedchunk2.png (29.79 KiB) Viewed 11604 times
Some text selected:
selectedchunk1.png
selectedchunk1.png (26.01 KiB) Viewed 11604 times

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

Re: Delete Character In Field.

Post by dunbarx » Mon Dec 09, 2024 7:08 pm

Richmond.
With the cursor between 2 letters (i.e. NO text is selected) I get nothing.
I bet you do, if you really have a blinking cursor.

Anyway, it is not really true that "no text is selected", as you put it, though I understand your point. When the selectedChunk returns a value that has word 2 greater than word 4, it indicates just that case, a blinking cursor in the body of the text but with no actual character(s) selected.

One might say that the existence of the cursor within the text constitutes a selection, albeit a very narrow one. :wink:

Anyway, a blinking cursor is rightly considered to be a participant in the text, and the selectedChunk locates it with two "reverse" numbers, the chars after and before the cursor.

Craig
Last edited by dunbarx on Tue Dec 10, 2024 9:45 pm, edited 1 time in total.

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

Re: Delete Character In Field.

Post by jacque » Tue Dec 10, 2024 6:51 pm

Richmond: we evaluate the string returned in the selectedChunk. The first four words of that string include the character positions. I'm not sure what you were expecting?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply