get the selectedChunk

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

get the selectedChunk

Postby Till Bandi » Mon Apr 17, 2017 5:03 pm

I would like to get the selectedChunk from a palette.
If I put the button on the same card as the field then the handler
on mouseUp
answer the selectedChunk
end mouseUp
works.
If I do the same thing with a button on a palette then I get an empty answer. Though with
on mouseUp
select before fld "AAA" of stack "xyxy"
answer the selectedChunk
end mouseUp
the answer is correct.

Is there a way to get the position of the cursor/selection from a palette?

Till

EDIT:
OP: MacOS Sierra, 10.12.4
LC Version is 9.0.0-dp-6
Till Bandi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 10
Joined: Sun Apr 16, 2006 4:52 am

Re: get the selectedChunk

Postby Klaus » Mon Apr 17, 2017 6:00 pm

Hi Till,

maybe setting the defaultstack first will do?
Code: Select all
...
set the defaultstack to "xyz"
answer the selectedchunk
...

I think your second script does exactly this, so it works.


Best

Klaus
Klaus
 
Posts: 9173
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: get the selectedChunk

Postby dunbarx » Mon Apr 17, 2017 6:01 pm

Hi.

Should work just fine. as simply as you wrote it.

A palette floats above other stacks, but "sees" those stacks as if it was part of them. You could even have two stacks, either with text selected, and a palette stack, (even if a substack of one of them) would still return the chunk requested. Assuming you had two stacks named "untitled 1" and "untitled 2", each with a field with some random text in it, in a button script on the palette:

Code: Select all
on mouseUp
   select word 1 of fld 1 of stack ("untitled" && random(2))
   answer the selectedChunk
end mouseUp


So tell us exactly how you constructed your stack and palette.

Craig Newman
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 4596
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: get the selectedChunk

Postby Till Bandi » Wed Apr 19, 2017 9:48 pm

I guess I was not able to explain my problem
The Script I put here

on mouseUp
select before word 1 of fld 1 of stack xyxy
answer the selectedChunk
end mouseUp

means, that I have to know where the cursor is. But that is not the case. I would like to push the button on the palette (it could also be on a normal stack) and would like to get the answer where the cursor is (which line of which field of which stack – but the answer is empty). With this information I would like to change for instance the list indent.

If I select a word in that field then the handler in the palette

on mouseUp
answer the selectedChunk
end mouseUp

will give me the information I am looking for → char 16 to 18 of fld 1. The cursor blinking in a field seems to not be the same as a selected word when I call it with the selectedChunk.

Is there any other was how I can get the information I am looking for?

Thanks, Till
Till Bandi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 10
Joined: Sun Apr 16, 2006 4:52 am

Re: get the selectedChunk

Postby FourthWorld » Wed Apr 19, 2017 10:58 pm

Till Bandi wrote:I guess I was not able to explain my problem
The Script I put here

on mouseUp
select before word 1 of fld 1 of stack xyxy
answer the selectedChunk
end mouseUp

means, that I have to know where the cursor is. But that is not the case. I would like to push the button on the palette (it could also be on a normal stack) and would like to get the answer where the cursor is (which line of which field of which stack – but the answer is empty). With this information I would like to change for instance the list indent.

If I select a word in that field then the handler in the palette

on mouseUp
answer the selectedChunk
end mouseUp

will give me the information I am looking for → char 16 to 18 of fld 1. The cursor blinking in a field seems to not be the same as a selected word when I call it with the selectedChunk.

Is there any other was how I can get the information I am looking for?

What value do you see returned from "the selectedChunk" when the cursor is inserted into the field but no words are selected?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 5087
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: get the selectedChunk

Postby Klaus » Wed Apr 19, 2017 11:07 pm

Hi richard,

as he wrote earlier: EMPTY!

Just made a quick test with a toplevel stack with a field and a plalette stack with the button "put the selectedchunk":
1. Selected a word in the field -> char 1 to 5 of fld 1
2. NOTHING selected, but cursor in the field -> EMPTY/NADA/NOTHING

I think this is correct behavior since in 2. the field simply loses focus so there is no selectedchunk anymore!
However the selection/selected word as in 1. STAYS of course selected even if the field loses focus.


Best

Klaus
Klaus
 
Posts: 9173
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: get the selectedChunk

Postby FourthWorld » Wed Apr 19, 2017 11:41 pm

