4 "A minibuffer used to search for text."
6 def setup(self
, window
):
9 cursor
= buffer.get_iter_at_mark(window
.insert_mark
)
10 buffer.move_mark_by_name('search_base', cursor
)
16 self
.window
.set_mini_label('Forward search:')
18 self
.window
.set_mini_label('Backward search:')
20 def set_dir(self
, dir):
21 assert dir == 1 or dir == -1
23 buffer = self
.window
.buffer
24 cursor
= buffer.get_iter_at_mark(self
.window
.insert_mark
)
25 buffer.move_mark_by_name('search_base', cursor
)
31 cursor
.backward_char()
32 if self
.search(cursor
):
33 buffer.move_mark_by_name('search_base', cursor
)
41 def key_press(self
, kev
):
43 if k
== g
.keysyms
.Return
:
44 self
.window
.set_minibuffer(None)
45 elif k
== g
.keysyms
.Up
:
47 elif k
== g
.keysyms
.Down
:
53 def search(self
, start
):
54 "Search forwards or backwards for the pattern. Matches at 'start'"
55 "are allowed in both directions. Returns (match_start, match_end) if"
58 pattern
= self
.window
.mini_entry
.get_text()
62 found
= iter.forward_search(pattern
, 0, None)
64 iter.forward_chars(len(pattern
))
65 found
= iter.backward_search(pattern
, 0, None)
69 buffer = self
.window
.buffer
70 pos
= buffer.get_iter_at_mark(self
.window
.search_base
)
72 found
= self
.search(pos
)
74 buffer.move_mark_by_name('insert', found
[0])
75 buffer.move_mark_by_name('selection_bound', found
[1])
76 self
.window
.text
.scroll_to_iter(found
[0], 0.05, g
.FALSE
)