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 point import Point
|
||||||
from render import HighlightRegion
|
from render import HighlightRegion
|
||||||
|
|
||||||
bg_color = 'black'
|
BG = 'black'
|
||||||
selected_color = 'magenta'
|
SELECTED = 'magenta'
|
||||||
unselected_color = 'yellow'
|
UNSELECTED = 'yellow'
|
||||||
|
|
||||||
class IllegalPatternError(Exception):
|
class IllegalPatternError(Exception):
|
||||||
pass
|
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):
|
for m in r.finditer(w.buffer.lines[y], x, limit):
|
||||||
if len(m.group(0)) == 0:
|
if len(m.group(0)) == 0:
|
||||||
raise IllegalPatternError, "zero-width match found"
|
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
|
x = 0
|
||||||
y += 1
|
y += 1
|
||||||
return ranges
|
return ranges
|
||||||
|
@ -64,25 +66,26 @@ def find(r, w, move=False, direction='next', start=None, end=None):
|
||||||
else:
|
else:
|
||||||
raise Exception, 'blech'
|
raise Exception, 'blech'
|
||||||
for i in indices:
|
for i in indices:
|
||||||
if direction == 'next' and ranges[i][0] > limit:
|
if (direction == 'next' and ranges[i].p1 > limit or
|
||||||
ranges[i][3] = selected_color
|
direction == 'previous' and ranges[i].p2 < limit):
|
||||||
newc = (ranges[i][0], ranges[i][1], ranges[i][4])
|
ranges[i].bg = SELECTED
|
||||||
|
newc = (ranges[i].p1, ranges[i].p2, ranges[i].match)
|
||||||
break
|
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:
|
if newc:
|
||||||
w.goto(newc[0])
|
w.goto(newc[0])
|
||||||
for (p1, p2, fg, bg, m) in ranges:
|
else:
|
||||||
if p1 < w.first:
|
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
|
continue
|
||||||
elif p2 > w.last:
|
elif hr.p2 > w.last:
|
||||||
break
|
break
|
||||||
hr = HighlightRegion(w, p1, p2, fg, bg, match=m, name='search')
|
|
||||||
app.add_highlighted_range(hr)
|
app.add_highlighted_range(hr)
|
||||||
return newc
|
return newc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue