Menu Buttons and the text property

Bob Sneidar bobsneidar at iotecdigital.com
Sat Feb 14 01:43:22 CET 2015


Thanks for the reply. Let me explain what I am trying to accomplish. 

I have a combo box with a property containing a list of Industry Names. Things like Retail Services, Auto Repair and such. As the user types, I want to autofill the text with the first choice in that list that matches what the user typed, then select the remaining text after it, so that typing replaces the text after the insertion point. That part works fine. 

But what happens when the user backspaces? Well it just fills in the remainder of the entry and selects after the insertion point like it normally does. I want the user to be able to delete what is there. Easy enough, I just put empty into the selectedText. But what if there *is* no selected text?? The selectedText is empty, the selected chunk is a description of the first line of the text. So it will delete the whole contents if I use that. 

Now if the selected chunk behaved in a combo box the way it does in a field, I could parse that and delete the character of the label prior to the insertion point. But it doesn’t, and no commands or functions I’ve found do. 

I did find a workaround though. The following seems to work properly. It’s a kludge in the finest tradition of epic kludges, but it works. 

on rawKeyDown pKeyCode
   if pKeyCode = 65288 then
      lock messages
      if the selection is empty then
         type numToChar(pKeyCode)
         exit to top
      end if
   end if
   pass rawKeyDown
end rawKeyDown

on textChanged
   if the label of me is empty then
      set the text of me to the options of me
      exit textChanged
   end if
   
   put the label of me into theValue
   put length(theValue) into theLength
   put the Options of me into theOptions
   filter theOptions with theValue & "*"
   
   if theOptions is not empty then
      set the text of me to theOptions
      if the text of me is among the lines of theOptions then
         -- set the label of me to line 1 of theOptions
         select char theLength +1 to -1 of me
      end if
   end if
   
   -- focus on me
   pass textChanged
end textChanged



More information about the use-livecode mailing list