mirror of
https://github.com/python/cpython.git
synced 2025-09-23 00:43:12 +00:00
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:
parent
d29e279de3
commit
fc31a13dc1
4 changed files with 18 additions and 14 deletions
|
@ -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
|
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'
|
with 'Cut' and 'Copy' but not 'Paste'. Add a separator between 'Replace'
|
||||||
and 'Go to Line' to help IDLE issue triagers.
|
and 'Go to Line' to help IDLE issue triagers.
|
||||||
|
|
|
@ -733,7 +733,7 @@ class ShellSidebarTest(unittest.TestCase):
|
||||||
first_line = get_end_linenumber(text)
|
first_line = get_end_linenumber(text)
|
||||||
self.do_input(dedent('''\
|
self.do_input(dedent('''\
|
||||||
if True:
|
if True:
|
||||||
print(1)
|
print(1)
|
||||||
|
|
||||||
'''))
|
'''))
|
||||||
yield
|
yield
|
||||||
|
@ -744,9 +744,10 @@ class ShellSidebarTest(unittest.TestCase):
|
||||||
|
|
||||||
selected_lines_text = text.get('sel.first linestart', 'sel.last')
|
selected_lines_text = text.get('sel.first linestart', 'sel.last')
|
||||||
selected_lines = selected_lines_text.split('\n')
|
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 = \
|
expected_prompts = \
|
||||||
['>>>'] + ['...'] * (len(selected_lines) - 3) + [None, '>>>']
|
['>>>'] + ['...'] * (len(selected_lines) - 2) + [None]
|
||||||
selected_text_with_prompts = '\n'.join(
|
selected_text_with_prompts = '\n'.join(
|
||||||
line if prompt is None else prompt + ' ' + line
|
line if prompt is None else prompt + ' ' + line
|
||||||
for prompt, line in zip(expected_prompts,
|
for prompt, line in zip(expected_prompts,
|
||||||
|
|
|
@ -996,19 +996,17 @@ class PyShell(OutputWindow):
|
||||||
and/or last lines is selected.
|
and/or last lines is selected.
|
||||||
"""
|
"""
|
||||||
text = self.text
|
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 = (
|
selected_text = self.text.get(selfirst, sellast)
|
||||||
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)
|
|
||||||
selection_lineno_range = range(
|
selection_lineno_range = range(
|
||||||
int(float(selection_indexes[0])),
|
int(float(selfirst)),
|
||||||
int(float(selection_indexes[1]))
|
int(float(sellast))
|
||||||
)
|
)
|
||||||
prompts = [
|
prompts = [
|
||||||
self.shell_sidebar.line_prompts.get(lineno)
|
self.shell_sidebar.line_prompts.get(lineno)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix the Shell context menu copy-with-prompts bug of copying an extra line
|
||||||
|
when one selects whole lines.
|
Loading…
Add table
Add a link
Reference in a new issue