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

@ -733,7 +733,7 @@ class ShellSidebarTest(unittest.TestCase):
first_line = get_end_linenumber(text)
self.do_input(dedent('''\
if True:
print(1)
print(1)
'''))
yield
@ -744,9 +744,10 @@ class ShellSidebarTest(unittest.TestCase):
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,