Page 1 of 2
get the selectedChunk
Posted: Mon Apr 17, 2017 5:03 pm
by Till Bandi
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
Re: get the selectedChunk
Posted: Mon Apr 17, 2017 6:00 pm
by Klaus
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
Re: get the selectedChunk
Posted: Mon Apr 17, 2017 6:01 pm
by dunbarx
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
Re: get the selectedChunk
Posted: Wed Apr 19, 2017 9:48 pm
by Till Bandi
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
Re: get the selectedChunk
Posted: Wed Apr 19, 2017 10:58 pm
by FourthWorld
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?
Re: get the selectedChunk
Posted: Wed Apr 19, 2017 11:07 pm
by Klaus
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
Re: get the selectedChunk
Posted: Wed Apr 19, 2017 11:41 pm
by FourthWorld
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.
Re: get the selectedChunk
Posted: Thu Apr 20, 2017 8:40 am
by Till Bandi
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
Re: get the selectedChunk
Posted: Thu Apr 20, 2017 10:28 am
by Klaus
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 !!!
Best
Klaus
Re: get the selectedChunk
Posted: Thu Apr 20, 2017 3:45 pm
by FourthWorld
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 !!!
Thank you!!!!!!!

Re: get the selectedChunk
Posted: Thu Apr 20, 2017 4:40 pm
by Klaus
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 !!!
Thank you!!!!!!!

Good boy!
Best
Klaus
Re: get the selectedChunk
Posted: Fri Apr 21, 2017 9:36 am
by Till Bandi
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 !!!

" ?
Re: get the selectedChunk
Posted: Fri Apr 21, 2017 9:41 am
by Klaus
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 !!!
Get it?
Best
Klaus
Re: get the selectedChunk
Posted: Sat Apr 22, 2017 12:34 am
by dunbarx
The emoji

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

or

.
For rancor,
For worse yet:
What the $^#%^$^%%...
Craig Newman
Re: get the selectedChunk
Posted: Sun Apr 23, 2017 11:49 am
by Till Bandi
>> Get it?
>>The emoji

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?