From f2b43fb3068f719aa2343fc7ab1d394ce58c62db Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Sat, 22 May 2021 10:16:46 +0200 Subject: Ignore termios control characters if cursor is not at end To me it seems somewhat unintuitive if ctrl+d causes VEOF if your cursor is not at the point where you would normally enter the next character. With this commit, all termios control keybindings are a NOPs in this case. --- saneterm/terminal.py | 6 +++++- saneterm/termview.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/saneterm/terminal.py b/saneterm/terminal.py index 60d1b24..da41590 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -95,7 +95,11 @@ class Terminal(Gtk.Window): os.write(self.pty.master, line.encode("UTF-8")) def termios_ctrl(self, termview, cidx): - if cidx == termios.VEOF: + # termios ctrl keys are ignored if the cursor is not at the + # buffer position where the next character would appear. + if not termview.cursor_at_end(): + return + elif cidx == termios.VEOF: termview.flush() # TODO: Employ some heuristic to cache tcgetattr result. diff --git a/saneterm/termview.py b/saneterm/termview.py index 0b8a16c..6c2ce14 100644 --- a/saneterm/termview.py +++ b/saneterm/termview.py @@ -83,6 +83,12 @@ class TermView(Gtk.TextView): return cur.compare(out) == 0 + def cursor_at_end(self): + cur = self._textbuffer.get_iter_at_offset(self._textbuffer.props.cursor_position) + end = self._textbuffer.get_iter_at_mark(self._last_mark) + + return cur.compare(end) == 0 + def do_backspace(self): # If current position is output positon ignore backspace. if not self.cursor_at_out(): -- cgit 1.4.1