summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-06-16 09:35:29 -0300
committerAndrés <andmarti@gmail.com>2021-06-16 09:35:29 -0300
commit362e462d6ed36daf5c1103fade84b801fd821cb8 (patch)
treeb3e278273f340cf059527c0867fc9cad53bd0a64 /src
parent1ca58845c40d3be21652155a4c58e2fa0a7cef95 (diff)
rebuild graph in delete_sheet
Diffstat (limited to 'src')
-rwxr-xr-xsrc/gram.y2
-rw-r--r--src/sheet.c11
2 files changed, 10 insertions, 3 deletions
diff --git a/src/gram.y b/src/gram.y
index 9605723..0ee0939 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -847,7 +847,7 @@ command:
else if (roman->cur_sh == sh)
roman->cur_sh = sh->prev;
delete_sheet(roman, sh, 0);
- rebuild_graph();
+ sh = NULL;
roman->modflg++;
chg_mode('.');
ui_update(TRUE);
diff --git a/src/sheet.c b/src/sheet.c
index 66910ce..f399623 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -48,6 +48,7 @@
#include "file.h"
#include "yank.h"
#include "marks.h"
+#include "graph.h"
int id_sheet = 0;
@@ -185,7 +186,7 @@ void delete_doc(struct session * session, struct roman * doc) {
void delete_sheet(struct roman * roman, struct sheet * sh, int flg_free) {
REMOVE(sh, (roman->first_sh), (roman->last_sh), next, prev);
- // mark to NULL all ents on yanklist that refers to this sheet
+ // mark '->sheet to NULL' in all ents on yanklist that refers to this sheet
struct ent_ptr * yl = get_yanklist();
while (yl != NULL) {
if (yl->sheet == sh) yl->sheet = NULL;
@@ -196,7 +197,12 @@ void delete_sheet(struct roman * roman, struct sheet * sh, int flg_free) {
clean_marks_by_sheet(sh);
// free sheet
- erasedb(sh, flg_free); // clear sh and also free
+ erasedb(sh, flg_free); // clear sh and free on if flg_free is true
+
+ // if we are deleting a sheet not at exit
+ // we need to update references of ents of other sheets
+ // that could refer to this one by rebuilding the graph.
+ if (! flg_free) rebuild_graph();
for (int row = 0; sh->tbl != NULL && row < sh->maxrows; row++) {
if (sh->tbl[row] != NULL) {
@@ -220,6 +226,7 @@ void delete_sheet(struct roman * roman, struct sheet * sh, int flg_free) {
sh->name = NULL;
}
free(sh);
+ sh = NULL;
return;
}