diff options
author | Guido van Rossum <guido@python.org> | 1999-04-20 15:00:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-04-20 15:00:00 (GMT) |
commit | cfb819ee5168dd2d5c9c1bd237d8ac7d0e2278e2 (patch) | |
tree | 3951db9eae552fd5330237b097c161642c2237c7 /Tools | |
parent | ad56dafd62baf60d6be28481154d1a69bb966ca3 (diff) | |
download | cpython-cfb819ee5168dd2d5c9c1bd237d8ac7d0e2278e2.zip cpython-cfb819ee5168dd2d5c9c1bd237d8ac7d0e2278e2.tar.gz cpython-cfb819ee5168dd2d5c9c1bd237d8ac7d0e2278e2.tar.bz2 |
Patch by Mark Favas: it fixes the search engine behaviour where an
unsuccessful search wraps around and re-searches that part of the file
between the start of the search and the end of the file - only really
an issue for very large files, but... (also removes a redundant
m.span() call).
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/idle/SearchEngine.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Tools/idle/SearchEngine.py b/Tools/idle/SearchEngine.py index d9361d0..e379751 100644 --- a/Tools/idle/SearchEngine.py +++ b/Tools/idle/SearchEngine.py @@ -111,8 +111,6 @@ class SearchEngine: If the search is allowed to wrap around, it will return the original selection if (and only if) it is the only match. - XXX When wrapping around and failing to find anything, the - portion of the text after the selection is searched twice :-( """ if not prog: prog = self.getprog() @@ -137,6 +135,8 @@ class SearchEngine: return res def search_forward(self, text, prog, line, col, wrap, ok=0): + wrapped = 0 + startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) while chars: m = prog.search(chars[:-1], col) @@ -144,28 +144,35 @@ class SearchEngine: if ok or m.end() > col: return line, m line = line + 1 + if wrapped and line > startline: + break col = 0 ok = 1 chars = text.get("%d.0" % line, "%d.0" % (line+1)) if not chars and wrap: + wrapped = 1 wrap = 0 line = 1 chars = text.get("1.0", "2.0") return None def search_backward(self, text, prog, line, col, wrap, ok=0): + wrapped = 0 + startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) while 1: m = search_reverse(prog, chars[:-1], col) if m: - i, j = m.span() if ok or m.start() < col: return line, m line = line - 1 + if wrapped and line < startline: + break ok = 1 if line <= 0: if not wrap: break + wrapped = 1 wrap = 0 pos = text.index("end-1c") line, col = map(int, string.split(pos, ".")) |