From 6e961d7a61cd53232e0421f2ee5e981bbe1f8599 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 4 May 2008 00:21:17 +0000 Subject: [PATCH] maybe fixed the search-as-you-type bugs!!! --HG-- branch : pmacs2 --- searchutil.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/searchutil.py b/searchutil.py index 1582439..09be40f 100644 --- a/searchutil.py +++ b/searchutil.py @@ -3,9 +3,9 @@ import regex from point import Point from render import HighlightRegion -bg_color = 'black' -selected_color = 'magenta' -unselected_color = 'yellow' +BG = 'black' +SELECTED = 'magenta' +UNSELECTED = 'yellow' class IllegalPatternError(Exception): pass @@ -35,7 +35,9 @@ def find_ranges(r, w, start=None, end=None): for m in r.finditer(w.buffer.lines[y], x, limit): if len(m.group(0)) == 0: raise IllegalPatternError, "zero-width match found" - ranges.append([Point(m.start(), y), Point(m.end(), y), bg_color, unselected_color, m]) + p1, p2 = Point(m.start(), y), Point(m.end(), y) + hr = HighlightRegion(w, p1, p2, BG, UNSELECTED, match=m, name='search') + ranges.append(hr) x = 0 y += 1 return ranges @@ -64,25 +66,26 @@ def find(r, w, move=False, direction='next', start=None, end=None): else: raise Exception, 'blech' for i in indices: - if direction == 'next' and ranges[i][0] > limit: - ranges[i][3] = selected_color - newc = (ranges[i][0], ranges[i][1], ranges[i][4]) + if (direction == 'next' and ranges[i].p1 > limit or + direction == 'previous' and ranges[i].p2 < limit): + ranges[i].bg = SELECTED + newc = (ranges[i].p1, ranges[i].p2, ranges[i].match) break - elif direction == 'previous' and ranges[i][1] < limit: - ranges[i][3] = selected_color - newc = (ranges[i][0], ranges[i][1], ranges[i][4]) - break - if ranges and not newc: - return None - app.clear_highlighted_ranges('search') if newc: w.goto(newc[0]) - for (p1, p2, fg, bg, m) in ranges: - if p1 < w.first: + else: + i = 0 + if direction == 'next': + i = -1 + ranges[i].bg = SELECTED + newc = (ranges[i].p1, ranges[i].p2, ranges[i].match) + + app.clear_highlighted_ranges('search') + for hr in ranges: + if hr.p1 < w.first: continue - elif p2 > w.last: + elif hr.p2 > w.last: break - hr = HighlightRegion(w, p1, p2, fg, bg, match=m, name='search') app.add_highlighted_range(hr) return newc