Bug reported relating to textchanged
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Bug reported relating to textchanged
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
https://quality.livecode.com/show_bug.cgi?id=22039
Summary:
Adding text to a field via a script does not invoke textchanged
Kaveh
Re: Bug reported relating to textchanged
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.
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Bug reported relating to textchanged
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
Cut also did not invoke textchanged but was fixed recently:
https://quality.livecode.com/show_bug.cgi?id=21802
Kaveh
Re: Bug reported relating to textchanged
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)
...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.
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.
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Bug reported relating to textchanged
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
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
Re: Bug reported relating to textchanged
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
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 -
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.
Code: Select all
on textchanged
answer "Changed"
end textchanged
on rawkeyUp
// answer "Changed"
yourHandlerHere
end rawkeyUp
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
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.
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Bug reported relating to textchanged
Thank you Bogs. I have watched the first tutorial and very useful. Is there a part 2?
Kaveh
Re: Bug reported relating to textchanged
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).
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Bug reported relating to textchanged
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
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Bug reported relating to textchanged
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