Page 1 of 2

Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 10:43 am
by mrcoollion
Hello fellow LiveCoders

I so not understand why I get the below error in a one line script. I cannot be any simpler..
Error message is:
Button "InsertSource": execution error at line 2 (Chunk: no target found), char 1
The script in the button is :

Code: Select all

on mouseUp
   put "Text to insert at cursor" into the selection
end mouseUp
Working with LC 9.5 (dp 1) on Windows 10

Regards,

Paul (mrcoollion)

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 11:26 am
by Klaus
Hi Paul,

works as exspected in LC 9.04 on macOS 10.14.5.
Maybe a bug in DP1?


Best

Klaus

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 3:54 pm
by dunbarx
Hi.

Works for me too, on a Mac. This must be an odd regression.

Craig

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 7:05 pm
by FourthWorld
Is that script in a button, and is the button's traversalOn property set to true?

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 11:36 pm
by dunbarx
Richard.

I assumed the text was in a field.

Paul?

Craig

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 11:45 pm
by Klaus
dunbarx wrote:
Wed Jun 19, 2019 11:36 pm
I assumed the text was in a field.
Only a locked field will receive mouseup (1) messages! An unlocked field will only receive a right-click = mouseup (2) message, where the number is the number of the clicked mouse-button.

And if a button has it traversalon property set to true, it will get the focus when clicked and thus remove an eventual text selection.

Re: Error on 'put "My text" into the selection'

Posted: Wed Jun 19, 2019 11:46 pm
by FourthWorld
dunbarx wrote:
Wed Jun 19, 2019 11:36 pm
Richard.

I assumed the text was in a field.
Yes, so do I. My question was about the button containing the script that acts on that field.

If the traversalOn property of the button is true (which for most button styles is the default), what's reported here makes sense, and is consistent with every version I've used since 1998.

When traversalOn is true, clicking on the button shifts focus away from any previously-selected object to the button. So if text is selected, we would see that selection cleared once the mouse goes down on the button. Once the selection is cleared, "the selection" no longer returns a valid chunk reference, which would give rise to the error shown.

Turning off the traversalOn property of the button should remedy this easily. Provided, that is, that the traversalOn is currently true. To know that we'll have to wait for the OP to reply.

Re: Error on 'put "My text" into the selection'

Posted: Thu Jun 20, 2019 9:37 am
by mrcoollion
Hi everyone,

Thanks for the support.
After some testing the traversal property (Focus with keyboard) set to true was the reason it did not worked.
I should have known this myself... :oops: Probably had tooo much ..... in the weekend :lol:

Thanks again...

Re: Error on 'put "My text" into the selection'

Posted: Thu Jun 20, 2019 11:37 am
by FourthWorld
mrcoollion wrote:
Thu Jun 20, 2019 9:37 am
I should have known this myself... :oops: Probably had tooo much ..... in the weekend :lol:
One never needs to apologise for living well. :)

Re: Error on 'put "My text" into the selection'

Posted: Thu Jun 20, 2019 11:40 am
by Klaus
FourthWorld wrote:
Thu Jun 20, 2019 11:37 am
mrcoollion wrote:
Thu Jun 20, 2019 9:37 am
I should have known this myself... :oops: Probably had tooo much ..... in the weekend :lol:
One never needs to apologise for living well. :)
Exactly!

Exspect our invoices at the end of this month! :)

Re: Error on 'put "My text" into the selection' (Solved)

Posted: Thu Jun 20, 2019 2:03 pm
by mrcoollion
I only pay in beer :D so you are welcome to visit me in the Netherlands :wink:

Re: Error on 'put "My text" into the selection' (Solved)

Posted: Thu Jun 20, 2019 2:03 pm
by dunbarx
Hmmm.

I have a field and a button. The traversalOn of the button is set to "true". The script of the button is:

Code: Select all

  put "XXX" into the selection
I select a word in the field, and then click on the button. "XXX" appears in place of the selectedText

Craig

Re: Error on 'put "My text" into the selection' (Solved)

Posted: Thu Jun 20, 2019 4:42 pm
by FourthWorld
I don't believe I've ever seen that. Can you post that example stack?

Re: Error on 'put "My text" into the selection' (Solved)

Posted: Thu Jun 20, 2019 5:55 pm
by dunbarx
Glad the "Solved" appended to this thread did not close it. May I request of the OP that he remove that word?

Paul?

@ Richard.

All I did was create a new stack, adding a button and a field. I put a few words into the field, and this into the button script:

Code: Select all

on mouseUp
     put "XXX" into the selection
end mouseUp
I now select a word in the field, and click the button. Oh, and it matters not the state of traversalOn.

I can certainly post the stack, but there is nothing unusual about it. Are you saying that this does not happen for you?

Craig

Re: Error on 'put "My text" into the selection' (Solved)

Posted: Thu Jun 20, 2019 6:39 pm
by Klaus
Just tested with LC 9.04 on macOS 10.14.5, and yes traversalon or not, it works as advertized.
Looks like they have changed this in a former version, but this did definitively not work a long time ago.