diff --git a/TODO b/TODO index 6f84b3a..b166bb5 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ Todo: -- Right align the left editor. - Keyboard shortcuts for resolving differences. - How to handle tabs? - Colourise file name. @@ -29,6 +28,7 @@ Done: - Fix coast scrolling. - Put it on github. - tab key should align code. +- Right align the left editor. Shelved: diff --git a/diff_edit/__init__.py b/diff_edit/__init__.py index 54685ef..b4d78ac 100755 --- a/diff_edit/__init__.py +++ b/diff_edit/__init__.py @@ -128,7 +128,7 @@ def draw_connector(columns, color, left_y, right_y): class DiffEditor: def __init__(self, left_path, right_path): - self.left_editor = editor.Editor() + self.left_editor = editor.Editor(is_right_aligned=True) self.left_editor.load(left_path) self.left_editor.view_widget.is_scrollbar_right = False self.right_editor = editor.Editor() @@ -370,6 +370,7 @@ def main(): if path_b is None: editor_ = editor.Editor(path_a) editor_.load(path_a) + editor_.is_right_aligned = True else: editor_ = DiffEditor(path_a, path_b) asyncio.run(fill3.tui(PROJECT_NAME, editor_)) diff --git a/diff_edit/editor.py b/diff_edit/editor.py index 31832f1..ae45e41 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -184,7 +184,7 @@ class Editor: THEMES = [pygments.styles.get_style_by_name(style) for style in ["monokai", "fruity", "native"]] + [None] - def __init__(self, text="", path="Untitled"): + def __init__(self, text="", path="Untitled", is_right_aligned=False): self.path = os.path.normpath(path) self.set_text(text) self.mark = None @@ -195,6 +195,7 @@ class Editor: self.theme_index = 0 self.previous_term_code = None self.history = [] + self.is_right_aligned = is_right_aligned @property def cursor_x(self): @@ -626,6 +627,13 @@ class Editor: def appearance_for(self, dimensions): width, height = dimensions + text_width = self.text_widget.max_line_length + if self.is_right_aligned and text_width < width: + x, y = self.view_widget.position + new_x = text_width - width + if self.cursor_x == text_width: + new_x += 1 + self.view_widget.position = new_x, y is_changed = self.text_widget.actual_text != self.original_text header = self.get_header(self.path, width, self.cursor_x, self.cursor_y, is_changed) self.last_width = width diff --git a/setup.py b/setup.py index fda6b4e..17dbd8b 100755 --- a/setup.py +++ b/setup.py @@ -18,4 +18,4 @@ setup(name="diff-edit", entry_points={"console_scripts": ["diff-edit=diff_edit:main"]}, install_requires=[ "pygments==2.10.0", "docopt==0.6.2", - "fill3 @ git+https://github.com/ahamilton/eris@v2022.01.18#subdirectory=fill3"]) + "fill3 @ git+https://github.com/ahamilton/eris@v2022.01.21#subdirectory=fill3"])