@@ -25,7 +25,8 @@ def replace(text, insert_tags=None):
25
25
if not hasattr (engine , "_replacedialog" ):
26
26
engine ._replacedialog = ReplaceDialog (root , engine )
27
27
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 )
29
30
30
31
31
32
class ReplaceDialog (SearchDialogBase ):
@@ -51,27 +52,17 @@ def __init__(self, root, engine):
51
52
self .replvar = StringVar (root )
52
53
self .insert_tags = None
53
54
54
- def open (self , text , insert_tags = None ):
55
+ def open (self , text , searchphrase = None , * , insert_tags = None ):
55
56
"""Make dialog visible on top of others and ready to use.
56
57
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).
59
60
60
61
Args:
61
62
text: Text widget being searched.
63
+ searchphrase: String phrase to search.
62
64
"""
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 )
75
66
self .ok = True
76
67
self .insert_tags = insert_tags
77
68
0 commit comments