From 2ea9462ed15e8fb62568adebbb05884f33b813ff Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 28 Nov 2021 15:45:06 -0800 Subject: 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. --- src/kilo.c | 10 ++++++++-- src/lua.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') 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); -- cgit 1.4.1-2-gfad0 ets/common.go?h=0.4.0&id=aed847f9ebf5e1d7301b5965e5d5c405a62453fe'>plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20