Klaus, I always enjoy your exclamation marks, but what he wrote was:
on mouseUp
select before word 1 of fld 1 of stack xyxy
answer the selectedChunk
end mouseUp

That script should be impervious to any triggering action initially losing focus, because of course it re-establishes focus in the first statement.

That was what prompted me to write. As originally written, I'm unable to reproduce that. Seemed worth double-checking, since that's the sort of thing others would likely have seen as well, so it seems unlikely to have survived testing.

If the other script that doesn't explicitly set the selection is losing focus, then don't do that: set the button's traversalOn property to false and clicking it should no longer affect focus anywhere else.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 5087
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: get the selectedChunk

Postby Till Bandi » Thu Apr 20, 2017 8:40 am

the traversalOn was already off when I originally asked my question. I tried now again with the traversalOn true and false, there is no difference, both give me an empty result.

Till
Till Bandi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 10
Joined: Sun Apr 16, 2006 4:52 am

Re: get the selectedChunk

Postby Klaus » Thu Apr 20, 2017 10:28 am

Hi Richard,
FourthWorld wrote:Klaus, I always enjoy your exclamation marks, but what he wrote was:
on mouseUp
select before word 1 of fld 1 of stack xyxy
answer the selectedChunk
end mouseUp

...

yes, and in the next line after that script he wrote:
...
would like to get the answer where the cursor is (which line of which field of which stack – but the answer is empty)
...
Same result in my test!!! and !!! :D


Best

Klaus
Klaus
 
Posts: 9173
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: get the selectedChunk

Postby FourthWorld » Thu Apr 20, 2017 3:45 pm

Klaus wrote:yes, and in the next line after that script he wrote:
...
would like to get the answer where the cursor is (which line of which field of which stack – but the answer is empty)

I saw that, which is why I replied. If it was working there would be no need to investigate this further.

The question at hand is: why is it not working?

Same result in my test!!!

Curious indeed. Here the script works as expected, and while I'm likely using a different OS (Ubuntu here), the logic of the statements should yield success.

So this would appear to be a platform-specific bug, no?

Did I miss where the OP noted his OS and LC versions? Those may be useful to help pin this down.

and !!! :D

Thank you!!!!!!! :)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 5087
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: get the selectedChunk

Postby Klaus » Thu Apr 20, 2017 4:40 pm

Hi Richard,

FourthWorld wrote:So this would appear to be a platform-specific bug, no?

yep, looks like that.
Did I miss where the OP noted his OS and LC versions?

No, Till didn't mention it.
FourthWorld wrote:
and !!! :D

Thank you!!!!!!! :)

Good boy! :D


Best

Klaus
Klaus
 
Posts: 9173
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: get the selectedChunk

Postby Till Bandi » Fri Apr 21, 2017 9:36 am

OP: MacOS Sierra, 10.12.4
LC Version is 9.0.0-dp-6

(but I had this problem already in earlier versions).

I am not so familiar with Emojis: What means in this context "and !!! :D" ?
Till Bandi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 10
Joined: Sun Apr 16, 2006 4:52 am

Re: get the selectedChunk

Postby Klaus » Fri Apr 21, 2017 9:41 am

Hi Till,

that was just a personal joke by teasing Richard a bit:
FourthWorld wrote:Klaus, I always enjoy your exclamation marks, but...

Klaus wrote:...Same result in my test!!! and !!! :D

Get it?


Best

Klaus
Klaus
 
Posts: 9173
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: get the selectedChunk

Postby dunbarx » Sat Apr 22, 2017 12:34 am

The emoji :D is used when one makes a point, possibly quite pointedly, but also wants to communicate that there is no (or very little) impatience, frustration or admonition involved.

To do any of the above, though still without rancor, one would use either :roll: or 8) .

For rancor, :evil:

For worse yet: What the $^#%^$^%%...

Craig Newman
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 4596
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: get the selectedChunk

Postby Till Bandi » Sun Apr 23, 2017 11:49 am

>> Get it?
>>The emoji :D is used when one makes a point, ...

yes and thanks

But there seems not to be a solution to my question how I can get the location of the cursor (Stack, card, field) with the selectedChink from a palette? Is there any other way to get this information?
Till Bandi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 10
Joined: Sun Apr 16, 2006 4:52 am

Next

Return to Talking LiveCode

Who is online

Users browsing this forum: No registered users and 3 guests