Last entered word in filed

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
shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Last entered word in filed

Post by shalu » Fri Jun 10, 2016 9:45 am

Hi All,

I have text field, when I type anything and press space bar the field become empty. If I press up arrow then it should display the last command (like linux terminal) , If I press down arrow also display the nex command . How I do this :(
--
Thanks
Shalu S

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

Re: Last entered word in filed

Post by dunbarx » Sat Jun 11, 2016 1:51 pm

Hi.

Do you mean that you want the field to "become" empty when you press spacebar? That is easy.

But what do you mean by "the last" or "the next" command?

Craig Newman

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Last entered word in filed

Post by jmburnod » Sat Jun 11, 2016 6:11 pm

Hi Craig,
But what do you mean by "the last" or "the next" command?
I think expected behavior is same of messages box.
Best
Jean-Marc
https://alternatic.ch

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

Re: Last entered word in filed

Post by dunbarx » Sun Jun 12, 2016 1:28 pm

Shalu.

So is Jean-Marc correct? You want this field to work like the message box? Interesting challenge if so, but please confirm.

Craig

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: Last entered word in filed

Post by shalu » Mon Jun 13, 2016 6:37 am

@dunbarx sorry for the late reply, I want a field like

When I type any text and press space bar the field should be empty

When I press up-arrow the field should display last typed text
--
Thanks
Shalu S

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

Re: Last entered word in filed

Post by dunbarx » Mon Jun 13, 2016 3:07 pm

OK. I did this in two handlers for readability. You need to pay me by rewriting in a single handler. Now which message should you use?

In a field script:

Code: Select all

on keyDown tkey
   put tKey after me
   set the lastText of me to me
   if tkey is space then put "" into me
end keyDown

on rawKeyDown tKey
   if tKey = 65362 then set the text of me to the lastText of me
   select after text of me
   pass rawKeyDown
end rawKeyDown
Get going.

Craig

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: Last entered word in filed

Post by shalu » Tue Jun 14, 2016 7:09 am

@dunbarx This is awesome. suppose I want see the all entered word in field then, how I change this code
--
Thanks
Shalu S

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

Re: Last entered word in filed

Post by dunbarx » Tue Jun 14, 2016 1:45 pm

Sorry.
suppose I want see the all entered word in field then, how I change this code
I do not understand what you want.

Craig

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

Re: Last entered word in filed

Post by Klaus » Tue Jun 14, 2016 4:26 pm

Hi Shalu,

do you have any idea what Craig's script actually does?


Best

Klaus

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: Last entered word in filed

Post by shalu » Wed Jun 15, 2016 5:57 am

@dunbarx @Klaus sorry for the late reply

now the last entered word is placed into lastText "set the lastText of me to me", I want all word I entered into the field is placed into "lastText".
--
Thanks
Shalu S

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: Last entered word in filed

Post by shalu » Wed Jun 15, 2016 10:57 am

samlpe video is attached, I think now you understand my requrement
Attachments
s.zip
(47.93 KiB) Downloaded 222 times
--
Thanks
Shalu S

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

Re: Last entered word in filed

Post by dunbarx » Wed Jun 15, 2016 3:18 pm

Shalu.

I have seen your video, but I do not understand it.

But is this what you wanted":

Code: Select all

on keyDown tkey
   put tKey after me
   set the lastText of me to the lastText of me & tKey
   if tkey is space then put "" into me
end keyDown

on rawKeyDown tKey
   if tKey = 65362 then set the text of me to the lastText of me
   select after last char of me
 pass rawKeyDown
end rawKeyDown
Craig

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: Last entered word in filed

Post by shalu » Tue Jun 28, 2016 10:19 am

@dunbarx sorry for the late reply

It's ok now but the problem is when I press up arrow tex field is display the all last entered words. suppose the last entered words are word1, word2, word3 (word1 space word2 space e.t.c). If I press up arrow then word3 should display and If I again press uparrow then word2 should display. now the current output is word1 word2 word3
--
Thanks
Shalu S

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

Re: Last entered word in filed

Post by dunbarx » Tue Jun 28, 2016 4:13 pm

Hmmm.

Are you saying you want to store each field entry separately when you hit the spacebar? That is, each time the field is cleared? And then recall those entries one-by-one when you hit the up arrow?

If so, then make a second field, a bit larger than the first. Change your field handler to this:

Code: Select all

on keyDown tkey
      put tKey after me
      if tkey is space then
       set the lastText of me to me & return & the lastText of me
      put "" into me
   end if
   put the lastText of me into fld 2
end keyDown

on rawKeyDown tKey
   if tKey = 65362 then 
   --your homework here
 pass rawKeyDown
end rawKeyDown
Now this will load your text snippets into both the custom property and the field so you can see it. You will want to think of a way to clear that property, I would imagine, and maybe add other required gadgetry.

@Jacque, please look the other way. OK? Good. Now, Shalu, tell me how you can, in the "rawKeyDown" handler, extract each line of the custom property, one by one. This is tricky, but should be fun.

@Jacque! I asked you to turn around please.

Craig

Post Reply