Browse code

Control+Click in a printout goes in the editor window to the body of the function name under the mouse (just like control-clicking does in the editor window)

Dario Rodriguez authored on 30/09/2025 16:27:15
Showing 1 changed files
... ...
@@ -308,6 +308,7 @@ redata_t *re_getfunclisting(re_t *re);
308 308
 int re_funclistingxy2line(re_t *re,int mx,int my);
309 309
 int re_wheelaccel(re_t *re, int rawamount);
310 310
 int re_themeset(re_t *re, int ntheme);
311
+int re_gotofunctiondefinition(re_t *re, int line, int col);
311 312
 int re_socketinit(re_t *re, char *filename);
312 313
 void re_socketfree(re_t *re);
313 314
 int re_socketnewclient(re_t *re, int alreadyacceptedfd);
... ...
@@ -558,11 +559,18 @@ fprintf(stderr,"RENDER\n");
558 559
                                                         newposx=(newposx<0)?0:newposx;
559 560
                                                         newposy=my/printout->ui->fontheight;
560 561
                                                         if(redata_linecol2pos(re->data, printout->originline+newposy, printout->origincol+newposx,&tmppos,NULL)==0) {
561
-                                                                re->curline=printout->originline+newposy;
562
-                                                                re->curcol=printout->origincol+newposx;
563
-                                                                re->headerdirty=1;
564
-                                                                re->contentsdirty=1;
565
-                                                                re_fixorigin_center(re);                                                        }
562
+                                                                if((SDL_GetModState()&KMOD_CTRL)==0) {
563
+                                                                        /* go to this printout clicked-pos in the editor */
564
+                                                                        re->curline=printout->originline+newposy;
565
+                                                                        re->curcol=printout->origincol+newposx;
566
+                                                                        re->headerdirty=1;
567
+                                                                        re->contentsdirty=1;
568
+                                                                        re_fixorigin_center(re);
569
+                                                                } else {
570
+                                                                        /* control+click: search function definition (in the editor window, not in the printout) */
571
+                                                                        re_gotofunctiondefinition(re, printout->originline+newposy, printout->origincol+newposx);
572
+                                                                }
573
+                                                        }
566 574
                                                 }
567 575
                                                 break;
568 576
 
... ...
@@ -715,50 +723,12 @@ fprintf(stderr,"Resizing from %ix%i to %ix%i...\n",re->ui->w,re->ui->h,(int)even
715 723
                                                         redata_free(re->funclisting),re->funclisting=NULL;
716 724
                                                         re->contentsdirty=1;
717 725
                                                 } else if(event.type==SDL_MOUSEBUTTONUP && (SDL_GetModState()&KMOD_CTRL) && my>=re->y) {
718
-                                                        /* control+click: search function definition */
719 726
                                                         int newposx,newposy;
720
-                                                        long tmppos;
721 727
                                                         newposx=(mx-re->x-(re->showlinenumbers?(re->ui->fontwidth*7+re->ui->fontwidth/2):0))/re->ui->fontwidth;
722 728
                                                         newposx=(newposx<0)?0:newposx;
723 729
                                                         newposy=(my-re->y)/re->ui->fontheight;
724
-                                                        if(redata_linecol2pos(re->data, re->originline+newposy, re->origincol+newposx,&tmppos,NULL)==0) {
725
-                                                                char searchbuf[1024]; /* magic number: max. size of string to search (truncated if bigger) */
726
-                                                                int usedsearchbuf;
727
-                                                                long curpos;
728
-                                                                redata_t *funclisting;
729
-                                                                /* extract word, generate funclisting, search word in funclisting */
730
-                                                                funclisting=NULL;
731
-                                                                if(re_extractword2buf(re, re->data, tmppos, searchbuf, sizeof(searchbuf), &usedsearchbuf)==0
732
-                                                                   && (funclisting=re_getfunclisting(re))!=NULL
733
-                                                                   && (curpos=redata_searchforward(funclisting,0,searchbuf,usedsearchbuf))!=-1) {
734
-                                                                        char linebuf[32],*cmdend;
735
-                                                                        int funcline,funccol;
736
-                                                                        if(redata_pos2linecol(funclisting,curpos,&funcline,&funccol)==0
737
-                                                                           && redata_line_getstartstrtrimmed(funclisting,funcline,linebuf,sizeof(linebuf)," ")==0) {
738
-                                                                                int oldline;
739
-                                                                                if((cmdend=strchr(linebuf,':'))!=NULL)
740
-                                                                                        *cmdend='\0';
741
-                                                                                re->command=COMMAND_GOTOLINE;
742
-                                                                                strncpy(re->commandbuf,linebuf,sizeof(re->commandbuf));
743
-                                                                                re->commandbuf[sizeof(re->commandbuf)-1]='\0';
744
-                                                                                oldline=re->curline;
745
-                                                                                re_processcommand(re);
746
-                                                                                if(oldline!=re->curline) {
747
-                                                                                        /* position the cursor near the top of the window */
748
-                                                                                        re->originline=re->curline-3;
749
-                                                                                        re->originline=(re->originline<0)?0:re->originline;
750
-                                                                                }
751
-                                                                                /* position the cursor at the start of the line */
752
-                                                                                re->origincol=0;
753
-                                                                                re->curcol=0;
754
-                                                                                /* redraw */
755
-                                                                                re->contentsdirty=1;
756
-                                                                        }
757
-                                                                        redata_free(re->funclisting),re->funclisting=NULL;
758
-                                                                }
759
-                                                                if(funclisting!=NULL)
760
-                                                                        redata_free(funclisting),funclisting=NULL;
761
-                                                        }
730
+                                                        /* control+click: search function definition */
731
+                                                        re_gotofunctiondefinition(re, re->originline+newposy, re->origincol+newposx);
762 732
                                                 } else if(event.type==SDL_MOUSEMOTION && re->funclisting!=NULL) {
763 733
                                                         if(mx<re->ui->fontwidth*10) {
764 734
                                                                 /* scroll */
... ...
@@ -3148,6 +3118,53 @@ re_themeset(re_t *re, int ntheme)
3148 3118
         return(0);
3149 3119
 }
3150 3120
 
3121
+int
3122
+re_gotofunctiondefinition(re_t *re, int line, int col)
3123
+{
3124
+        long tmppos;
3125
+        if(re==NULL)
3126
+                return(-1);
3127
+        if(redata_linecol2pos(re->data, line, col,&tmppos,NULL)==0) {
3128
+                char searchbuf[1024]; /* magic number: max. size of string to search (truncated if bigger) */
3129
+                int usedsearchbuf;
3130
+                long curpos;
3131
+                redata_t *funclisting;
3132
+                /* extract word, generate funclisting, search word in funclisting */
3133
+                funclisting=NULL;
3134
+                if(re_extractword2buf(re, re->data, tmppos, searchbuf, sizeof(searchbuf), &usedsearchbuf)==0
3135
+                   && (funclisting=re_getfunclisting(re))!=NULL
3136
+                   && (curpos=redata_searchforward(funclisting,0,searchbuf,usedsearchbuf))!=-1) {
3137
+                        char linebuf[32],*cmdend;
3138
+                        int funcline,funccol;
3139
+                        if(redata_pos2linecol(funclisting,curpos,&funcline,&funccol)==0
3140
+                           && redata_line_getstartstrtrimmed(funclisting,funcline,linebuf,sizeof(linebuf)," ")==0) {
3141
+                                int oldline;
3142
+                                if((cmdend=strchr(linebuf,':'))!=NULL)
3143
+                                        *cmdend='\0';
3144
+                                re->command=COMMAND_GOTOLINE;
3145
+                                strncpy(re->commandbuf,linebuf,sizeof(re->commandbuf));
3146
+                                re->commandbuf[sizeof(re->commandbuf)-1]='\0';
3147
+                                oldline=re->curline;
3148
+                                re_processcommand(re);
3149
+                                if(oldline!=re->curline) {
3150
+                                        /* position the cursor near the top of the window */
3151
+                                        re->originline=re->curline-3;
3152
+                                        re->originline=(re->originline<0)?0:re->originline;
3153
+                                }
3154
+                                /* position the cursor at the start of the line */
3155
+                                re->origincol=0;
3156
+                                re->curcol=0;
3157
+                                /* redraw */
3158
+                                re->contentsdirty=1;
3159
+                        }
3160
+                        redata_free(re->funclisting),re->funclisting=NULL;
3161
+                }
3162
+                if(funclisting!=NULL)
3163
+                        redata_free(funclisting),funclisting=NULL;
3164
+        }
3165
+        return(0);
3166
+}
3167
+
3151 3168
 int
3152 3169
 re_socketinit(re_t *re,char *filename)
3153 3170
 {