Skip to content

Poor handling of endPosition value of zero in editor.research() #248

@alankilborn

Description

@alankilborn

Using PS 2.0, consider the following code:

# -*- coding: utf-8 -*-
from __future__ import print_function

from Npp import *
import re

matches = []
editor.research(r'.', lambda m: matches.append(m.span(0)), re.I, 0, 0)
print(len(matches))

I was surprised to see that the length of the matches list was non-zero when run on any file with content.

It seems the problem comes from running with endPosition equal to zero.
This apparently is used as a "special signal" to the receiving code that the effective endPosition should be the position of the last character in the document.

So of course I don't call editor.research in real code like I show above. That's just for illustration. My real code looked more like this:

 editor.research(r'.', lambda m: matches.append(m.span(0)), re.I, 0, editor.positionFromLine(editor.lineFromPosition(editor.getCurrentPos())))

and that will cause a failure when run with the caret on user line 1 of a file with content, because my intent is "no matches" in this case.

This is similar to the desire expressed by another user in #172, but that other user was nice as I'd call 172 a bug, just like I call this current issue a bug. :-)

As it is, I have to do extra error trapping to work around this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions