Browse code

Make commandbuffer input to accept Control+TAB (to be able to search/substitute real tabs. Put a cursor con commandbuffer input

Dario Rodriguez authored on 20/02/2022 15:03:32
Showing 1 changed files
... ...
@@ -1302,9 +1302,18 @@ re_processkey_commandwait(re_t *re, SDL_Event *event)
1302 1302
 int
1303 1303
 re_processkey_commanddata(re_t *re, SDL_Event *event)
1304 1304
 {
1305
+        SDL_Event fakeevent;
1305 1306
         if(re==NULL || event==NULL)
1306 1307
                 return(-1); /* sanity check failed */
1307 1308
         /* special case: text editing event */
1309
+        if(event->type==SDL_KEYDOWN && event->key.keysym.sym==SDLK_TAB && (SDL_GetModState()&KMOD_CTRL)!=0) {
1310
+                /* If control+tab is pressed, insert a real tab (to be able to search for them using Control+F) */
1311
+                memset(&fakeevent,0,sizeof(SDL_Event));
1312
+                event=&fakeevent;
1313
+                event->type=SDL_TEXTINPUT;
1314
+                strncpy(event->text.text,"\t",sizeof(event->text.text));
1315
+                event->text.text[sizeof(event->text.text)-1]='\0';
1316
+        }
1308 1317
         if(event->type==SDL_TEXTINPUT) {
1309 1318
                 int len;
1310 1319
                 if(re->ignorenkeys>0) {
... ...
@@ -2118,10 +2127,12 @@ re_drawheader_command(re_t *re)
2118 2127
                 re->commandbuf[sizeof(re->commandbuf)-1]='\0';
2119 2128
                 commandlen=redata_generic_utf8len(re->command,strlen(re->command));
2120 2129
                 reui_printf(re->ui,0,0,COLOR_QUERYFG,"%s",re->command);
2130
+                commandbuflen=redata_generic_utf8len(re->commandbuf,strlen(re->commandbuf));
2121 2131
                 if(!(re->is_oldcommandbuf) || re->commandbuf[0]=='\0') {
2122 2132
                         reui_printf(re->ui,re->ui->fontwidth*(commandlen+1),0,COLOR_QUERYFG,"%s",re->commandbuf);
2133
+                        /* draw something that to indicate the end of the commandbuf (useful if commandbuf ends in spaces) */
2134
+                        reui_fill(re->ui,re->ui->fontwidth*(commandlen+1+commandbuflen)+1,re->ui->fontheight/2,1,re->ui->fontheight/2,COLOR_QUERYFG);
2123 2135
                 } else {
2124
-                        commandbuflen=redata_generic_utf8len(re->commandbuf,strlen(re->commandbuf));
2125 2136
                         reui_fillrounded(re->ui,re->ui->fontwidth*(commandlen+1)-re->ui->fontwidth/2,0,re->ui->fontwidth*(commandbuflen+1)+1,re->ui->fontheight,COLOR_QUERYBGOLD);
2126 2137
                         reui_printf(re->ui,re->ui->fontwidth*(commandlen+1),0,COLOR_QUERYFGOLD,"%s",re->commandbuf);
2127 2138
                 }