about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-05-22 10:16:46 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-05-22 10:16:46 +0200
commitf2b43fb3068f719aa2343fc7ab1d394ce58c62db (patch)
tree62ee8ba2c010aff0f808c40238c02e08f175951d
parent7826b13628323daecf6918042a00bce68743dc6a (diff)
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.
-rw-r--r--saneterm/terminal.py6
-rw-r--r--saneterm/termview.py6
2 files changed, 11 insertions, 1 deletions
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():