summaryrefslogtreecommitdiff
path: root/Lib/idlelib/pyshell.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-31 22:25:56 -0700
committerGitHub <noreply@github.com>2022-07-31 22:25:56 -0700
commit4eab100e0dc764a5b85557aa30265066d1fde72e (patch)
treef209f2d75dbe9aa86cea60e4c5e4b3b4f65ee51c /Lib/idlelib/pyshell.py
parent03fed0ade40af6877ed0d8289c05c46e985b66ec (diff)
downloadcpython-git-4eab100e0dc764a5b85557aa30265066d1fde72e.tar.gz
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 6c333b0bc3..ba33f581ea 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -1005,19 +1005,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)