Skip to content

gh-95511: IDLE - fix Shell context menu copy-with-prompts bug #95512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Released on 2022-10-03
=========================


gh-95511: Fix the Shell context menu copy-with-prompts bug of copying
an extra line when one selects whole lines.

gh-95471: Tweak Edit menu. Move 'Select All' above 'Cut' as it is used
with 'Cut' and 'Copy' but not 'Paste'. Add a separator between 'Replace'
and 'Go to Line' to help IDLE issue triagers.
Expand Down
7 changes: 4 additions & 3 deletions Lib/idlelib/idle_test/test_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def test_copy_with_prompts(self):
first_line = get_end_linenumber(text)
self.do_input(dedent('''\
if True:
print(1)
print(1)

'''))
yield
Expand All @@ -744,9 +744,10 @@ def test_copy_with_prompts(self):

selected_lines_text = text.get('sel.first linestart', 'sel.last')
selected_lines = selected_lines_text.split('\n')
# Expect a block of input, a single output line, and a new prompt
selected_lines.pop() # Final '' is a split artifact, not a line.
# Expect a block of input and a single output line.
expected_prompts = \
['>>>'] + ['...'] * (len(selected_lines) - 3) + [None, '>>>']
['>>>'] + ['...'] * (len(selected_lines) - 2) + [None]
selected_text_with_prompts = '\n'.join(
line if prompt is None else prompt + ' ' + line
for prompt, line in zip(expected_prompts,
Expand Down
22 changes: 10 additions & 12 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,19 +996,17 @@ def copy_with_prompts_callback(self, event=None):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the Shell context menu copy-with-prompts bug of copying an extra line
when one selects whole lines.