highlighting regions

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-03 21:05:24 +00:00
parent 210e00eb37
commit 0c751d5770
5 changed files with 23 additions and 14 deletions

View File

@ -516,8 +516,16 @@ class Application(object):
# highlighting
def add_highlighted_range(self, hr):
self.highlighted_ranges.append(hr)
def clear_highlighted_ranges(self):
def clear_highlighted_ranges(self, name=None):
if name is None:
self.highlighted_ranges = []
else:
i = 0
while i < len(self.highlighted_ranges):
if self.highlighted_ranges[i].name == name:
del self.highlighted_ranges[i]
else:
i += 1
def run_external(self, *args):
curses.reset_shell_mode()

View File

@ -117,7 +117,7 @@ def _finish(m, w):
def _end(w):
w.application.close_mini_buffer()
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
w.buffer.method.old_cursor = None
w.buffer.method.old_window = None
assert not w.application.mini_active

View File

@ -28,7 +28,7 @@ class SearchNext(method.Method):
r = _make_regex(w, s)
searchutil.find_next(r, w.buffer.method.old_window, move=True)
except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
else:
action = InsertSearchString(w.application.last_search)
action.execute(w)
@ -45,7 +45,7 @@ class SearchPrevious(method.Method):
r = _make_regex(w, s)
searchutil.find_previous(r, w2, move=True)
except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
class EndSearch(method.Method):
def execute(self, w, **vargs):
@ -74,7 +74,7 @@ def _post_delete(w):
old_w = w.buffer.method.old_window
old_w.goto(old_cursor)
if not w.buffer.make_string():
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
return
s = w.buffer.make_string()
w2 = w.buffer.method.old_window
@ -85,7 +85,7 @@ def _post_delete(w):
else:
searchutil.find_previous(r, w2, move=False)
except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
class InsertSearchString(method.Method):
def __init__(self, s):
@ -97,7 +97,7 @@ class InsertSearchString(method.Method):
w.insert_string_at_cursor(self.string)
s = w.buffer.make_string()
if not s:
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
return
else:
try:
@ -108,11 +108,11 @@ class InsertSearchString(method.Method):
else:
searchutil.find_previous(r, w2, move=False)
except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
def _end(w):
w.application.close_mini_buffer()
w.application.clear_highlighted_ranges()
w.application.clear_highlighted_ranges('search')
w.application.last_search = w.buffer.make_string()
class Search(mode.Fundamental):

View File

@ -74,7 +74,7 @@ def find(r, w, move=False, direction='next', start=None, end=None):
break
if ranges and not newc:
return None
app.clear_highlighted_ranges()
app.clear_highlighted_ranges('search')
if newc:
w.goto(newc[0])
for (p1, p2, fg, bg, m) in ranges:
@ -82,7 +82,8 @@ def find(r, w, move=False, direction='next', start=None, end=None):
continue
elif p2 > w.last:
break
app.add_highlighted_range(HighlightRegion(w, p1, p2, fg, bg))
hr = HighlightRegion(w, p1, p2, fg, bg, match=m, name='search')
app.add_highlighted_range(hr)
return newc
def find_previous(r, w, move=False, start=None, end=None):