Predictive Text...

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

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

Re: Predictive Text...

Post by FourthWorld » Wed Mar 12, 2025 6:39 pm

dunbarx wrote:
Wed Mar 12, 2025 6:26 pm
...does not need a backSpace key handler.
Then what invokes it in response to the input text changing from the user hitting the Backspace key?
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: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 7:14 pm

Richard.

The backSpace key simply changes the contents of the entry field, just like pressing, say "X", which adds that char to the mix. Every keypress invokes the resident handler, and the current contents of the entry field is used to collect matches from the master list.

Craig
Last edited by dunbarx on Wed Mar 12, 2025 7:14 pm, edited 1 time in total.

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

Re: Predictive Text...

Post by richmond62 » Wed Mar 12, 2025 7:14 pm

Well, my solution maybe clunky (and Klaus is always alarmingly eager to squash my efforts), but it was me who produced a solution first, and I do believe that without a backspaceKey handler things might get slightly problematic.

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

Re: Predictive Text...

Post by richmond62 » Wed Mar 12, 2025 7:16 pm

Collecting matches?

I have heard of people collecting those match books from restaurants and match boxes: but matches, surely not. 8)

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 7:17 pm

Richmond,

I don't think, knowing Klaus, it is personal. :D

I am fond of saying that we all race to answer here in this forum. A race is to some degree a competition, after all, but I think it is all in good fun.

Matches? You are rarely silly, but I am happy to see it from you.

Craig

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 7:30 pm

And another thing. The filter version outputs duplicates for some reason. Mine does not, so there. :evil:

Craig

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

Re: Predictive Text...

Post by richmond62 » Wed Mar 12, 2025 7:35 pm

Andanotherthing.jpg
Andanotherthing.jpg (31.22 KiB) Viewed 5092 times
-
Yes, well . . . 8)

I guess the cork in my . . . slipped a bit. :P

Oh, and by-ther-way: I picked that book up in a third-hand sort of way in a second-hand clothes shop in Bulgaria where the price was by the kilogramme: so it was about 50 Euro cents.

A pale shadow . . . a pale shadow.

Never ceases to surprise me when perfectly decent authors who have already written readable books attempt pastiches of dead authors' stuff: pace the 57 writers who have tried their sweaty paws at James Bond novels . . .
-
CSun.jpg
-
Kingsley Amis degrading himself (perhaps he knew it so adopted a fake name).

Even at 15 that did not fool me for a minute.
Last edited by richmond62 on Wed Mar 12, 2025 7:42 pm, edited 1 time in total.

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 7:42 pm

Richmond

I never heard of this. Is it just another entry into what Adams called "the ever increasingly misnamed Hitchhikers...trilogy"?

Craig

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

Re: Predictive Text...

Post by richmond62 » Wed Mar 12, 2025 7:43 pm

It is a pastiche written by an Irish bloke quite a long time after Douglas Adams was dead.

cmhjon
Posts: 190
Joined: Tue Aug 04, 2015 11:55 am

Re: Predictive Text...

Post by cmhjon » Wed Mar 12, 2025 9:57 pm

Hi all,

First, thanks to everyone who has responded and provided code and/or sample stacks. Between everything, I…think/hope…I have managed to combine elements of the provided stacks into a relatively completed stack which seems to, for the most part work. Here is my adapted code:

Code: Select all

on keyDown KP
   put KP after me
   put me into tLookupString
   if tLookupString is empty then
      put empty into field "Results"
      hide field "Results"
      exit to top
   else
      put field 1 into tList
      filter tList with (tLookupString & "*")
      if tList = EMPTY then
         beep
         put empty into field "Results"
         hide field "Results"
         exit to top
      end if
      put tList into field "Results"
      show field "Results"
   end if
end keyDown

on backspaceKey
   delete the last char of me
   send ("keydown" & "") to me
   if me = empty then
      hide field "Results"
   end if
end backspaceKey
One issue (and there may be others that I haven’t discovered yet) is that suppose the customer name field is populated. If I highlight all the text in the field and press the backspace key, instead of deleting the text is removes the last character which based on the above code would be expected behavior. So, if I simply want to remove all the text from the field, how could this be trapped for?

Thank you again and best regards,
Jon :-)

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 10:33 pm

cmhjon.

If you hilite all, or any block of text in a field and hit backspace, all the hilted text is deleted. That is normal behavior on all platforms I believe.

Are you really seeing what you say you are???

Craig

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

Re: Predictive Text...

Post by Klaus » Wed Mar 12, 2025 10:40 pm

Hi Craig,

the script does this, but not what the TS and user might exspect:

Code: Select all

on backspaceKey
   ## SIC!
   delete the last char of me
...
This will work as exspected:

Code: Select all

on backspaceKey
   if the selectedtext of me <> EMPTY then
      pass backspaceKey
   end if
   delete the last char of me
...
Best

Klaus

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 10:53 pm

Maybe I misread your last post.

Isn't the "customer name field" the field with all your customer data? You never want to delete anything there when using your filtering routine, right?

Or is it the entry field that you want to empty with backSpace. If so then you need to add this to your script:

Code: Select all

on rawkeyDown tkey
   if tkey = 65288 and the optionkey is down then put "" into me
   pass rawkeyDown
end rawkeyDown
You must press the optionKey along with the backspace key in order to make this work. The reason is that the "keyDown" message does not recognize the backSpace key, only "rawKeyDown" does. And therefore you need to identify the action of pressing backSpace to do what you want with the optionKey modifier. You can select any of the other modifier keys if you would rather.

Craig

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

Re: Predictive Text...

Post by dunbarx » Wed Mar 12, 2025 10:58 pm

Klaus.

I got the impression that the OP wanted a way to clear the whole data entry field in one key press, and not have to press backSpace several times to do so. Of course a button would do the job just as well.

Or neither of us yet knows exactly what he wants.

cmhjon?

Craig

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

Re: Predictive Text...

Post by Klaus » Thu Mar 13, 2025 9:07 am

Hi Craig,

cmhjon wrote:
If I highlight all the text in the field and press the backspace key, instead of deleting the text is removes the last character which based on the above code would be expected behavior. So, if I simply want to remove all the text from the field, how could this be trapped for?
I understand this like cmhjon wants to have the "usual/normal" behavior of the backspacekey in a field with all of its text selected.
That is what my little addition does.

@Richmond
What Craig said, it is nothing personal Cpt. Cumbersome! :-D
Not sure this is the correct translation of the german saying***, but: Teasing is a sign of affection.
***Was sich liebt, das neckt sich.

Best

Klaus

Post Reply