Page 1 of 2

Get the screen position of the cursor

Posted: Sat Nov 27, 2021 1:46 pm
by banjaxd
Hi,

I'm returning to LC after a few years, (the Black Friday all deal was too good to miss) so I do have 'some' experience but I can't figure out how to do this..

I have a requirement to find the screen position of the flashing cursor inside of a multi-line field, so that I can pop open a sub menu at that location. For context, similar to an IDE, I'm hoping the field will recognise a pattern in the string, and pop open a relevant sub menu at location of the cursor.

I'm not sure I've explained that well enough? But I'd be grateful for any advice.

Thanks,
Banjaxd

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 1:50 pm
by Klaus
Hi Banjaxd,

welcome to the forum!
You are probably looking for -> the mouseloc
So you can:

Code: Select all

on mousedown
  popup btn "your popup menu here..." AT THE MOUSELOC
end mousedown
Best

Klaus

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 4:06 pm
by dunbarx
Hi.

But there is a big problem here. In an editable field, such messages as "mouseDown" and "mouseUp" are not sent.

If you hold down the commandKey, at least "mouseUp" is sent. But the current location of the mouseLoc will not be where the blinking cursor is, but rather where the mouse is. This will take just a little fooling around with, but I have to leave now. Klaus, do you se what I mean?

Craig

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 4:10 pm
by richmond62
The OP is looking for the screen position of the cursor

the mouseLoc will not suffice as a cursor can also be moved via the keyboard.

and NOT for the mouseLoc: these are different things completely.

https://stackoverflow.com/questions/289 ... -the-field

Unfortunately selectionChanged, as in:

Code: Select all

on selectionChanged
   put word 2 of the selectedChunk into fld "fOUTPUT"
end selectionChanged
is not, as far as I can see, going to be much use getting a location where something should appear.
-
SShot 2021-11-27 at 17.37.23.png

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 4:45 pm
by richmond62
Naively, perhaps, tried this:

Code: Select all

put the loc of word 2 of the selectedChunk
No joy.

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 5:42 pm
by jmburnod
Hi Richmond,

Code: Select all

put the selectedloc
is for you
Kind regards
Jean-Marc

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 5:56 pm
by richmond62
Super: just the ticket: Thanks. 8)

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 7:32 pm
by dunbarx
Yes, the selectedLoc. A powerful little gadget.

Here is a stack I made that should get you started. Simply place the cursor in the field and then click on the button.

It is up to you to populate the pullDown menuItems. I assume you will do this by getting the "currentWord of this card" (from the button script).
showPullDown.livecode.zip
(1.16 KiB) Downloaded 159 times
Craig

Re: Get the screen position of the cursor

Posted: Sat Nov 27, 2021 10:40 pm
by Klaus
Hi Craig,
dunbarx wrote:
Sat Nov 27, 2021 4:06 pm
But there is a big problem here. In an editable field, such messages as "mouseDown" and "mouseUp" are not sent.
FALSE and TRUE! :-)
"mouseup" is not sent to an editable field, but "mousedown" is in fact!
Otherwise one could not create an e.g. text formatting popup menu for the user.

Best

Klaus

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 1:27 am
by dunbarx
Klaus.
but "mousedown" is in fact!
No, the "mouseDown" message is not sent in an unlocked field. Never was. Unless you mean to use a right click (button 3?)

Craig

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 2:55 am
by Klaus
Of course I meant:

Code: Select all

on mousedown le_click
  if le_click = 3 then
   ##  right-click, do the popup
  end if
end mousedown
So... :D

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 3:36 am
by dunbarx
OK.

So,banjaxd, how did you intend that the user invoke the popup? Is right-click (or Command-click for button 1 with "mouseUp") acceptable? If so, you do not need the extra button. Its handler can go right into the field script.

And now about that blinking cursor...

Might you lock the field, which would allow the user to click directly on a word and bring the popup directly? To me, this seems like a much better interface. I do not know how the cursor is placed into the text as you originally described it, and you may have good reasons to need it to work that way. But a process that leaves a blinking cursor within a text field does not strike me as a good one as a means to find a target word. When I am looking at a large block of text, sometimes I have to work to find the cursor at all. Better to hilite a word in some way, and then click on it. You could even hilite each word as the cursor moves within the text, and then click on the one of interest.

That sounds like fun.

Craig

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 9:26 am
by banjaxd
Thank you to all who have contributed here - some. very interesting points.

@Craig - I feel we're getting close with your example - thank you.

To further explain, this simple application will be used for note taking, so, I will be typing into the field and I intend to use patterns as I type to replace or insert text. An example being "//t" would replace the patten with a date time stamp.
So the text might read " At //t, I met with the stakeholders and discussed..." in this instance, as I type the 't' in '//t' it would be replaced with "2021-11-28 08:18 ". All of this works really well. However, some symbols will have multiple options, where a date time stamp is an absolute, others have options for example, //p might be a 'Person' which should then open a context (sub) menu to select the right person. I've assumed that a good UX would be to open the menu at the cursor location - I could be wrong. But it's important that all of this should happen as I type.

The discussion here suggests using an MS Word, spelling error style, where the UI calls for the user to click on the word with the red underline, this of course get the mouse location. A neat and well known option, but IDE's like visual studio seem to do this really well and I wanted to replicate it to help my note taking.

Am I being unrealistic or are we close? I do really appreciate your feedback.
Thanks again. Banjaxd

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 4:44 pm
by dunbarx
There is no problem at all in making this happen in LiveCode. We just need the rules.

How you decide on the actual user experience is up to you.

Are you saying that, as you type, you will be entering such strings as "//t"? And will do this anticipating that a series of choices will present themselves at that point in the text stream? That is straightforward to put into place, but I could not remember to do that while typing...

Craig

Re: Get the screen position of the cursor

Posted: Sun Nov 28, 2021 5:18 pm
by richmond62
That is straightforward to put into place, but I could not remember to do that while typing...
Never mind, Richmond reinvented the wheel . . . 8)

Code in text field:

Code: Select all

on keyUp KUP
   put empty into fld "fOUTPUT"
   put the number of chars in fld "fINPUT" into CHARZ
   put char (CHARZ -2) of fld "fINPUT" after fld "fOUTPUT"
   put char (CHARZ -1) of fld "fINPUT" after fld "fOUTPUT"
   put char (CHARZ) of fld "fINPUT" after fld "fOUTPUT"
   put fld "fOUTPUT" into MAGIC
   if MAGIC contains "//t" then
      --- do some magic
   end if
end keyUp KUP
Of course, Richmond's obsession with bunging things in fields (so he can see them) can be circumvented very easily:

Code: Select all

on keyUp KUP
   put empty into MAGIC
   put the number of chars in fld "fINPUT" into CHARZ
   put char (CHARZ -2) of fld "fINPUT" after MAGIC
   put char (CHARZ -1) of fld "fINPUT" after MAGIC
   put char (CHARZ) of fld "fINPUT" after MAGIC
   if MAGIC contains "//t" then
      --- do some magic
   end if
end keyUp KUP