From da6e077e3be85b6bc9c220ddf8ca205ae8b41033 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 13 Dec 2019 12:27:41 -0700 Subject: [PATCH] bpo-13586: IDLE: Enter the selected text when opening the "Replace" dialog Co-Authored-By: Roger Serwy --- Lib/idlelib/replace.py | 23 +++++++------------ .../2019-12-13-12-26-56.bpo-13586.1grqsR.rst | 1 + 2 files changed, 9 insertions(+), 15 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 6be034af962..eb517ce6ab7 100644 --- a/Lib/idlelib/replace.py +++ b/Lib/idlelib/replace.py @@ -25,7 +25,7 @@ def replace(text): if not hasattr(engine, "_replacedialog"): engine._replacedialog = ReplaceDialog(root, engine) dialog = engine._replacedialog - dialog.open(text) + dialog.open(text, text.get("sel.first", "sel.last")) class ReplaceDialog(SearchDialogBase): @@ -50,27 +50,20 @@ class ReplaceDialog(SearchDialogBase): super().__init__(root, engine) self.replvar = StringVar(root) - def open(self, text): + def open(self, text, selected=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. + selected: The selected text. """ 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) + if selected: + self.ent.delete(0, "end") + self.ent.insert("end", selected) self.ok = True def create_entries(self): 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 00000000000..1a73cad175c --- /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.