Skip to content

Commit b2ef358

Browse files
miss-islingtonZackerySpytzserwyserhiy-storchaka
authored
[3.12] gh-57795: IDLE: Enter the selected text when opening the "Replace" dialog (GH-17593) (GH-113514)
(cherry picked from commit 712afab) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Roger Serwy <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent ba3e19a commit b2ef358

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
@@ -26,7 +26,8 @@ def replace(text, insert_tags=None):
2626
if not hasattr(engine, "_replacedialog"):
2727
engine._replacedialog = ReplaceDialog(root, engine)
2828
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)
3031

3132

3233
class ReplaceDialog(SearchDialogBase):
@@ -52,27 +53,17 @@ def __init__(self, root, engine):
5253
self.replvar = StringVar(root)
5354
self.insert_tags = None
5455

55-
def open(self, text, insert_tags=None):
56+
def open(self, text, searchphrase=None, *, insert_tags=None):
5657
"""Make dialog visible on top of others and ready to use.
5758
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).
6061
6162
Args:
6263
text: Text widget being searched.
64+
searchphrase: String phrase to search.
6365
"""
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)
7667
self.ok = True
7768
self.insert_tags = insert_tags
7869

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)