Browse code

fix plugins not being called on undo

Dario Rodriguez authored on 01/12/2020 21:24:22
Showing 6 changed files
... ...
@@ -1039,8 +1039,12 @@ redata_op_add(redata_t *redata, long insertpos, char *buf, long buflen, undostac
1039 1039
         }
1040 1040
         /* add to plugins (unsaved,...) */
1041 1041
         for(i=0;i<redata->sizeplugins;i++) {
1042
-                if(redata->plugins[i].add!=NULL)
1043
-                        redata->plugins[i].add(redata,redata->plugins+i,redata->undostack.undo+redata->undostack.usedundo-1);
1042
+                if(redata->plugins[i].add_or_unadd!=NULL) {
1043
+                        redata->plugins[i].add_or_unadd(redata,redata->plugins+i
1044
+                          ,(undo!=NULL)?redata->undostack.undo+redata->undostack.usedundo-1
1045
+                                       :redata->redostack.undo+redata->redostack.usedundo-1
1046
+                          ,(undo!=NULL)?0:1);
1047
+                }
1044 1048
         }
1045 1049
         /* compact if needed */
1046 1050
         if(redata_getsize(redata)>(redata->chunkdatasize) && redata_getavailable(redata)>(redata_getsize(redata)/2))
... ...
@@ -1131,8 +1135,12 @@ redata_op_del(redata_t *redata, long delpos, long size, undostack_t *fromhere)
1131 1135
         }
1132 1136
         /* add to plugins (unsaved,...) */
1133 1137
         for(i=0;i<redata->sizeplugins;i++) {
1134
-                if(redata->plugins[i].add!=NULL)
1135
-                        redata->plugins[i].add(redata,redata->plugins+i,redata->undostack.undo+redata->undostack.usedundo-1);
1138
+                if(redata->plugins[i].add_or_unadd!=NULL) {
1139
+                        redata->plugins[i].add_or_unadd(redata,redata->plugins+i
1140
+                          ,(undo!=NULL)?redata->undostack.undo+redata->undostack.usedundo-1
1141
+                                       :redata->redostack.undo+redata->redostack.usedundo-1
1142
+                          ,(undo!=NULL)?0:1);
1143
+                }
1136 1144
         }
1137 1145
         /* compact if needed */
1138 1146
         if(redata_getsize(redata)>(redata->chunkdatasize) && redata_getavailable(redata)>(redata_getsize(redata)/2))
... ...
@@ -1272,8 +1280,12 @@ redata_op_move(redata_t *redata, long posorig, long size, long posdest, undostac
1272 1280
         }
1273 1281
         /* add to plugins (unsaved,...) */
1274 1282
         for(i=0;i<redata->sizeplugins;i++) {
1275
-                if(redata->plugins[i].add!=NULL)
1276
-                        redata->plugins[i].add(redata,redata->plugins+i,redata->undostack.undo+redata->undostack.usedundo-1);
1283
+                if(redata->plugins[i].add_or_unadd!=NULL) {
1284
+                        redata->plugins[i].add_or_unadd(redata,redata->plugins+i
1285
+                          ,(undo!=NULL)?redata->undostack.undo+redata->undostack.usedundo-1
1286
+                                       :redata->redostack.undo+redata->redostack.usedundo-1
1287
+                          ,(undo!=NULL)?0:1);
1288
+                }
1277 1289
         }
1278 1290
         /* compact if needed */
1279 1291
         if(redata_getsize(redata)>(redata->chunkdatasize) && redata_getavailable(redata)>(redata_getsize(redata)/2))
... ...
@@ -74,8 +74,7 @@ typedef struct redata_plugin_t {
74 74
         int (*loadquestion)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */);
75 75
         int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */);
76 76
         int (*postsave)(/*redata_t *redata, redata_plugin_t *plugin,char *oldfilename,char *newfilename*/);
77
-        int (*add)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/);
78
-        int (*unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/);
77
+        int (*add_or_unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo, int is_unadd*/);
79 78
         int (*commit)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/);
80 79
         void *userptr;
81 80
 } redata_plugin_t;
... ...
@@ -46,8 +46,6 @@ typedef enum colorsenum_t {
46 46
 } colorsenum_t;
47 47
 
48 48
 
49
-static int redata_highlighter_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
50
-static int redata_highlighter_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
51 49
 static int redata_highlighter_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd);
52 50
 static int redata_highlighter_postload(redata_t *redata, redata_plugin_t *slot,char *filename);
53 51
 
... ...
@@ -68,6 +66,7 @@ redata_highlighter_register(redata_t *redata, redata_plugin_t *slot)
68 66
         highlighter_t *hl;
69 67
         if(redata==NULL || slot==NULL)
70 68
                 return(-1);
69
+        /* "forest" theme */
71 70
         colors=hl_initcolors(&ncolors,
72 71
                              color_keyword,"\x38\x17\x1e\xff",
73 72
                              color_directive,"\x38\x4b\x00\xff",
... ...
@@ -97,8 +96,7 @@ redata_highlighter_register(redata_t *redata, redata_plugin_t *slot)
97 96
         slot->name[sizeof(slot->name)-1]='\0';
98 97
         slot->unregister=redata_highlighter_unregister;
99 98
         slot->postload=redata_highlighter_postload;
100
-        slot->add=redata_highlighter_add;
101
-        slot->unadd=redata_highlighter_unadd;
99
+        slot->add_or_unadd=redata_highlighter_add_or_unadd;
102 100
         slot->userptr=hl;
103 101
         return(0);
104 102
 }
... ...
@@ -170,36 +168,20 @@ redata_highlighter_getcolorindex(redata_t *redata, int line, int nthbyte)
170 168
         return(-1);
171 169
 }
172 170
 
