Browse code

Make Control+5 go to the matching parenthesis or curly bracket

Dario Rodriguez authored on 15/07/2025 15:21:43
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-	/*
1
+/*
2 2
  * recenteditor.c
3 3
  *
4 4
  * A programmers editor
... ...
@@ -1428,6 +1428,28 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":"");
1428 1428
                         re_themeset(re, 0);
1429 1429
                 if(re->quirk_duplicates)
1430 1430
                         re->ignorenkeys++;
1431
+        } else if(event->key.keysym.sym==SDLK_5 && (SDL_GetModState()&KMOD_CTRL)!=0) {
1432
+                char cursorchar[7];
1433
+                int usedcursorchar;
1434
+                long cursorpos;
1435
+                int matchingpos;
1436
+                char matchingchar;
1437
+                int mline,mcol;
1438
+                usedcursorchar=0;
1439
+                if(redata_linecol2pos(re->data,re->curline,re->curcol,&cursorpos,NULL)==0
1440
+                  && redata_getutf8char(re->data,cursorpos,cursorchar,sizeof(cursorchar),&usedcursorchar)==0
1441
+                  && usedcursorchar==1
1442
+                  && strchr("[]{}<>()",*cursorchar)!=NULL
1443
+                  && (matchingpos=re_getmatchingbracket(re,cursorpos,*cursorchar,&matchingchar))!=-1
1444
+                  && redata_pos2linecol(re->data,matchingpos,&mline,&mcol)!=-1
1445
+                ) {
1446
+                        re->command=COMMAND_GOTOLINE;
1447
+                        snprintf(re->commandbuf,sizeof(re->commandbuf),"%i:%i",mline+1,mcol+1);
1448
+                        re->commandbuf[sizeof(re->commandbuf)-1]='\0';
1449
+                        re_processcommand(re);
1450
+                }
1451
+                if(re->quirk_duplicates)
1452
+                        re->ignorenkeys++;
1431 1453
         } else if((event->key.keysym.sym==SDLK_c || event->key.keysym.sym==SDLK_x) && (SDL_GetModState()&KMOD_CTRL)!=0) {
1432 1454
                 long frompos,topos;
1433 1455
                 int coldone;
... ...
@@ -2293,6 +2315,7 @@ Recenteditor help\n\
2293 2315
  Home/End           - Go to the start/end of the line\n\
2294 2316
  Control+'0'        - Set default font size\n\
2295 2317
  Shift+Ctrl+'0'     - Set default color permutation\n\
2318
+ Control+'5'        - Go to the matching parenthesis or curly brace\n\
2296 2319
  Control+C          - Copy selection to clipboard. Will deselect selection.\n\
2297 2320
  Control+K+Command  - Block command, see below\n\
2298 2321
  Control+L          - Search next (requires a previous search with Control+Q+F)\n\