gh-95511: IDLE - fix Shell context menu copy-with-prompts bug (#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.)
This commit is contained in:
Terry Jan Reedy 2022-08-01 01:06:13 -04:00 committed by GitHub
parent d29e279de3
commit fc31a13dc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 14 deletions

View file

@ -996,19 +996,17 @@ class PyShell(OutputWindow):
and/or last lines is selected.
"""
text = self.text
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")
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)
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)