Skip to main content
Topic: Is there a way to get the current cursor position ("caret position") ... (Read 4415 times) previous topic - next topic

Is there a way to get the current cursor position ("caret position") ...

... in a (Lua) user tool?

Thx for any enlightenment!

H.M.

Re: Is there a way to get the current cursor position ("caret position") ...

Reply #1
If you save a song in NWCTXT format, you will see something like the following as the second line:
Code: (nwc) [Select · Download]
|Editor|ActiveStaff:1|CaretIndex:5|SelectIndex:7|CaretPos:0
CaretIndex holds the cursor position when the file was saved. If there was an active selection, SelectIndex will hold that. I haven't figured out what CaretPos indicates.

I haven't verified this, but I would assume that this information is available if you are using file mode in the user tool.

Re: Is there a way to get the current cursor position ("caret position") ...

Reply #2
I'd say CaretPos is how "high" the cursor is (like any other Pos) (whereas CaretIndex is its "x coordinate"). Unfortunately, I'm in clip mode for my user tool; and I would need the current cursor position - not the last saved one - anyway. Well, then this will be a option box ...

Thx.
H.M.

Re: Is there a way to get the current cursor position ("caret position") ...

Reply #3
You are of course correct about CaretPos - it is in fact the vertical position on the staff.

I indicated a saved nwctxt file just as an example, but those values are also dynamically sent to a user tool. I would suggest running the "nwctxt File Explorer" user tool, which is installed as part of the NWC2 User Tool Starter Kit. (You can find it under the .Developer Tools group). This is a handy tool for browsing the structure of a score from a user tool's perspective.

I seem to recall that it is possible for a clip text user tool to also access the score's file text, but I can't think of any examples off the top of my head. Hopefully one of the other user tool authors can provide an example.

 

Re: Is there a way to get the current cursor position ("caret position") ...

Reply #4
I'm in clip mode for my user tool;
The cursor position is not available in Clip Mode. You would need to change your User Tool to use File Mode.

In File Mode, the '|Editor|...' info is for the the current view. It is possible to parse the '#/File:..' tag for the source file, if one exists.
This will not work for files opened via 'Open Sample...'
Registered user since 1996

Re: Is there a way to get the current cursor position ("caret position") ...

Reply #5
Thanks. I found that an additional prompt for the position is not really a problem, as pressing <enter> (for the default) or 12<enter> (for value 12) is practically as short as it gets ... So, I am happy, and have learned something.

H.M.