mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
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).
This commit is contained in:
parent
ad56dafd62
commit
cfb819ee51
1 changed files with 10 additions and 3 deletions
|
|
@ -111,8 +111,6 @@ class SearchEngine:
|
||||||
If the search is allowed to wrap around, it will return the
|
If the search is allowed to wrap around, it will return the
|
||||||
original selection if (and only if) it is the only match.
|
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:
|
if not prog:
|
||||||
prog = self.getprog()
|
prog = self.getprog()
|
||||||
|
|
@ -137,6 +135,8 @@ class SearchEngine:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def search_forward(self, text, prog, line, col, wrap, ok=0):
|
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))
|
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
||||||
while chars:
|
while chars:
|
||||||
m = prog.search(chars[:-1], col)
|
m = prog.search(chars[:-1], col)
|
||||||
|
|
@ -144,28 +144,35 @@ class SearchEngine:
|
||||||
if ok or m.end() > col:
|
if ok or m.end() > col:
|
||||||
return line, m
|
return line, m
|
||||||
line = line + 1
|
line = line + 1
|
||||||
|
if wrapped and line > startline:
|
||||||
|
break
|
||||||
col = 0
|
col = 0
|
||||||
ok = 1
|
ok = 1
|
||||||
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
||||||
if not chars and wrap:
|
if not chars and wrap:
|
||||||
|
wrapped = 1
|
||||||
wrap = 0
|
wrap = 0
|
||||||
line = 1
|
line = 1
|
||||||
chars = text.get("1.0", "2.0")
|
chars = text.get("1.0", "2.0")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def search_backward(self, text, prog, line, col, wrap, ok=0):
|
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))
|
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
||||||
while 1:
|
while 1:
|
||||||
m = search_reverse(prog, chars[:-1], col)
|
m = search_reverse(prog, chars[:-1], col)
|
||||||
if m:
|
if m:
|
||||||
i, j = m.span()
|
|
||||||
if ok or m.start() < col:
|
if ok or m.start() < col:
|
||||||
return line, m
|
return line, m
|
||||||
line = line - 1
|
line = line - 1
|
||||||
|
if wrapped and line < startline:
|
||||||
|
break
|
||||||
ok = 1
|
ok = 1
|
||||||
if line <= 0:
|
if line <= 0:
|
||||||
if not wrap:
|
if not wrap:
|
||||||
break
|
break
|
||||||
|
wrapped = 1
|
||||||
wrap = 0
|
wrap = 0
|
||||||
pos = text.index("end-1c")
|
pos = text.index("end-1c")
|
||||||
line, col = map(int, string.split(pos, "."))
|
line, col = map(int, string.split(pos, "."))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue