From 401005ee3a819f7c3906c9eda55c70238201cf86 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Fri, 7 Jan 2022 17:55:16 +1000 Subject: [PATCH] editor: Fix scrolling crash. --- BUGS | 6 +++--- TODO | 2 ++ diff_edit/editor.py | 30 +++++++++++++----------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/BUGS b/BUGS index 203dd54..c5a7456 100644 --- a/BUGS +++ b/BUGS @@ -1,9 +1,9 @@ Current: + + +Fixed: - Interface freezing often. - Fix scrolling. -Fixed: - - Won't fix: diff --git a/TODO b/TODO index 6e14352..4f1f8ad 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ Todo: - Right align the left editor. +- Keyboard shortcuts for resolving differences. +- tab key should align code. Done: diff --git a/diff_edit/editor.py b/diff_edit/editor.py index ddd8b91..692fac8 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -228,24 +228,20 @@ class Editor: @scroll_position.setter def scroll_position(self, position): x, y = position - # text_width = self.text_widget.max_line_length - # if x < 0: - # new_x = 0 - # elif x > text_width - self.last_width + 2: - # new_x = max(text_width - self.last_width + 2, 0) - # else: - # new_x = x - # if y < 0: - # new_y = 0 - # elif y > len(self.text_widget) - self.last_height + 2: - # new_y = max(len(self.text_widget) - self.last_height + 2, 0) - # else: - # new_y = y - new_x, new_y = max(x, 0), y + text_width = self.text_widget.max_line_length + if x < 0: + new_x = 0 + elif x > text_width - self.last_width + 2: + new_x = max(text_width - self.last_width + 2, 0) + else: + new_x = x + if y < 0: + new_y = 0 + elif y > len(self.text_widget) - self.last_height + 2: + new_y = max(len(self.text_widget) - self.last_height + 2, 0) + else: + new_y = y self.view_widget.position = new_x, new_y - view_x, view_y = self.view_widget.position - new_cursor_y = self.cursor_y + y - view_y - self.cursor_y = max(0, min(new_cursor_y, len(self.text_widget) - 1)) def get_selection_interval(self): mark_x, mark_y = self.mark