• Login
Community
  • Login

Scroll to a position

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 112 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.
  • W
    Wim Gielis
    last edited by Wim Gielis Mar 1, 2025, 8:48 AM Mar 1, 2025, 8:36 AM

    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
    • A
      Alan Kilborn
      last edited by Mar 1, 2025, 11:18 AM

      Dunno. Your script worked for fine for me.

      W 1 Reply Last reply Mar 1, 2025, 12:23 PM Reply Quote 0
      • W
        Wim Gielis @Alan Kilborn
        last edited by Mar 1, 2025, 12:23 PM

        @Alan-Kilborn

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

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