bpo-13586: IDLE: Enter the selected text when opening the "Replace" dialog

Co-Authored-By: Roger Serwy <roger.serwy@gmail.com>
This commit is contained in:
Zackery Spytz 2019-12-13 12:27:41 -07:00
parent 8289e27393
commit da6e077e3b
2 changed files with 9 additions and 15 deletions

View File

@ -25,7 +25,7 @@ def replace(text):
if not hasattr(engine, "_replacedialog"): if not hasattr(engine, "_replacedialog"):
engine._replacedialog = ReplaceDialog(root, engine) engine._replacedialog = ReplaceDialog(root, engine)
dialog = engine._replacedialog dialog = engine._replacedialog
dialog.open(text) dialog.open(text, text.get("sel.first", "sel.last"))
class ReplaceDialog(SearchDialogBase): class ReplaceDialog(SearchDialogBase):
@ -50,27 +50,20 @@ class ReplaceDialog(SearchDialogBase):
super().__init__(root, engine) super().__init__(root, engine)
self.replvar = StringVar(root) 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. """Make dialog visible on top of others and ready to use.
Also, highlight the currently selected text and set the Also, set the search to include the current selection
search to include the current selection (self.ok). (self.ok).
Args: Args:
text: Text widget being searched. text: Text widget being searched.
selected: The selected text.
""" """
SearchDialogBase.open(self, text) SearchDialogBase.open(self, text)
try: if selected:
first = text.index("sel.first") self.ent.delete(0, "end")
except TclError: self.ent.insert("end", selected)
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)
self.ok = True self.ok = True
def create_entries(self): def create_entries(self):

View File

@ -0,0 +1 @@
Enter the selected text when opening the "Replace" dialog.