]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-57795: IDLE: Enter the selected text when opening the "Replace" dialog (GH-17593)
authorZackery Spytz <zspytz@gmail.com>
Wed, 27 Dec 2023 14:27:40 +0000 (06:27 -0800)
committerGitHub <noreply@github.com>
Wed, 27 Dec 2023 14:27:40 +0000 (16:27 +0200)
Co-authored-by: Roger Serwy <roger.serwy@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/idlelib/replace.py
Misc/NEWS.d/next/IDLE/2019-12-13-12-26-56.bpo-13586.1grqsR.rst [new file with mode: 0644]

index 7997f24f1b0fa6a28928cae93b5c75dfff2b3891..3716d841568d30930eea40840fba260792adedb9 100644 (file)
@@ -25,7 +25,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):
@@ -51,27 +52,17 @@ class ReplaceDialog(SearchDialogBase):
         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 (file)
index 0000000..1a73cad
--- /dev/null
@@ -0,0 +1 @@
+Enter the selected text when opening the "Replace" dialog.