summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/pyshell.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-01 05:32:33 (GMT)
committerGitHub <noreply@github.com>2022-08-01 05:32:33 (GMT)
commite4541c474aa5a4e27c5d1078de4508fef018b302 (patch)
treedc4dcb3f009647ea2f77611f681b8782c287a058 /Lib/idlelib/pyshell.py
parenta4cda28f7b83c25ed412f8ce2a502fd54d7b4c5a (diff)
downloadcpython-e4541c474aa5a4e27c5d1078de4508fef018b302.zip
cpython-e4541c474aa5a4e27c5d1078de4508fef018b302.tar.gz
cpython-e4541c474aa5a4e27c5d1078de4508fef018b302.tar.bz2
gh-95511: IDLE - fix Shell context menu copy-with-prompts bug (GH-95512)
If one selects whole lines, as the sidebar makes easy, do not add an extra line. Only move the end of a selection to the beginning of the next line when not already at the beginning of a line. (Also improve the surrounding code.) (cherry picked from commit fc31a13dc1799b8d972c1f4ea49f27090aed7f48) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/pyshell.py')
-rwxr-xr-xLib/idlelib/pyshell.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 2e54a81..3806122 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -996,19 +996,17 @@ class PyShell(OutputWindow):
and/or last lines is selected.
"""
text = self.text
-
- selection_indexes = (
- self.text.index("sel.first linestart"),
- self.text.index("sel.last +1line linestart"),
- )
- if selection_indexes[0] is None:
- # There is no selection, so do nothing.
- return
-
- selected_text = self.text.get(*selection_indexes)
+ selfirst = text.index('sel.first linestart')
+ if selfirst is None: # Should not be possible.
+ return # No selection, do nothing.
+ sellast = text.index('sel.last')
+ if sellast[-1] != '0':
+ sellast = text.index("sel.last+1line linestart")
+
+ selected_text = self.text.get(selfirst, sellast)
selection_lineno_range = range(
- int(float(selection_indexes[0])),
- int(float(selection_indexes[1]))
+ int(float(selfirst)),
+ int(float(sellast))
)
prompts = [
self.shell_sidebar.line_prompts.get(lineno)