From 4d760a552b2c1143c1bd0a8b055b02892daab60e Mon Sep 17 00:00:00 2001
From: pommicket <pommicket@gmail.com>
Date: Wed, 17 Jul 2024 23:16:09 -0700
Subject: Fix opening file from build output

---
 main.c |  3 ---
 ted.c  | 10 ++++++----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/main.c b/main.c
index af57927..723b748 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,4 @@
 /*
-TODO:
-- fix opening file from build output (while there are any nodes open)
-
 FUTURE FEATURES:
 - more tests
 - prepare rename support
diff --git a/ted.c b/ted.c
index 969b416..0765898 100644
--- a/ted.c
+++ b/ted.c
@@ -620,10 +620,12 @@ static TextBuffer *ted_open_buffer(Ted *ted, u16 *tab) {
 			// it may happen.... (currently happens for rename symbol)
 			node = ted_buffer_location_in_node_tree(ted, ted->prev_active_buffer, NULL);
 		} else {
-			// idk what is going on
-			ted_error(ted, "internal error: can't figure out where to put this buffer.");
-			ted_delete_buffer(ted, new_buffer);
-			return NULL;
+			// e.g. opening a file while build output buffer is active
+			// just guess a node where the buffer should go -
+			// this situation is pretty rare.
+			node = ted->nodes[0];
+			while (node_child1(node))
+				node = node_child1(node);
 		}
 	}
 	
-- 
cgit v1.2.3