add multi-line support
This commit is contained in:
parent
7a154e1ae1
commit
3c02865e8b
|
@ -356,13 +356,22 @@ class FlowView(common.WWrap):
|
|||
|
||||
return (start_line, start_index)
|
||||
|
||||
def search_get_range(self, len_text_objects, start_line, backwards):
|
||||
if not backwards:
|
||||
loop_range = range(start_line, len_text_objects)
|
||||
else:
|
||||
loop_range = range(start_line, 0, -1)
|
||||
|
||||
return loop_range
|
||||
|
||||
def search_highlight_text(self, text_objects, search_string, looping = False, backwards = False):
|
||||
start_line, start_index = self.search_get_start(search_string)
|
||||
i = start_line
|
||||
|
||||
found = False
|
||||
text_objects = copy.deepcopy(text_objects)
|
||||
for text_object in text_objects[start_line:]:
|
||||
for i in self.search_get_range(len(text_objects), start_line, backwards):
|
||||
text_object = text_objects[i]
|
||||
if i != start_line:
|
||||
start_index = None
|
||||
|
||||
|
@ -391,8 +400,6 @@ class FlowView(common.WWrap):
|
|||
found = True
|
||||
break
|
||||
|
||||
i += 1
|
||||
|
||||
# handle search WRAP
|
||||
if found:
|
||||
focus_pos = i
|
||||
|
|
|
@ -119,3 +119,18 @@ def test_search_backwards():
|
|||
text_object = tutils.get_body_line(f.last_displayed_body, 0)
|
||||
assert text_object.get_text() == first_match
|
||||
|
||||
def test_search_back_multiline():
|
||||
f = tutils.tflowview(request_contents="this is string\nstring is string")
|
||||
|
||||
f.search("string")
|
||||
text_object = tutils.get_body_line(f.last_displayed_body, 0)
|
||||
first_match = ('this is string', [(None, 8), (f.highlight_color, 6)])
|
||||
assert text_object.get_text() == first_match
|
||||
|
||||
f.search_again()
|
||||
text_object = tutils.get_body_line(f.last_displayed_body, 1)
|
||||
assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)])
|
||||
|
||||
f.search_again(backwards=True)
|
||||
text_object = tutils.get_body_line(f.last_displayed_body, 0)
|
||||
assert text_object.get_text() == first_match
|
||||
|
|
Loading…
Reference in New Issue