Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Automatically scrolling to caret

    Help wanted · · · – – – · · ·
    3
    6
    194
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Tamarindo94
      Tamarindo94 last edited by

      Is there a way to set a shortut that automatically scrolls the current file so that the line displayed at the top is the one where the caret is currently placed? I know that SCI_SCROLLCARET can be configured in the shortcut mapper, but it only works if the caret is currently out of view.

      Thanks in advance :)

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Tamarindo94 last edited by

        @tamarindo94

        I don’t know about other methods, but I tried the following bit of script code using the PythonScript plugin, and it seems to work to do the desired thing:

        editor.setFirstVisibleLine(editor.lineFromPosition(editor.getCurrentPos()))

        Tamarindo94 1 Reply Last reply Reply Quote 3
        • Tamarindo94
          Tamarindo94 @Alan Kilborn last edited by

          @alan-kilborn
          Thanks a lot for your reply! I tried what you suggested and it does indeed work under normal circumstances. However, when word wrap is enabled and I’m working with wrapped lines, the behavior of the script becomes rather unpredictable (to me, at least): under those conditions, it doesn’t actually scroll to the caret, but rather to a position a few lines before it.
          I suppose this is due to the fact that the actual position of the lines is altered by word wrap, but I have no idea how to solve the problem. Do you?

          Michael Vincent 1 Reply Last reply Reply Quote 0
          • Michael Vincent
            Michael Vincent @Tamarindo94 last edited by

            @tamarindo94 said in Automatically scrolling to caret:

            However, when word wrap is enabled and I’m working with wrapped lines, the behavior of the script becomes rather unpredictable (to me, at least): under those conditions, it doesn’t actually scroll to the caret, but rather to a position a few lines before it.
            I suppose this is due to the fact that the actual position of the lines is altered by word wrap, but I have no idea how to solve the problem. Do you?

            Maybe you need to include “Scintilla ensure visible commands”?

            Cheers.

            Alan Kilborn 1 Reply Last reply Reply Quote 0
            • Alan Kilborn
              Alan Kilborn @Michael Vincent last edited by Alan Kilborn

              I did some experiments with Word Wrap enabled and confirmed the finding of @Tamarindo94. In every case in my experiments, the line of the caret remained visible in the viewport, just not necessarily as the first line of the viewport, as one would be led to believe from the setFirstVisibleLine function call.

              Unfortunately, I don’t really see a way to fix the bad behavior. There are other problems/complaints with functionality of Notepad++ with Word Wrap enabled, maybe this is just one more. :-(

              1 Reply Last reply Reply Quote 1
              • Alan Kilborn
                Alan Kilborn last edited by

                Actually, this seems to do it:

                editor.setFirstVisibleLine(editor.visibleFromDocLine(editor.lineFromPosition(editor.getCurrentPos())))

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors