Loading ...
Sorry, an error occurred while loading the content.

Where is the cursor?

Expand Messages
  • dandiebolt@yahoo.com
    I have an clip where I need to precisely position the cursor in the middle of the inserted text. While executing my clip, how do I determine where the cursor
    Message 1 of 12 , Mar 3 10:56 AM
    • 0 Attachment
      I have an clip where I need to precisely position the
      cursor in the middle of the inserted text. While executing
      my clip, how do I determine where the cursor currently is?
      The following clip inserts two lines of numbers but reports
      the cursor positions a r=1,c=1 ; r=1,c=1 ; r=2,c=11
      instead of what I would expect: r=1,c=1 ; r=2,c=11; r=2,c=11.

      H="Where is the Cursor?"
      ^!Info row=^$GetRow$,col=^$GetCol$
      1234567890
      1234567890
      ^!Info row=^$GetRow$,col=^$GetCol$
      ^!Info row=^$GetRow$,col=^$GetCol$

      This clip executed from a blank document.

      Anyone know how to determine the current cursor location,
      even if the clip is not through executing?

      Thanks in advance.
    • Alan C.
      Hi, ... Either of the two commented, ie remove the ; from the beginning of the line to try it. H= Where is the Cursor? ^!Info row=^$GetRow$,col=^$GetCol$
      Message 2 of 12 , Mar 3 7:36 PM
      • 0 Attachment
        Hi,

        >The following clip inserts two lines of numbers but reports
        >the cursor positions a r=1,c=1 ; r=1,c=1 ; r=2,c=11
        >instead of what I would expect: r=1,c=1 ; r=2,c=11; r=2,c=11.
        >
        >H="Where is the Cursor?"
        >^!Info row=^$GetRow$,col=^$GetCol$
        >1234567890
        >1234567890
        >^!Info row=^$GetRow$,col=^$GetCol$
        >^!Info row=^$GetRow$,col=^$GetCol$
        >
        >This clip executed from a blank document.
        >
        >Anyone know how to determine the current cursor location,
        >even if the clip is not through executing?

        Either of the two commented, ie remove the ; from the beginning of the line to try it.

        H="Where is the Cursor?"
        ^!Info row=^$GetRow$,col=^$GetCol$
        1234567890
        1234567890
        ;^!Jump SELECT_END
        ;^!Delay 3
        ^!Info row=^$GetRow$,col=^$GetCol$
        ^!Info row=^$GetRow$,col=^$GetCol$

        Probably the delay is the better of the two to use. Sometimes things just go so fast that other parts are not yet caught up, a delay insures to retain sequence. It worked for me.

        it sounds like you would next then want to move the cursor back to the middle of the inserted text. there are ways to do that too.

        Clever on the Walking the list. Thanks for sharing it.

        BTW sometimes instead of

        :loop
        ^%i%) ^%List^%i%%

        sometimes, not always, need the inserttext too

        :loop
        ^!InsertText ^%i%) ^%List^%i%%

        bye. Alan.
      • Jody
        Hi Dandie and Alan, ... NoteTab s cursor position is always at the beginning of the selection as far as the row:col coordinates go *when text is selected*
        Message 3 of 12 , Mar 3 8:43 PM
        • 0 Attachment
          Hi Dandie and Alan,

          >I have an clip where I need to precisely position the cursor in
          >the middle of the inserted text. While executing my clip, how do
          >I determine where the cursor currently is?

          NoteTab's cursor position is always at the beginning of the
          selection as far as the row:col coordinates go *when text is
          selected* regardless of where the cursor actually is. Otherwise,
          it is where the cursor actually is. That is true for all flavors
          of NoteTab.

          >H="Where is the Cursor?"
          >1234567890
          >1234567890
          >^!Info row=^$GetRow$,col=^$GetCol$
          >^!Info row=^$GetRow$,col=^$GetCol$

          Alan gave you correct information about a delay needed, but
          better to just use Jump Select_End *if* you can get away with it
          (depending on your Clip). NoteTab is to fast for its own
          britches at times so a delay is needed. You will find a delay is
          needed in other situations as well, but there are other ways to
          write the script to be more accurate so you always have the right
          timing.

          In your case above if you wanted to be "exact" and not do a jump,
          you could do something like the following. Of course this is
          just as an example when you know a given point. A lot of times
          you will know that or perhaps an application Titlebar name that
          you are checking to see when it is focused so the idea is to loop
          in some manner until you see what you are looking for before
          continuing on with the script.

          H=Where is the Cursor?
          1234567890
          1234567890
          :Loop
          ^!IfSame "2:11" "^$GetRowEnd$:^$GetColEnd$" Next else Loop
          ^!Info row=^$GetRow$:^$GetCol$

          >Anyone know how to determine the current cursor location,
          >even if the clip is not through executing?

          Here are the row:col functions we have available:

          ^$GetCol$
          Returns column index of cursor in current document.

          ^$GetColEnd$
          Returns the cursor column index in the current document. If some
          text is selected, then the end of the selection determines the
          column position.

          ^$GetColLeft$
          Returns the leftmost column index visible in current document
          window.

          ^$GetColScreen$ (added in v4.6)

          Returns the actual column position on the screen. Unlike
          ^$GetCol$, this function takes into account expanded tabs. This
          function is only meaningful in NoteTab Pro; NoteTab Light/Std
          return the same result as the ^$GetCol$ function.

          ^$GetColStart$
          Returns the cursor column index in the current document. If some
          text is selected, then the beginning of the selection determines
          the column position.

          ^$GetRow$
          Returns line index of cursor in current document.

          ^$GetRowEnd$
          Returns the cursor line index the in current document. If some
          text is selected, then the end of the selection determines the
          line index.

          ^$GetRowStart$
          Returns the cursor line index in the current document. If some
          text is selected, then the beginning of the selection determines
          the line index.

          ^$GetRowTop$
          Returns the index of the top line visible in current document
          window.

          Happy Clip'n!
          Jody

          http://www.notetab.net

          Subscribe, UnSubscribe, Options
          mailto:Ntb-Clips-Subscribe@yahoogroups.com
          mailto:Ntb-Clips-UnSubscribe@yahoogroups.com
          http://www.egroups.com/group/ntb-clips
        • dandiebolt@yahoo.com
          Thanks for the LINE_END tip. I am generating some XML related clips and after inserting the markup, I want to position the cursor in the middle at the proper
          Message 4 of 12 , Mar 3 11:59 PM
          • 0 Attachment
            Thanks for the LINE_END tip. I am generating some XML
            related clips and after inserting the markup, I want to
            position the cursor in the middle at the proper level
            of indention. The enclosed clips demonstrate the general
            indention technique it looks like I will be using. The
            actual clips for my application will be substantially
            more complex, but I want to iron out some formatting
            and style techniques first. I am running with AutoIndent
            on, avoiding using tabs and wand an indention level of
            four spaces. I would appreciate some input on the technique
            and alternatives as I will be creating many clips.

            H="Tag1 Indent"
            ^!Set Indent=" "
            ^!Set tag=^?[Enter Tag]
            <^%tag%>
            ^%Indent%
            </^%tag%>
            ^!Jump -1
            ^!Jump LINE_END

            H="Tag2 Indent"
            ^!Set Indent=" "
            ^!Set tag1=^?[Enter Tag1]
            ^!Set tag2=^?[Enter Tag2]
            <^%tag1%>
            ^%Indent%<^%tag2%>
            ^%Indent%^%Indent%
            ^%Indent%</^%tag2%>
            </^%tag1%>
            ^!Jump -2
            ^!Jump LINE_END
          • Eb Guenther
            ... The following solution does not place your cursor into the indentation, but manages the closing tags instead. The closing tag never has any arguments, so
            Message 5 of 12 , Mar 4 1:32 PM
            • 0 Attachment
              dandiebolt@... wrote:

              >I am generating some XML related clips and after
              >inserting the markup, I want to position the cursor
              >in the middle at the proper level of indention.

              The following solution does not place your cursor into the
              indentation, but manages the closing tags instead.

              The closing tag never has any arguments, so you can auto-generate
              the closing tag easily. Push the tag name (i.e. <tag ...>) onto
              a stack (array), and when your code reaches the end of the inserted
              code (including nested tags), pop the closing tag[s] off the stack
              into their angle brackets.

              For Example (for tag "<tag ...>"):

              ^!SetArray %stack%=</xtml>
              ^!InsertText <tag ...>
              ^!Set %stack%=^%Stack%;tag
              ;insert content here, including subordinated tags,
              ;push subordinated closing tags onto stack as well.
              :loop
              ;pop the closing tags off the stack in proper order
              ^!InsertText </^%stack^%stack0%%>
              ;where ^%stack0% is the count of array elements, hence TOP of Stack
              ^!Dec %stack0%
              ^!If ^%stack0%>1 loop
              ;loop through the stack until no more tags, or sequence by
              ;other means. The stack will always keep track of the order
              ;of your closing tags.

              One caveat: you'll have to devise a way to keep from pushing empty
              tags, like <br /> onto the stack. Unless you don't mind cluttering
              your code with strange tags like </br> along the way.


              Cheers,

              Eb
            • Jody
              Hi Eb and dandiebolt, ... prerelease for Pro), but there are HTML to XTHML functions and also off the main menu. (There is a bug in v4.84 which is fixed in
              Message 6 of 12 , Mar 5 9:02 AM
              • 0 Attachment
                Hi Eb and dandiebolt,

                >One caveat: you'll have to devise a way to keep from pushing empty
                >tags, like <br /> onto the stack. Unless you don't mind cluttering
                >your code with strange tags like </br> along the way.

                :-) You cannot do it until v4.85 is released (or get the
                prerelease for Pro), but there are HTML to XTHML functions and
                also off the main menu. (There is a bug in v4.84 which is fixed
                in v4.85).

                You might also look into ^!SetPasteIndent Off which might be
                causing you a problem since I noticed you had it on. Sometimes,
                as mentioned, a delay is needed.


                Happy Clip'n!
                Jody

                http://www.notetab.net

                Subscribe, UnSubscribe, Options
                mailto:Ntb-Clips-Subscribe@yahoogroups.com
                mailto:Ntb-Clips-UnSubscribe@yahoogroups.com
                http://www.egroups.com/group/ntb-clips
              • Don Passenger
                When I use tag out of the html clip library it always returns all the way to the left margin after inserting the tag, instead of maintaining the indent.
                Message 7 of 12 , Mar 5 9:59 AM
                • 0 Attachment
                  When I use <br> tag out of the html clip library it always returns all the
                  way to the left margin after inserting the tag, instead of maintaining the
                  indent. When I use the enter key it maintains the indent. Is this
                  something that has any relationship to that? Could it be the fix? I would
                  love to modify my <br> clip so it maintains the indent. Or better yet add
                  one that does and one that doesn't.

                  If I turn it on will it hold the indent?

                  > You might also look into ^!SetPasteIndent Off which might be
                  > causing you a problem since I noticed you had it on. Sometimes,
                  > as mentioned, a delay is needed
                • Andy Young
                  Hi, all, In my continued pursuit of string manipulations with NoteTab. I ve run across a question in using ^$StrPosRight( SubStr ; Str ;CaseSensitive)$
                  Message 8 of 12 , Mar 5 10:20 AM
                  • 0 Attachment
                    Hi, all,
                    In my continued pursuit of string manipulations with NoteTab. I've
                    run across a question in using
                    ^$StrPosRight("SubStr";"Str";CaseSensitive)$ According to the help
                    file it is "similar to the ^$StrPos()$ function but searches from
                    right to left."

                    I created a clip to discover how different string functions work.
                    However, I've not been able to get ^$StrPosRight()$ to work. Here is
                    the clip ...

                    ;clip begins, there are lots of long lines
                    H="String test clip"
                    ^!Info This clip tests some string manipulation techniques
                    ^!ClearVariables
                    ^!Set %teststring%=^?{What string do you wish to test?}
                    ^!Set %substring%=^?{What part of the string do you wish to use for
                    testing?}
                    ^!InsertText _^%teststring%_ is the string^%NL%
                    ^!Set %tstsiz%=^$StrSize("^%teststring%")$
                    ^!InsertText _^%tstsiz%_ is the number of characters in
                    _^%teststring%_^%NL%
                    ^!InsertText _^%substring%_ should be part of _^%teststring%_^%NL%
                    ^!Set %tst2siz%=^$StrSize("^%substring%")$
                    ^!InsertText _^%tst2siz%_ is the number of characters in
                    _^%substring%_^%NL%
                    ^!Set %tstpos%=^$StrPos("^%substring%";"^%teststring%";False)$
                    ^!InsertText Counting from left _^%substring%_ starts at the
                    _^%tstpos%_th character^%NL%
                    ^!Set
                    %tstrtpos%=^$StrPosRight("^%substring%";"^%teststring%";False)$
                    ^!InsertText Counting from right _^%substring%_ starts at the
                    _^%tstrtpos%_th character^%NL%
                    ^!Set %newstring%=^$StrCopy("^%teststring%";^%tstpos%;^%tst2siz%)$
                    ^!InsertText Using string copy position and size information the new
                    substring is _^%newstring%_^%NL%
                    ^!Set %delstring%=^$StrDelete("^%teststring%";^%tstpos%;^%tst2siz%)$
                    ^!InsertText Using string delete position and size information the
                    remaining string is _^%delstring%_^%NL%
                    ^!Set %adjpos%=^$Calc(^%tstpos%+^%tst2siz%-1)$
                    ^!Set %rtstring%=^$StrDeleteLeft("^%teststring%";^%adjpos%)$
                    ^!InsertText Deleting leftwise up to including _^%substring%_ from
                    _^%teststring%_ leaves a string _^%rtstring%_^%NL%
                    ^!ClearVariables
                    ;clip ends

                    For the long string I use "Andy seems bewildered" (no quotes)
                    and for the substring I use "see" (no quotes)

                    The clip gives the following results ...
                    _Andy seems bewildered_ is the string
                    _21_ is the number of characters in _Andy seems bewildered_
                    _see_ should be part of _Andy seems bewildered_
                    _3_ is the number of characters in _see_
                    Counting from left _see_ starts at the _6_th character
                    Counting from right _see_ starts at the _6_th character
                    Using string copy position and size information the new substring is
                    _see_
                    Using string delete position and size information the remaining
                    string is _Andy ms bewildered_
                    Deleting leftwise up to including _see_ from _Andy seems bewildered_
                    leaves a string _ms bewildered_

                    This line "Counting from right _see_ starts at the _6_th character"
                    should start at either 14 or 17 depending on the how it is counted.
                    Is there something I'm doing wrong with this function?
                    Any suggestions on how to get this ^$StrPosRight()$ to work?

                    Thanks,
                    Andy
                  • Jody
                    Hi Don, Try turning it on it the script and then turning it off at the end perhaps. I did not reference Help, but I think it will turn off automatically when
                    Message 9 of 12 , Mar 5 10:24 AM
                    • 0 Attachment
                      Hi Don,

                      Try turning it on it the script and then turning it off at the
                      end perhaps. I did not reference Help, but I think it will turn
                      off automatically when the script is through. You might have to
                      use ^$GetRow$:^$GetCol$ or one of the sister functions to do what
                      you want and then ^!SetCursor before pasting.

                      >When I use <br> tag out of the html clip library it always
                      >returns all the way to the left margin after inserting the tag,
                      >instead of maintaining the indent. When I use the enter key it
                      >maintains the indent. Is this something that has any
                      >relationship to that? Could it be the fix? I would love to
                      >modify my <br> clip so it maintains the indent. Or better yet
                      >add one that does and one that doesn't.
                      >
                      >If I turn it on will it hold the indent?
                      >
                      > > You might also look into ^!SetPasteIndent Off


                      Happy Clip'n!
                      Jody

                      http://www.notetab.net

                      Subscribe, UnSubscribe, Options
                      mailto:Ntb-Clips-Subscribe@yahoogroups.com
                      mailto:Ntb-Clips-UnSubscribe@yahoogroups.com
                      http://www.egroups.com/group/ntb-clips
                    • Alan C.
                      Hi Andy, ... H= strstuff ^!Goto ^?[(H=10)choose==StrPos^=next|StrPosRight^=skip_2] ^!Info ^$StrPos( efg ; zyxwabcdefghijkl ;True)$ ^!Goto end ^!Info
                      Message 10 of 12 , Mar 5 8:53 PM
                      • 0 Attachment
                        Hi Andy,

                        At 12:20 PM 3/5/01 -0600, you wrote:
                        >Hi, all,
                        >In my continued pursuit of string manipulations with NoteTab. I've
                        >run across a question in using
                        >^$StrPosRight("SubStr";"Str";CaseSensitive)$ According to the help
                        >file it is "similar to the ^$StrPos()$ function but searches from
                        >right to left."
                        <snip>

                        H="strstuff"
                        ^!Goto ^?[(H=10)choose==StrPos^=next|StrPosRight^=skip_2]
                        ^!Info ^$StrPos("efg";"zyxwabcdefghijkl";True)$
                        ^!Goto end
                        ^!Info ^$StrPosRight("efg";"zyabcdefghij";True)$
                        ;--<end of clip<<

                        When I used the above clip, both StrPos and StrPosRight indicate the correct index. However, I do notice that they both indicate the index as beginning the count of the index position from the left end of the string.

                        Perhaps they are both supposed to indicate the index as relative to the left hand end of the string. (I do not know how they are supposed to work)

                        But, as per help, a difference is that StrPosRight searches from right to left until it finds the string. It (either of the two functions) must find the sub string before it can indicate the index of the sub string.

                        All of the above brings up a new question for me:

                        Is StrPos and StrPosRight, are they both supposed to indicate the index of a substring, indicate it as being relative to the left end of the string?

                        Is the direction of search the only difference between those two functions?

                        Thanks. Regards. Alan.
                      • Jody
                        Hi Alan and Andy, Andy, do you have like a question specifically instead of a whole Clip to go through? ... Yes. ... Yes. H=Type in NoteTab and select it:
                        Message 11 of 12 , Mar 5 10:22 PM
                        • 0 Attachment
                          Hi Alan and Andy,

                          Andy, do you have like a question specifically instead of a whole
                          Clip to go through?

                          >Is StrPos and StrPosRight, are they both supposed to indicate the
                          >index of a substring, indicate it as being relative to the left
                          >end of the string?

                          Yes.

                          >Is the direction of search the only difference between those two
                          >functions?

                          Yes.

                          H=Type in NoteTab and select it:
                          ^!Set %str1%=^$StrPos("Tab";"^$GetSelection$";0)$
                          ^!Info ^%str1%
                          ^!Set %str2%=^$StrPosRight("Tab";"^$GetSelection$";0)$
                          ^!Info ^%str2%

                          Happy Clip'n!
                          Jody

                          http://www.notetab.net

                          Subscribe, UnSubscribe, Options
                          mailto:Ntb-Clips-Subscribe@yahoogroups.com
                          mailto:Ntb-Clips-UnSubscribe@yahoogroups.com
                          http://www.egroups.com/group/ntb-clips
                        • Andy Young
                          Hi, Jody & Allan Both of your remarks below answered my question. Thank you. I was trying to use ^$StrPos( SubStr ; Str ;CaseSensitive)$ to go with
                          Message 12 of 12 , Mar 6 6:06 AM
                          • 0 Attachment
                            Hi, Jody & Allan

                            Both of your remarks below answered my question. Thank you.
                            I was trying to use ^$StrPos("SubStr";"Str";CaseSensitive)$
                            to go with ^$StrDeleteLeft("Str";Amount)$ Which worked in
                            the example clip as long as I adjusted the number by 1

                            But I couldn't do the same thing with
                            ^$StrPosRight("SubStr";"Str";CaseSensitive)$ and
                            ^$StrDeleteRight("Str";Amount)$
                            I was trying to work with a string so that I can delete
                            everything from right or the left of a substring. I had assumed
                            that $StrPosRight()$ would help me with $StrDeleteRight()$
                            of which I now know I was mistaken.

                            The difference between the two ^$StrPos()$ and ^$StrPosRight()$
                            is only useful if you have multiple occurences of the the same
                            item in a string. ^$StrPos()$ would reference the left-most one
                            and ^$StrPosRight()$ would return a value for the right-most
                            one.

                            Thank you, Andy

                            > Andy, do you have like a question specifically instead of a
                            > whole Clip to go through?
                            >
                            > > Is StrPos and StrPosRight, are they both supposed to indicate
                            > > the index of a substring, indicate it as being relative to the
                            > > left end of the string?
                            >
                            > Yes.
                            >
                            > >Is the direction of search the only difference between those two
                            > >functions?
                            >
                            > Yes.
                            >
                          Your message has been successfully submitted and would be delivered to recipients shortly.