diff --git a/search.py b/search.py index 73f388f..d3cd102 100644 --- a/search.py +++ b/search.py @@ -52,18 +52,27 @@ def find(r, w, move=False, direction='next', start=None, end=None): offset = 0 if direction == 'next': limit = Point(x - 1 + offset, y) - else: + elif direction == 'previous': limit = Point(x + 1 - offset, y) for stuff in app.highlighted_ranges: (wz, p1, p2, fg, bg) = stuff - if p1.y == c.y and p1.x == c.x: - limit = Point(x + 1 + p2.x - p1.x - offset, y) + #if p1.y == c.y and p1.x == c.x: + if p1 == c: + #raise Exception, "argh you got me: %d (%d + 1 + %d - %d - %d), %d" % (x + 1 + p2.x - p1.x - offset, x, p2.x, p1.x, offset, y) + limit = Point(x + 1 + p2.x - p1.x - 2*offset + 1, y) break indices.reverse() + else: + raise Exception, 'blech' for i in indices: - if ((direction == 'next' and ranges[i][0] > limit) or - (direction != 'next' and ranges[i][1] < limit)): + if direction == 'next' and ranges[i][0] > limit: ranges[i][3] = selected_color + #assert ranges[i][0] > c, "%r > %r" % (ranges[i][0], c) + newc = (ranges[i][0], ranges[i][1]) + break + elif direction == 'previous' and ranges[i][1] < limit: + ranges[i][3] = selected_color + #assert ranges[i][1] < c, "%r < %r" % (ranges[i][1], c) newc = (ranges[i][0], ranges[i][1]) break if ranges and not newc: