@@ -25,7 +25,8 @@ def replace(text, insert_tags=None):
2525 if not hasattr (engine , "_replacedialog" ):
2626 engine ._replacedialog = ReplaceDialog (root , engine )
2727 dialog = engine ._replacedialog
28- dialog .open (text , insert_tags = insert_tags )
28+ searchphrase = text .get ("sel.first" , "sel.last" )
29+ dialog .open (text , searchphrase , insert_tags = insert_tags )
2930
3031
3132class ReplaceDialog (SearchDialogBase ):
@@ -51,27 +52,17 @@ def __init__(self, root, engine):
5152 self .replvar = StringVar (root )
5253 self .insert_tags = None
5354
54- def open (self , text , insert_tags = None ):
55+ def open (self , text , searchphrase = None , * , insert_tags = None ):
5556 """Make dialog visible on top of others and ready to use.
5657
57- Also, highlight the currently selected text and set the
58- search to include the current selection (self.ok).
58+ Also, set the search to include the current selection
59+ (self.ok).
5960
6061 Args:
6162 text: Text widget being searched.
63+ searchphrase: String phrase to search.
6264 """
63- SearchDialogBase .open (self , text )
64- try :
65- first = text .index ("sel.first" )
66- except TclError :
67- first = None
68- try :
69- last = text .index ("sel.last" )
70- except TclError :
71- last = None
72- first = first or text .index ("insert" )
73- last = last or first
74- self .show_hit (first , last )
65+ SearchDialogBase .open (self , text , searchphrase )
7566 self .ok = True
7667 self .insert_tags = insert_tags
7768
0 commit comments