173
-
174
-static int
175
-redata_highlighter_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo)
176
-{
177
-        return(redata_highlighter_add_or_unadd(redata, slot, undo, 0));
178
-}
179
-
180
-static int
181
-redata_highlighter_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo)
182
-{
183
-        return(redata_highlighter_add_or_unadd(redata, slot, undo, 1));
184
-}
185
-
186
-
187 171
 static int
188 172
 redata_highlighter_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd)
189 173
 {
190 174
         long pos;
191 175
         int nline;
192
-        undostack_t *stack;
193 176
         highlighter_t *hl=(highlighter_t *) ((slot!=NULL)?(slot->userptr):NULL);
194
-        stack=redata_getstack(redata,undo);
195
-        if(redata==NULL || slot==NULL || hl==NULL || undo==NULL || stack==NULL || slot->active==0)
177
+        if(redata==NULL || slot==NULL || hl==NULL || undo==NULL || slot->active==0)
196 178
                 return(-1); /* sanity check failed */
197 179
         if(hl->usedlines==0) {
198 180
                 return(0); /* nothing to do */
199 181
         }
200 182
         /* get the first pos of the operation */
201 183
         pos=undo->posorig;
202
-        if(undo->type=='D')
184
+        if((!is_unadd && undo->type=='D') || (is_unadd && undo->type=='A'))
203 185
                 pos-=undo->len;
204 186
         if(undo->type=='M' && undo->posdest<pos)
205 187
                 pos=undo->posdest;
... ...
@@ -33,8 +33,6 @@ typedef struct cproto_t {
33 33
         char buffer[MAXINDEXDATALEN];
34 34
 } cproto_t;
35 35
 
36
-static int redata_prototypes_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
37
-static int redata_prototypes_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
38 36
 static int redata_prototypes_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd);
39 37
 static int redata_prototypes_postload(redata_t *redata, redata_plugin_t *slot,char *filename);
40 38
 static cproto_t *cproto_getplugin(redata_t *redata);
... ...
@@ -80,8 +78,7 @@ redata_prototypes_register(redata_t *redata, redata_plugin_t *slot)
80 78
         slot->name[sizeof(slot->name)-1]='\0';
81 79
         slot->unregister=redata_prototypes_unregister;
82 80
         slot->postload=redata_prototypes_postload;
83
-        slot->add=redata_prototypes_add;
84
-        slot->unadd=redata_prototypes_unadd;
81
+        slot->add_or_unadd=redata_prototypes_add_or_unadd;
85 82
         slot->userptr=cproto;
86 83
         return(0);
87 84
 }
... ...
@@ -102,19 +99,6 @@ redata_prototypes_unregister(redata_t *redata, redata_plugin_t *slot,char *filen
102 99
 
103 100
 }
104 101
 
105
-static int
106
-redata_prototypes_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo)
107
-{
108
-        return(redata_prototypes_add_or_unadd(redata, slot, undo, 0));
109
-}
110
-
111
-static int
112
-redata_prototypes_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo)
113
-{
114
-        return(redata_prototypes_add_or_unadd(redata, slot, undo, 1));
115
-}
116
-
117
-
118 102
 static int
119 103
 redata_prototypes_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd)
120 104
 {
... ...
@@ -27,7 +27,8 @@
27 27
 #define UNSAVEDGROWSIZE (256*1024)
28 28
 
29 29
 
30
-
30
+int redata_unsaved_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
31
+int redata_unsaved_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
31 32
 static int redata_unsaved_loadquestion(redata_t *redata, redata_plugin_t *slot,char *filename);
32 33
 static int redata_unsaved_postload(redata_t *redata, redata_plugin_t *slot,char *filename);
33 34
 static int redata_unsaved_check_gen(redata_t *redata, redata_plugin_t *slot, char *filename);
... ...
@@ -55,8 +56,7 @@ redata_unsaved_register(redata_t *redata, redata_plugin_t *slot)
55 56
         slot->wipe=redata_unsaved_wipe;
56 57
         slot->postload=redata_unsaved_postload;
57 58
         slot->postsave=redata_unsaved_trunc;
58
-        slot->add=redata_unsaved_add;
59
-        slot->unadd=redata_unsaved_unadd;
59
+        slot->add_or_unadd=redata_unsaved_add_or_unadd;
60 60
         slot->commit=redata_unsaved_commit;
61 61
         slot->userptr=unsaved;
62 62
         return(0);
... ...
@@ -357,6 +357,15 @@ fprintf(stderr,"\n");
357 357
         return(0);
358 358
 }
359 359
 
360
+int
361
+redata_unsaved_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd)
362
+{
363
+        return((is_unadd==0)?
364
+          redata_unsaved_add(redata, slot, undo):
365
+          redata_unsaved_unadd(redata, slot, undo));
366
+}
367
+
368
+
360 369
 int
361 370
 redata_unsaved_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo)
362 371
 {
... ...
@@ -32,7 +32,7 @@ int redata_unsaved_truncload(redata_t *redata, redata_plugin_t *slot, char *file
32 32
 int redata_unsaved_loadappend(redata_t *redata, redata_plugin_t *slot, char *filename);
33 33
 int redata_unsaved_unlink(redata_t *redata, redata_plugin_t *slot, char *filename);
34 34
 int redata_unsaved_trunc(redata_t *redata, redata_plugin_t *slot, char *oldfilename, char *newfilename);
35
-int redata_unsaved_add(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
35
+int redata_unsaved_add_or_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo, int is_unadd);
36 36
 int redata_unsaved_unadd(redata_t *redata, redata_plugin_t *slot, undo_t *undo);
37 37
 int redata_unsaved_commit(redata_t *redata, redata_plugin_t *slot, char *filename);
38 38