Bug reported relating to textchanged

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Bug reported relating to textchanged

Post by kaveh1000 » Sat May 04, 2019 5:56 pm

I have reported a bug here:

https://quality.livecode.com/show_bug.cgi?id=22039

Summary:

Adding text to a field via a script does not invoke textchanged
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Bug reported relating to textchanged

Post by bogs » Sat May 04, 2019 6:30 pm

There are a number of events that do not invoke textChanged in a field. Cut/copy/paste, mouse clicks, etc. For most of those, though, rawKeyUp/Down *does* see the event.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Bug reported relating to textchanged

Post by kaveh1000 » Sat May 04, 2019 6:46 pm

But it seems to me this is a bug.

Cut also did not invoke textchanged but was fixed recently:

https://quality.livecode.com/show_bug.cgi?id=21802
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Bug reported relating to textchanged

Post by bogs » Sat May 04, 2019 7:32 pm

I'm sorry for not being clearer kaveh, I'm not saying it is not a bug, I'm just pointing out there are lots of events where it doesn't trigger, and that rawKey* does for most of them.

I was surprised to find it out as well, as I made the assumption that 'textChanged' *should* reflect text changing in the field under any circumstance, based on reading this description of it (Max's wiki)
Is dispatched by the field whenever a user (or simulated user) action causes the content of the field to change.

Handle the textChanged message if you want to perform an action when the content of a field changes.

The message is sent immediately after the input operation completes, but before a screen update is requested. The corresponding update occurs at the end of the first command in the textChanged handler. This means that you can lock the screen at the first line of the handler to delay the screen update (allowing you to modify the content of the field without any flicker).
<sic>
The textChanged message is sent after messages such as keyDown and pasteKey but before messages such as keyUp.

...so I agree it sounds like a 'bug', but until they fix it if you need to know when something is happening in the field, you can substitute rawKey* events.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Bug reported relating to textchanged

Post by kaveh1000 » Sat May 04, 2019 10:05 pm

Ah, got it. Sorry, my confusion!

OK, but how do I use rawkey to find out if a text has been changed using a handler? I can't use on rawkeydown in place of on textchanged can I?

Pls see my minimal file I submitted in the bug report. I have added a rawkeydown handler.

Kaveh
Attachments
textchanged.livecode.zip
(1.31 KiB) Downloaded 194 times
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Bug reported relating to textchanged

Post by bogs » Sat May 04, 2019 10:37 pm

First thing I'd do with your stack is change rawKey to call something else, not process what is happening and pop up a dialog

Code: Select all

on textchanged
   answer "Changed"
end textchanged

on rawkeyUp
  //  answer "Changed"
  yourHandlerHere
end rawkeyUp
For instance, you may have seen my basic text editing tutorial, part 1. In it, I used this very technique in place of textChanged. Here is the way I structured it -

Code: Select all

local lclContent

on openField
   put me into lclContent
   charCount; saveCheck; scrollCheck
end openField

on rawKeyUp
   charCount; saveCheck; scrollCheck --<-- calling 3 other handlers to deal with what changes...
end rawKeyUp

on tabKey
   put "    " before the selectedChunk
end tabKey

on saveNow
// rawKeyUp lets this handler update the count for every character compared to the fields original state... 
   if the number of characters of me > (the number of characters of lclContent + 400) then
      put "Save Now ?" into field "saved"
   else
      put "" into field "saved"
   end if
end saveNow

on charCount
// rawKeyUp lets this handler update for every stroke that produces a character...
   put the number of characters of me && "Characters" into field "charCounter"
end charCount

on scrollCheck
// rawKeyUp lets this handler update to see if we need a scrollbar...
   if the formattedHeight of me > the height of me then
      set the vScrollbar of me to true
   else
      set the vScrollbar of me to false
   end if
end scrollCheck
In that code, 'charCount', 'saveCheck', and 'scrollCheck' all not only have to know if the field is different, but they have to know no matter what is going on, which may not be just typing. Opening the field sends a check, but the only way I could tell if something was pasted using the mouse was in using rawKey to send the check after each raw key message was processed.

Using it, you can also determine if someone was using a key combo that you didn't want enabled, like ctrl + c, and using other handlers to deal with it, but there are other message handlers built in that do most of that. Raw key is just a more precise instrument.
Image

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Bug reported relating to textchanged

Post by kaveh1000 » Sun May 05, 2019 11:41 am

Thank you Bogs. I have watched the first tutorial and very useful. Is there a part 2?
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Bug reported relating to textchanged

Post by bogs » Sun May 05, 2019 12:05 pm

There is, but it is a bit more complicated to put up. I think I am going to introduce some smaller subjects because, even though the actual tutorial is easy, the intuition behind it is not for people coming from other languages (I know it wasn't easy for me to grasp, at any rate).
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Bug reported relating to textchanged

Post by jacque » Sun May 05, 2019 3:41 pm

The textChanged message is only sent after manual user input. Presumably if a script implements a change, it knows and will call the appropriate handlers as necessary. Cut was fixed because it's a user action.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Bug reported relating to textchanged

Post by kaveh1000 » Sun May 05, 2019 10:20 pm

Yes. In my case I can have a workaround by getting the external script doing the change to do what is necessary, as it knows text has changed. But I have to put this workaround for any script making the change. It would be nicer if the field could indicate a change no matter how that change was made.
Kaveh

Post Reply

Return to “Talking LiveCode”