Thank you Eric. I'll push an update as soon as I get the chance.

Regards,
Saq

On Monday, October 19, 2020 at 7:31:50 AM UTC+2, Eric Shulman wrote:
>
> On Sunday, October 18, 2020 at 5:00:36 PM UTC-7, cmari wrote:
>>
>> I'd like to be able to use the features of both 
>> TiddlyTools/Time/AutoSaver 
>> <http://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FAutoSaver> and 
>> Streams <https://saqimtiaz.github.io/sq-tw/streams.html>. But after some 
>> experimenting, it seems that if I add both of these plugins to an otherwise 
>> empty 5.1.22 TW, when I try to use the (TiddlyTools) Autosaver option of 
>> "confirm before saving", I get the red javascript error ("Uncaught 
>> TypeError: Cannot read property 'toString' of null). Is there something I 
>> can do to prevent this error?
>
>
> I took a look at the browser's debugging console, where it reports:
> streams.html:13257 Uncaught TypeError: Cannot read property 'toString' of 
> null
>
> $tw.utils.error @ streams.html:13257
> $:/plugins/sq/streams/selection-vars-tweak.js:29 Uncaught TypeError: 
> Cannot read property 'toString' of null
>     at TimeoutWidget.Widget.invokeActionString ($:/plugins/sq/streams/
> selection-vars-tweak.js:29)
>     at eval (TiddlyTools/Time/action-timeout.js:40)
>
> Here's a summary of what occurs:
>
>    1. The *TiddlyTools/Time/AutoSaver *countdown timer is processed by 
>    the <<countdown_tick>> macro,
>    2. which is defined in *TiddlyTools/Time/CountDown* and is called from 
>    *TiddlyTools/Time/Ticker*,
>    3. which is invoked once per second by 
>    *TiddlyTools/Time/action-timeout.js*,
>    4. which uses the *TWCore "invokeActionString()"* method.
>    5. which has been "hijacked" by the Streams plugin code contained in 
>    *$:/plugins/sq/streams/selection-vars-tweak.js*,
>    
> Take note of these two lines from 
> *$:/plugins/sq/streams/selection-vars-tweak.js*:
>  if(activeElement && selection && (activeElement.tagName === "INPUT" || 
> activeElement.tagName === "TEXTAREA")) {
>  variables["selectionStart"] = activeElement.selectionStart.toString();
>
> This is where the error actually occurs.
>
> The problem is that the code is checking for *activeElement.tagName === 
> "INPUT"*, which is OK when the activeElement has a "selectionStart" 
> property.  However, in the AutoSaver settings panel, the "confirm before 
> saving" checkbox is also an HTML "input" element, but because it is not a 
> *text* element, it has no "selectionStart" property. Thus, attempting to 
> invoke "toString()" throws the "Uncaught TypeError: Cannot read property 
> 'toString' of null" error that is reported in the browser's debugging 
> console and by the TiddlyWiki RMOD ("Red Message of Death").
>
> Note that 
> https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/activeElement
>  says 
> this:
>
> Often activeElement will return a HTMLInputElement or HTMLTextAreaElement 
>> object if it has the text selection at the time. If so, you can get more 
>> detail by using the object's selectionStart and selectionEnd properties. 
>> Other times the focused element might be a <select> element (menu) or an 
>> <input> element, of type "button", "checkbox", or "radio".
>
>
> The fix is to change the code in 
> *$:/plugins/sq/streams/selection-vars-tweak.js *to ensure that when the 
> *activeElement.tagName 
> === "INPUT"*, the *activeElement.type === "text"*, which would then 
> exclude "button", "checkbox", or "radio" input elements.
>
> Something like this will do the trick:
>  if(activeElement && selection && ((activeElement.tagName === "INPUT" && 
> activeElement.type === "TEXT") || activeElement.tagName === "TEXTAREA")) {
>
> If you edit the *$:/plugins/sq/streams/selection-vars-tweak.js* shadow 
> tiddler and change the line of code as shown above, that will bypass the 
> problem until Saq can provide an update to the Streams plugin.
>
> -e
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/320576e9-3f99-48a2-a4e1-3360377b3efeo%40googlegroups.com.

Reply via email to