about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-28 08:44:24 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-28 08:44:37 -0800
commit75ded7a9187ebd588f6ef0a99a48dff726179ed6 (patch)
treee197d9c5b82261cfa2f1a0a5d67ad9dd16dd130a /src
parentdff7a5226f0c4023aa995efc8e5143d0188924c3 (diff)
downloadteliva-75ded7a9187ebd588f6ef0a99a48dff726179ed6.tar.gz
editor hotkeys: sol/eol
I'm growing attached to ^e, so mildly breaking with convention there.
Perhaps this is a bad idea.
Diffstat (limited to 'src')
-rw-r--r--src/kilo.c23
-rw-r--r--src/teliva.h1
2 files changed, 20 insertions, 4 deletions
diff --git a/src/kilo.c b/src/kilo.c
index ef2e345..dc40fb0 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -652,6 +652,8 @@ static void editorMenu(void) {
     draw_menu_item("^g", "go");
     draw_menu_item("^b", "big picture");
     draw_menu_item("^f", "find");
+    draw_menu_item("^a", "start of line");
+    draw_menu_item("^l", "end of line");
     attrset(A_NORMAL);
 }
 
@@ -882,6 +884,10 @@ static void editorFind() {
 
 /* ========================= Editor events handling  ======================== */
 
+static int editorAtStartOfLine() {
+  return E.coloff == 0 && E.cx == 0;
+}
+
 /* Handle cursor position change because arrow keys were pressed. */
 static void editorMoveCursor(int key) {
     int filerow = E.rowoff+E.cy;
@@ -1070,16 +1076,25 @@ static void editorProcessKeypress(lua_State* L) {
             editorMoveCursor(c == KEY_PPAGE ? KEY_UP : KEY_DOWN);
         }
         break;
-
+    case CTRL_A:
+        while (!editorAtStartOfLine())
+          editorMoveCursor(KEY_LEFT);
+        break;
+    case CTRL_L:
+        while (1) {
+          editorMoveCursor(KEY_RIGHT);
+          if (editorAtStartOfLine()) {
+            editorMoveCursor(KEY_LEFT);
+            break;
+          }
+        }
+        break;
     case KEY_UP:
     case KEY_DOWN:
     case KEY_LEFT:
     case KEY_RIGHT:
         editorMoveCursor(c);
         break;
-    case CTRL_L:
-        /* Just refresh the line as side effect. */
-        break;
     case ESC:
         /* Nothing to do for ESC in this mode. */
         break;
diff --git a/src/teliva.h b/src/teliva.h
index dfe322d..9a6038e 100644
--- a/src/teliva.h
+++ b/src/teliva.h
@@ -3,6 +3,7 @@
 
 enum KEY_ACTION {
   KEY_NULL = 0,
+  CTRL_A = 1,
   CTRL_B = 2,
   CTRL_C = 3,
   CTRL_D = 4,