Skip to content

Commit 712afab

Browse files
ZackerySpytzserwyserhiy-storchaka
authored
gh-57795: IDLE: Enter the selected text when opening the "Replace" dialog (GH-17593)
Co-authored-by: Roger Serwy <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 1ddd773 commit 712afab

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Lib/idlelib/replace.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3132
class 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enter the selected text when opening the "Replace" dialog.

0 commit comments

Comments
 (0)