diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-12-27 14:57:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 14:57:01 (GMT) |
commit | b2ef35842cc846a40aa51ff9902ab5ce0dd844e7 (patch) | |
tree | f7c8f93e92a35cf3f4eb72f1f198d0f41e32f708 /Lib/idlelib/replace.py | |
parent | ba3e19a5d73833063dfab68f7fcfcf5715203d56 (diff) | |
download | cpython-b2ef35842cc846a40aa51ff9902ab5ce0dd844e7.zip cpython-b2ef35842cc846a40aa51ff9902ab5ce0dd844e7.tar.gz cpython-b2ef35842cc846a40aa51ff9902ab5ce0dd844e7.tar.bz2 |
[3.12] gh-57795: IDLE: Enter the selected text when opening the "Replace" dialog (GH-17593) (GH-113514)
(cherry picked from commit 712afab5acbe27ceb1eddde5aa559078ae7eaa3b)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Roger Serwy <roger.serwy@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/idlelib/replace.py')
-rw-r--r-- | Lib/idlelib/replace.py | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/Lib/idlelib/replace.py b/Lib/idlelib/replace.py index 71e187f..1cddb63 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 @@ 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 |