PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

notepad.activateFile() doesn't work (sometimes) on "new _" files

Open sasumner opened this issue 7 years ago • 4 comments

N++ v7.5.8 x64 PS 1.2.0.0

It is observed that notepad.activateFile() sometimes seems to ignore the request when its argument is an unsaved file, e.g. "new 1", "new 2", etc.

This video (https://imgur.com/CfNdDnP) shows that I have 4 such files open, 1,3,4 and 5, but that "new 1" can't be switched to using notepad.activateFile('new 1'). The video shows that 'new 4' and 'new 5' can be switched to. No problem for 'new 3' either (but that is not in the video).

sasumner avatar Sep 14 '18 14:09 sasumner

@chcg Any interest in looking at this one?

sasumner avatar Jan 11 '19 14:01 sasumner

I just encountered this bug while creating a script for this inquiry: https://community.notepad-plus-plus.org/topic/24647/how-to-save-1000-fills-at-once

When using PS 2.0, notepad.activateFile('new 1') would not work, but when used with new 2, new 3, etc. it would work.

When trying with PS 3.0.16, notepad.activateFile() on ANY "new X" file did NOT work.

alankilborn avatar Jul 01 '23 12:07 alankilborn

When I am in a state where notepad.activateFile is not working to switch to new 1 in Python Script, if I switch to NppExec console and use npp_sendmsg NPPM_SWITCHTOFILE 0 "new 1", it switches just fine. So it appears that activateFile isn't always sending the right NPPM_SWITCHTOFILE message , because the message itself is working fine

pryrt avatar Jul 01 '23 19:07 pryrt

Over a year of inactivity. Time to present the obvious workaround, I guess:

def notepad_activateFile(f):
    # note: we can't simply use notepad.activateFile() because of this PS bug:  https://github.com/bruderstein/PythonScript/issues/105
    for (pathname, buffer_id, index, view) in notepad.getFiles():
        if pathname == f:
            notepad.activateIndex(view, index)
            break

alankilborn avatar Aug 02 '24 14:08 alankilborn