From 244dc5897de8ef9d415aa208216406e5767b9420 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Fri, 21 Jan 2022 08:59:29 +1000 Subject: [PATCH] diff-edit: Allow negative scroll positions in portals --- fill3/fill3/__init__.py | 14 ++++++++++---- fill3/tests/fill3_test.py | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fill3/fill3/__init__.py b/fill3/fill3/__init__.py index af3bd54..d56f32d 100755 --- a/fill3/fill3/__init__.py +++ b/fill3/fill3/__init__.py @@ -229,12 +229,18 @@ class Portal: width, height = dimensions x, y = self.position try: - appearance = self.widget.appearance_interval((y, y+height)) + appearance = self.widget.appearance_interval((max(y, 0), y+height)) except AttributeError: - appearance = self.widget.appearance()[y:y+height] + appearance = self.widget.appearance()[max(y, 0):y+height] self.last_dimensions = dimensions - return appearance_resize([row[x:x+width] for row in appearance], - dimensions, self.background_char) + top = [self.background_char * width] * -y if y < 0 else [] + bottom = appearance_resize([row[max(x, 0):x+width] for row in appearance], + (width + min(x, 0), height + min(y, 0)), + self.background_char) + if x < 0: + padding = self.background_char * -x + bottom = [padding + line for line in bottom] + return top + bottom class View: diff --git a/fill3/tests/fill3_test.py b/fill3/tests/fill3_test.py index c6711c4..856c980 100755 --- a/fill3/tests/fill3_test.py +++ b/fill3/tests/fill3_test.py @@ -38,6 +38,13 @@ class WidgetTests(unittest.TestCase): self.assert_string(portal.appearance_for((5, 1)), "oobar") portal.position = (0, 10) self.assert_string(portal.appearance_for((1, 1)), " ") + portal.position = (1, 0) + self.assert_string(portal.appearance_for((6, 2)), "oobar \n ") + portal.position = (-1, -1) + self.assert_string(portal.appearance_for((2, 2)), " \n f") + self.assert_string(portal.appearance_for((8, 3)), " \n foobar \n ") + portal.position = (5, 0) + self.assert_string(portal.appearance_for((2, 1)), "r ") def test_border_widget(self): contents = fill3.Filler(self.TEXT_A)