mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
gh-123177: Fix prompt for wrapped lines in pyrepl (#123324)
When display lines above the cursor come from the cache, the first line to not come from the cache may be a wrapped line, starting half way through a logical line in the buffer. Detect and handle this case to avoid accidentally drawing a stray prompt in the middle of a logical line.
This commit is contained in:
parent
70bfef52b5
commit
602fcf97df
3 changed files with 42 additions and 1 deletions
|
@ -345,7 +345,10 @@ class Reader:
|
|||
pos = self.pos
|
||||
pos -= offset
|
||||
|
||||
prompt_from_cache = (offset and self.buffer[offset - 1] != "\n")
|
||||
|
||||
lines = "".join(self.buffer[offset:]).split("\n")
|
||||
|
||||
cursor_found = False
|
||||
lines_beyond_cursor = 0
|
||||
for ln, line in enumerate(lines, num_common_lines):
|
||||
|
@ -359,7 +362,12 @@ class Reader:
|
|||
# No need to keep formatting lines.
|
||||
# The console can't show them.
|
||||
break
|
||||
prompt = self.get_prompt(ln, ll >= pos >= 0)
|
||||
if prompt_from_cache:
|
||||
# Only the first line's prompt can come from the cache
|
||||
prompt_from_cache = False
|
||||
prompt = ""
|
||||
else:
|
||||
prompt = self.get_prompt(ln, ll >= pos >= 0)
|
||||
while "\n" in prompt:
|
||||
pre_prompt, _, prompt = prompt.partition("\n")
|
||||
last_refresh_line_end_offsets.append(offset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue