Browse code

fix: correctly set the boundaries of data to move on Ctrl+K+C/Ctrl+K+V

Dario Rodriguez authored on 02/06/2021 05:31:03
Showing 2 changed files
... ...
@@ -2098,12 +2098,20 @@ redata_linecol2pos(redata_t *redata, int line, int colrequest, long *pos, int *c
2098 2098
         if(i>chunk->useddata)
2099 2099
                 return(-1); /* line not found */
2100 2100
         realstart=chunkpos+i;
2101
-        /* find col */
2101
+        /* trivial case: col 0 */
2102
+        if(colrequest==0) {
2103
+                if(coldone!=NULL)
2104
+                        *coldone=0;
2105
+                if(pos!=NULL)
2106
+                        *pos=realstart;
2107
+                return(0);
2108
+        }
2109
+        /* find col, stopping at the start of next char */
2102 2110
         for(n=-1,curpos=realstart;n<colrequest;) {
2103 2111
                 if(redata_line_rawinfo(redata,curpos,&startpos,&ptr,&len,NULL)==-1 || len==0)
2104 2112
                         return(-1); /* couldn't get current line data */
2105 2113
                 done=0;
2106
-                for(i=0;i<len && n<colrequest;i++) {
2114
+                for(i=0;i<len && n<colrequest;i++,curpos++) {
2107 2115
                         if(ptr[i]=='\n') {
2108 2116
                                 done=1;
2109 2117
                                 break;
... ...
@@ -2113,7 +2121,6 @@ redata_linecol2pos(redata_t *redata, int line, int colrequest, long *pos, int *c
2113 2121
                                         break;
2114 2122
                         }
2115 2123
                 }
2116
-                curpos=startpos+i;
2117 2124
                 if(done)
2118 2125
                         break;
2119 2126
         }
... ...
@@ -986,9 +986,11 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":"");
986 986
                         re_sel_toggle(re);
987 987
                 if(SDL_HasClipboardText())
988 988
                         re_selectbuf_replace(re,SDL_GetClipboardText());
989
-#if 1
990
-fprintf(stderr,"SELECTBUF:\"%s\" len:%i\n",re->selectbuf,(int)strlen(re->selectbuf));
991
-#endif
989
+                if(SDL_HasClipboardText()) {
990
+                        char *ptr;
991
+                        re_selectbuf_replace(re,(ptr=SDL_GetClipboardText()));
992
+                        SDL_free(ptr),ptr=NULL;
993
+                }
992 994
                 if(re->usedselectbuf>0)
993 995
                         re_textinsert(re, re->selectbuf,re->usedselectbuf);
994 996
                 re->ignorenkeys++;