...
|
...
|
@@ -107,7 +107,9 @@ int re_sel_toggle(re_t *re);
|
107
|
107
|
int re_sel_lincolisinside(re_t *re, int line, int col);
|
108
|
108
|
int re_sel_lincolisbefore(re_t *re, int line, int col);
|
109
|
109
|
int re_sel_lincolisafter(re_t *re, int line, int col);
|
|
110
|
+int re_selectbuf_resize(re_t *re,long size);
|
110
|
111
|
int re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces);
|
|
112
|
+int re_selectbuf_replace(re_t *re,char *newdata);
|
111
|
113
|
int re_rtrim(re_t *re, long curpos, int *trimmed);
|
112
|
114
|
long re_getmatchingbracket(re_t *re,long posini, char originalchar, char *matchingchar);
|
113
|
115
|
int re_drawheader_editing(re_t *re);
|
...
|
...
|
@@ -708,6 +710,7 @@ fprintf(stderr,"re_processkey(): received Control+%c\n",is_cut?'x':'c');
|
708
|
710
|
&& redata_linecol2pos(re->data,re->sellinefrom,re->selcolfrom,&frompos,NULL)==0
|
709
|
711
|
&& redata_linecol2pos(re->data,re->sellineto,re->selcolto,&topos,&coldone)==0) {
|
710
|
712
|
re_selectbuf_fill(re,frompos,topos-frompos,re->selcolto-coldone);
|
|
713
|
+ SDL_SetClipboardText(re->selectbuf);
|
711
|
714
|
if(is_cut) {
|
712
|
715
|
redata_undo_groupinit(re->data,NULL);
|
713
|
716
|
redata_op_del(re->data,frompos,topos-frompos,NULL);
|
...
|
...
|
@@ -726,6 +729,8 @@ fprintf(stderr,"re_processkey(): received Control+v\n");
|
726
|
729
|
/* CUA92-style paste (ctrl+v)*/
|
727
|
730
|
if(re->selactive)
|
728
|
731
|
re_sel_toggle(re);
|
|
732
|
+ if(SDL_HasClipboardText())
|
|
733
|
+ re_selectbuf_replace(re,SDL_GetClipboardText());
|
729
|
734
|
if(re->usedselectbuf>0) {
|
730
|
735
|
redata_undo_groupinit(re->data,NULL);
|
731
|
736
|
redata_op_add(re->data,re->cursorpos,re->selectbuf,re->usedselectbuf,NULL);
|
...
|
...
|
@@ -765,9 +770,6 @@ re_processkey_commandwait(re_t *re, SDL_Event *event)
|
765
|
770
|
re->commandbuf[0]='\0';
|
766
|
771
|
re->headerdirty=1;
|
767
|
772
|
} else if(re->command_first_key=='k' && event->key.keysym.sym==SDLK_h) {
|
768
|
|
-#warning #error TODO: IF Ctrl+C, get a buffer of the right size into re (re->selectbuf), use redata_extract() to get those bytes into the buffer
|
769
|
|
-#warning #error TODO: IF Ctrl+X, do as in Ctrl+X, but delete the bytes from redata afterwards
|
770
|
|
-#warning #error TODO: IF Ctrl+V, insert the bytes in re->selectbuf into the curent cursor pos
|
771
|
773
|
re_sel_toggle(re);
|
772
|
774
|
re->command=NULL;
|
773
|
775
|
re->headerdirty=1;
|
...
|
...
|
@@ -1214,6 +1216,24 @@ re_sel_lincolisafter(re_t *re, int line, int col)
|
1214
|
1216
|
return(0);
|
1215
|
1217
|
}
|
1216
|
1218
|
|
|
1219
|
+int
|
|
1220
|
+re_selectbuf_resize(re_t *re,long size)
|
|
1221
|
+{
|
|
1222
|
+ long newsize;
|
|
1223
|
+ char *newptr;
|
|
1224
|
+ if(re==NULL || size<0)
|
|
1225
|
+ return(-1); /* sanity check failed */
|
|
1226
|
+ if(size==0)
|
|
1227
|
+ return(0); /* nothing to do */
|
|
1228
|
+ newsize=(size+SELECTBUFBLOCK-1)/SELECTBUFBLOCK;
|
|
1229
|
+ newsize*=SELECTBUFBLOCK;
|
|
1230
|
+ if((newptr=realloc(re->selectbuf,newsize))==NULL)
|
|
1231
|
+ return(-1);
|
|
1232
|
+ re->selectbuf=newptr;
|
|
1233
|
+ re->sizeselectbuf=newsize;
|
|
1234
|
+ return(0);
|
|
1235
|
+}
|
|
1236
|
+
|
1217
|
1237
|
int
|
1218
|
1238
|
re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces)
|
1219
|
1239
|
{
|
...
|
...
|
@@ -1222,15 +1242,9 @@ re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces)
|
1222
|
1242
|
if(re==NULL || size<0 || nadditionalspaces<0 || (frompos+size)>redata_getused(re->data) || redata_getposptr(re->data,frompos,&nchunk,&off)!=0)
|
1223
|
1243
|
return(-1); /* sanity check failed */
|
1224
|
1244
|
re->usedselectbuf=0;
|
1225
|
|
- if((size+nadditionalspaces)>re->sizeselectbuf) {
|
1226
|
|
- long newsize;
|
1227
|
|
- char *newptr;
|
1228
|
|
- newsize=(size+nadditionalspaces+SELECTBUFBLOCK-1)/SELECTBUFBLOCK;
|
1229
|
|
- newsize*=SELECTBUFBLOCK;
|
1230
|
|
- if((newptr=realloc(re->selectbuf,newsize))==NULL)
|
1231
|
|
- return(-1);
|
1232
|
|
- re->selectbuf=newptr;
|
1233
|
|
- re->sizeselectbuf=newsize;
|
|
1245
|
+ if((size+nadditionalspaces+1)>re->sizeselectbuf
|
|
1246
|
+ && re_selectbuf_resize(re,size+nadditionalspaces+1)!=0) {
|
|
1247
|
+ return(-1); /* insuf. mem. */
|
1234
|
1248
|
}
|
1235
|
1249
|
for(n=0;n<size && nchunk<re->data->sizechunks;nchunk++,off=0) {
|
1236
|
1250
|
avail=re->data->chunks[nchunk]->useddata-off;
|
...
|
...
|
@@ -1246,6 +1260,24 @@ re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces)
|
1246
|
1260
|
memset(re->selectbuf+re->usedselectbuf,' ',nadditionalspaces);
|
1247
|
1261
|
re->usedselectbuf+=nadditionalspaces;
|
1248
|
1262
|
}
|
|
1263
|
+ re->selectbuf[re->usedselectbuf]='\0';
|
|
1264
|
+ return(0);
|
|
1265
|
+}
|
|
1266
|
+
|
|
1267
|
+int
|
|
1268
|
+re_selectbuf_replace(re_t *re,char *newdata)
|
|
1269
|
+{
|
|
1270
|
+ long size;
|
|
1271
|
+ if(re==NULL || newdata==NULL)
|
|
1272
|
+ return(-1);
|
|
1273
|
+ size=strlen(newdata);
|
|
1274
|
+ if((size+1)>re->sizeselectbuf
|
|
1275
|
+ && re_selectbuf_resize(re,size+1)!=0) {
|
|
1276
|
+ return(-1); /* insuf. mem. */
|
|
1277
|
+ }
|
|
1278
|
+ memcpy(re->selectbuf,newdata,size);
|
|
1279
|
+ re->usedselectbuf=size;
|
|
1280
|
+ re->selectbuf[re->usedselectbuf]='\0';
|
1249
|
1281
|
return(0);
|
1250
|
1282
|
}
|
1251
|
1283
|
|
...
|
...
|
@@ -1547,7 +1579,6 @@ fprintf(stderr,"\n");
|
1547
|
1579
|
if(utf8charlen==1 && strchr("[]{}<>()",*curptr)!=NULL)
|
1548
|
1580
|
matchingpos=re_getmatchingbracket(re,re->cursorpos,*curptr,&matchingchar);
|
1549
|
1581
|
}
|
1550
|
|
-#warning TODO: Select(control+k+b/control+k+k/...)
|
1551
|
1582
|
}
|
1552
|
1583
|
}
|
1553
|
1584
|
if(row==(re->curline-re->originline) && !drawn_cursor)
|