3 from EditWindow
import Minibuffer
5 class Search(Minibuffer
):
6 "A minibuffer used to search for text."
8 def setup(self
, window
):
10 buffer = window
.buffer
11 cursor
= buffer.get_iter_at_mark(window
.insert_mark
)
12 buffer.move_mark_by_name('search_base', cursor
)
16 info
= 'Type a string to search for. The display will scroll to show the ' \
17 'next match as you type. Use the Up and Down cursor keys to move ' \
18 'to the next or previous match. Press Escape or Return to finish.'
22 self
.window
.set_mini_label('Forward search:')
24 self
.window
.set_mini_label('Backward search:')
26 def set_dir(self
, dir):
27 assert dir == 1 or dir == -1
29 buffer = self
.window
.buffer
30 cursor
= buffer.get_iter_at_mark(self
.window
.insert_mark
)
31 buffer.move_mark_by_name('search_base', cursor
)
37 cursor
.backward_char()
38 if self
.search(cursor
):
39 buffer.move_mark_by_name('search_base', cursor
)
48 self
.window
.set_minibuffer(None)
50 def key_press(self
, kev
):
54 elif k
== g
.keysyms
.Down
:
60 def search(self
, start
):
61 "Search forwards or backwards for the pattern. Matches at 'start'"
62 "are allowed in both directions. Returns (match_start, match_end) if"
65 pattern
= self
.window
.mini_entry
.get_text()
69 found
= iter.forward_search(pattern
, 0, None)
71 iter.forward_chars(len(pattern
))
72 found
= iter.backward_search(pattern
, 0, None)
76 buffer = self
.window
.buffer
77 pos
= buffer.get_iter_at_mark(self
.window
.search_base
)
79 found
= self
.search(pos
)
81 buffer.move_mark_by_name('insert', found
[0])
82 buffer.move_mark_by_name('selection_bound', found
[1])
83 self
.window
.text
.scroll_to_iter(found
[0], 0.05, g
.FALSE
)