maybe fixed the search-as-you-type bugs!!!
--HG-- branch : pmacs2
This commit is contained in:
parent
3c7840e15c
commit
6e961d7a61
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue