NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: hmmueller on 2018-05-22 10:13 am

Title: Is there a way to get the current cursor position ("caret position") ...
Post by: hmmueller on 2018-05-22 10:13 am
... in a (Lua) user tool?

Thx for any enlightenment!

H.M.
Title: Re: Is there a way to get the current cursor position ("caret position") ...
Post by: Mike Shawaluk on 2018-05-22 10:41 am
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.
Title: Re: Is there a way to get the current cursor position ("caret position") ...
Post by: hmmueller on 2018-05-22 11:57 am
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.
Title: Re: Is there a way to get the current cursor position ("caret position") ...
Post by: Mike Shawaluk on 2018-05-22 12:25 pm
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 (https://noteworthycomposer.com/nwc2/usertools/). (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.
Title: Re: Is there a way to get the current cursor position ("caret position") ...
Post by: Rick G. on 2018-05-22 04:05 pm
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...'
Title: Re: Is there a way to get the current cursor position ("caret position") ...
Post by: hmmueller on 2018-05-22 08:07 pm
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.