diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-07-13 10:54:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-13 10:54:10 (GMT) |
commit | 4b9e10d0ea352592049c1f2a00318d7274143fa4 (patch) | |
tree | 1c2c4a8484e656db28fd88dac57702c69bcf60da /Lib/_pyrepl | |
parent | e745996b2d24b9234f896bdc2f3320e49287dcd0 (diff) | |
download | cpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.zip cpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.tar.gz cpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.tar.bz2 |
gh-121499: Fix multi-line history rendering in the REPL (#121531)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Diffstat (limited to 'Lib/_pyrepl')
-rw-r--r-- | Lib/_pyrepl/historical_reader.py | 1 | ||||
-rw-r--r-- | Lib/_pyrepl/reader.py | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/Lib/_pyrepl/historical_reader.py b/Lib/_pyrepl/historical_reader.py index dd90912..7f4d067 100644 --- a/Lib/_pyrepl/historical_reader.py +++ b/Lib/_pyrepl/historical_reader.py @@ -264,6 +264,7 @@ class HistoricalReader(Reader): self.historyi = i self.pos = len(self.buffer) self.dirty = True + self.last_refresh_cache.invalidated = True def get_item(self, i: int) -> str: if i != len(self.history): diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 1622d30..b2da038 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -253,6 +253,7 @@ class Reader: pos: int = field(init=False) cxy: tuple[int, int] = field(init=False) dimensions: tuple[int, int] = field(init=False) + invalidated: bool = False def update_cache(self, reader: Reader, @@ -265,14 +266,19 @@ class Reader: self.pos = reader.pos self.cxy = reader.cxy self.dimensions = reader.console.width, reader.console.height + self.invalidated = False def valid(self, reader: Reader) -> bool: + if self.invalidated: + return False dimensions = reader.console.width, reader.console.height dimensions_changed = dimensions != self.dimensions paste_changed = reader.in_bracketed_paste != self.in_bracketed_paste return not (dimensions_changed or paste_changed) def get_cached_location(self, reader: Reader) -> tuple[int, int]: + if self.invalidated: + raise ValueError("Cache is invalidated") offset = 0 earliest_common_pos = min(reader.pos, self.pos) num_common_lines = len(self.line_end_offsets) |