Community
    • Login

    Scroll to a position

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 120 Views
    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.
    • Wim GielisW
      Wim Gielis
      last edited by Wim Gielis

      Hello,

      I have the script below, it is work in progress for a bigger script, but I am isolating where it does not work.
      In Notepad++ there are 2 identical tabs open. The first one is active.
      The script should take the caret position on the active tab, switch to the second tab, and move the cursor to the same caret position there.
      It all works except moving the cursor on the second tab. That is, the cursor is at the right position but the line is not visible on screen (scrolling does not take place).

      Can anyone look at this with me please ? Thanks in advance!

      EDIT: with initially the cursor on the first position of the second tab, even this line does not jump down:
      editor.setFirstVisibleLine(90)

      This seems strange to me.

      from Npp import *
      
      def get_cursor_position():
          position = editor.getCurrentPos()
          line = editor.lineFromPosition(position) + 1
          column = editor.getColumn(position)
          return (position, line, column)
      
      def set_cursor_position(position):
          editor.gotoPos(position)
      
      def switch_tab(tab_index):
          notepad.activateIndex(notepad.getCurrentView(), tab_index)
      
      # Get the cursor position on the active tab
      current_tab_index = notepad.getCurrentDocIndex(notepad.getCurrentView())
      cursor_position_info = get_cursor_position()
      console.write('\nFull position: ' + str(cursor_position_info))
      
      # Switch to the next tab
      switch_tab(current_tab_index + 1)
      
      # Set the cursor position on the other tab
      set_cursor_position(cursor_position_info[0])
      
      1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn
        last edited by

        Dunno. Your script worked for fine for me.

        Wim GielisW 1 Reply Last reply Reply Quote 0
        • Wim GielisW
          Wim Gielis @Alan Kilborn
          last edited by

          @Alan-Kilborn

          Thank you for the confirmation ! I will not spend more time on it.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors