now really fix it + test

This commit is contained in:
Pedro Worcel 2013-12-26 22:18:34 +13:00
parent a4b059c2a7
commit 799c877676
2 changed files with 29 additions and 6 deletions

View File

@ -323,21 +323,25 @@ class FlowView(common.WWrap):
return "search hit BOTTOM, continuing at TOP"
def search_get_start(self, search_string):
start_line = 0
start_index = 0
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
if search_string == last_search_string:
start_line = self.state.get_flow_setting(self.flow, "last_find_line")
start_index = self.state.get_flow_setting(self.flow,
"last_search_index")
if start_index != None:
start_index += len(search_string)
else:
if start_index == None:
start_index = 0
else:
start_index += len(search_string)
if start_line == None:
start_line = 0
else:
self.state.add_flow_setting(self.flow, "last_search_string",
search_string)
start_line = 0
start_index = 0
return (start_line, start_index)

View File

@ -295,7 +295,6 @@ def test_search_highlights_multi_line():
# should highlight second line, first appearance of string.
f.search("string")
text_object = tutils.get_body_line(f.last_displayed_body, 1)
print text_object.get_text()
assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)])
# should highlight third line, second appearance of string.
@ -328,4 +327,24 @@ def test_search_focuses():
text_object = tutils.get_body_line(f.last_displayed_body, 1)
assert f.last_displayed_body.focus == text_object
def test_search_does_not_crash_on_bad():
"""
this used to crash, kept for reference.
"""
f = tutils.tflowview(request_contents="this is string\nstring is string\n"+("A" * cv.VIEW_CUTOFF)+"AFTERCUTOFF")
f.search("AFTERCUTOFF")
# pretend F
f.state.add_flow_setting(
f.flow,
(f.state.view_flow_mode, "fullcontents"),
True
)
f.master.refresh_flow(f.flow)
# text changed, now this string will exist. can happen when user presses F
# for full text view
f.search("AFTERCUTOFF")