@@ -26,7 +26,8 @@ def replace(text, insert_tags=None):
26
26
if not hasattr (engine , "_replacedialog" ):
27
27
engine ._replacedialog = ReplaceDialog (root , engine )
28
28
dialog = engine ._replacedialog
29
- dialog .open (text , insert_tags = insert_tags )
29
+ searchphrase = text .get ("sel.first" , "sel.last" )
30
+ dialog .open (text , searchphrase , insert_tags = insert_tags )
30
31
31
32
32
33
class ReplaceDialog (SearchDialogBase ):
@@ -52,27 +53,17 @@ def __init__(self, root, engine):
52
53
self .replvar = StringVar (root )
53
54
self .insert_tags = None
54
55
55
- def open (self , text , insert_tags = None ):
56
+ def open (self , text , searchphrase = None , * , insert_tags = None ):
56
57
"""Make dialog visible on top of others and ready to use.
57
58
58
- Also, highlight the currently selected text and set the
59
- search to include the current selection (self.ok).
59
+ Also, set the search to include the current selection
60
+ (self.ok).
60
61
61
62
Args:
62
63
text: Text widget being searched.
64
+ searchphrase: String phrase to search.
63
65
"""
64
- SearchDialogBase .open (self , text )
65
- try :
66
- first = text .index ("sel.first" )
67
- except TclError :
68
- first = None
69
- try :
70
- last = text .index ("sel.last" )
71
- except TclError :
72
- last = None
73
- first = first or text .index ("insert" )
74
- last = last or first
75
- self .show_hit (first , last )
66
+ SearchDialogBase .open (self , text , searchphrase )
76
67
self .ok = True
77
68
self .insert_tags = insert_tags
78
69
0 commit comments