From 34a76debfefed3fc9b1a7ad36d2d444e86fe0be9 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 27 Dec 2023 06:27:40 -0800 Subject: [PATCH] gh-57795: IDLE: Enter the selected text when opening the "Replace" dialog (GH-17593) (cherry picked from commit 712afab5acbe27ceb1eddde5aa559078ae7eaa3b) Co-authored-by: Zackery Spytz Co-authored-by: Roger Serwy Co-authored-by: Serhiy Storchaka --- Lib/idlelib/replace.py | 23 ++++++------------- .../2019-12-13-12-26-56.bpo-13586.1grqsR.rst | 1 + 2 files changed, 8 insertions(+), 16 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2019-12-13-12-26-56.bpo-13586.1grqsR.rst diff --git a/Lib/idlelib/replace.py b/Lib/idlelib/replace.py index 71e187f9279231..1cddb638b217ff 100644 --- a/Lib/idlelib/replace.py +++ b/Lib/idlelib/replace.py @@ -26,7 +26,8 @@ def replace(text, insert_tags=None): if not hasattr(engine, "_replacedialog"): engine._replacedialog = ReplaceDialog(root, engine) dialog = engine._replacedialog - dialog.open(text, insert_tags=insert_tags) + searchphrase = text.get("sel.first", "sel.last") + dialog.open(text, searchphrase, insert_tags=insert_tags) class ReplaceDialog(SearchDialogBase): @@ -52,27 +53,17 @@ def __init__(self, root, engine): self.replvar = StringVar(root) self.insert_tags = None - def open(self, text, insert_tags=None): + def open(self, text, searchphrase=None, *, insert_tags=None): """Make dialog visible on top of others and ready to use. - Also, highlight the currently selected text and set the - search to include the current selection (self.ok). + Also, set the search to include the current selection + (self.ok). Args: text: Text widget being searched. + searchphrase: String phrase to search. """ - SearchDialogBase.open(self, text) - try: - first = text.index("sel.first") - except TclError: - first = None - try: - last = text.index("sel.last") - except TclError: - last = None - first = first or text.index("insert") - last = last or first - self.show_hit(first, last) + SearchDialogBase.open(self, text, searchphrase) self.ok = True self.insert_tags = insert_tags diff --git a/Misc/NEWS.d/next/IDLE/2019-12-13-12-26-56.bpo-13586.1grqsR.rst b/Misc/NEWS.d/next/IDLE/2019-12-13-12-26-56.bpo-13586.1grqsR.rst new file mode 100644 index 00000000000000..1a73cad175c888 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-12-13-12-26-56.bpo-13586.1grqsR.rst @@ -0,0 +1 @@ +Enter the selected text when opening the "Replace" dialog.