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 15:45:06 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-28 15:45:28 -0800
commit2ea9462ed15e8fb62568adebbb05884f33b813ff (patch)
tree102489f98b42ec93ffecc68a7069e2fa4c434691 /src
parent2f42187663425d994660876ca76cacd69c085bbc (diff)
downloadteliva-2ea9462ed15e8fb62568adebbb05884f33b813ff.tar.gz
editing notes sucks a little less
I think I've gotten rid of all the segfaults, but it's still pretty
messed up: if you hit ctrl-g and go edit some definition, it doesn't get
saved. You're just storing the edit in the note.
Diffstat (limited to 'src')
-rw-r--r--src/kilo.c10
-rw-r--r--src/lua.c4
2 files changed, 10 insertions, 4 deletions
diff --git a/src/kilo.c b/src/kilo.c
index ac2e991..bc84948 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -972,6 +972,7 @@ void word_at_cursor(char* out, int capacity) {
   int cidx = E.coloff + E.cx;
   int len = 0;
   memset(out, 0, capacity);
+  if (row == NULL) return;
   /* scan back to first identifier char */
   while (cidx > 0) {
     --cidx;
@@ -989,15 +990,20 @@ void word_at_cursor(char* out, int capacity) {
     strncpy(out, &row->chars[cidx], len);
 }
 
+/* Jump to some definition. */
 extern void save_to_current_definition_and_editor_buffer(lua_State *L, char *name);
 extern void load_editor_buffer_to_current_definition_in_image(lua_State *L);
+extern char Current_definition[];
 #define CURRENT_DEFINITION_LEN 256
 static void editorGo(lua_State* L) {
     char query[CURRENT_DEFINITION_LEN+1] = {0};
     int qlen = 0;
 
-    editorSaveToDisk();
-    load_editor_buffer_to_current_definition_in_image(L);
+    if (strlen(Current_definition) > 0) {
+      /* We're currently editing a definition. Save it. */
+      editorSaveToDisk();
+      load_editor_buffer_to_current_definition_in_image(L);
+    }
 
     word_at_cursor(query, CURRENT_DEFINITION_LEN);
     qlen = strlen(query);
diff --git a/src/lua.c b/src/lua.c
index 0a5b608..b17b7db 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -674,7 +674,6 @@ void recent_changes_view (lua_State *L) {
     /* refresh state after each operation so we pick up modifications */
     lua_getglobal(L, "teliva_program");
     history_array = lua_gettop(L);
-    assert(history_array == 1);
     history_array_size = luaL_getn(L, history_array);
     render_recent_changes(L, history_array, cursor, history_array_size);
     int c = getch();
@@ -692,7 +691,8 @@ void recent_changes_view (lua_State *L) {
         break;
       case CTRL_E:
         save_note_to_editor_buffer(L, cursor);
-        /* TODO: some hotkeys advertised but broken: go, big picture */
+        /* big picture hotkey unnecessarily available here */
+        /* TODO: go hotkey is misleading. edits will not be persisted until you return to recent changes */
         edit(L, "teliva_editor_buffer", /*status message*/ "");
         load_note_from_editor_buffer(L, cursor);
         save_image(L);