Page 1 of 1

Delete Character In Field.

Posted: Mon Dec 09, 2024 10:09 am
by Googie85
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.

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 4:47 pm
by dunbarx
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

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 4:52 pm
by dunbarx
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

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 5:18 pm
by dunbarx
Googie.

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

Craig

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 6:19 pm
by richmond62
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'.

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 6:30 pm
by dunbarx
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

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 6:46 pm
by Klaus
OH BOY, Richmond...

Code: Select all

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

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 6:52 pm
by richmond62
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.

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 6:52 pm
by Klaus
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 11608 times
Some text selected:
selectedchunk1.png
selectedchunk1.png (26.01 KiB) Viewed 11608 times

Re: Delete Character In Field.

Posted: Mon Dec 09, 2024 7:08 pm
by dunbarx
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

Re: Delete Character In Field.

Posted: Tue Dec 10, 2024 6:51 pm
by jacque
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?