From f2928d927e77be6e02e3d052e751a2c5c2811852 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Sun, 23 May 2021 13:24:04 +0200 Subject: Remove code duplication in cursor_at_{end,out} --- saneterm/termview.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/saneterm/termview.py b/saneterm/termview.py index 9f40af8..6558f2a 100644 --- a/saneterm/termview.py +++ b/saneterm/termview.py @@ -80,23 +80,20 @@ class TermView(Gtk.TextView): self._last_output_mark = self._textbuffer.create_mark(None, end, True) self._last_mark = self._last_mark - def cursor_at_out(self): + def __cursor_at_mark(self, mark): if self._textbuffer.get_has_selection(): return False cur = self._textbuffer.get_iter_at_offset(self._textbuffer.props.cursor_position) - out = self._textbuffer.get_iter_at_mark(self._last_output_mark) - - return cur.compare(out) == 0 + other = self._textbuffer.get_iter_at_mark(mark) - def cursor_at_end(self): - if self._textbuffer.get_has_selection(): - return False + return cur.compare(other) == 0 - cur = self._textbuffer.get_iter_at_offset(self._textbuffer.props.cursor_position) - end = self._textbuffer.get_iter_at_mark(self._last_mark) + def cursor_at_out(self): + return self.__cursor_at_mark(self._last_output_mark) - return cur.compare(end) == 0 + def cursor_at_end(self): + return self.__cursor_at_mark(self._last_mark) def do_backspace(self): # If current position is output positon ignore backspace. -- cgit 1.4.1