this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Search from cursor position + go to the top if ended going down with … (#2671)

* search from cursor position + go to the top if ended going down with arrow keys and viceversa

* remove extra whitespaces that I included

authored by

Miguel and committed by
GitHub
7a6f51d9 1b359351

+28 -11
+28 -11
src/studio/editors/code.c
··· 3249 3249 3250 3250 static void textFindTick(Code* code) 3251 3251 { 3252 - 3253 - 3254 3252 if(enterWasPressed(code->studio)) setCodeMode(code, TEXT_EDIT_MODE); 3255 3253 else if(keyWasPressed(code->studio, tic_key_up) 3256 3254 || keyWasPressed(code->studio, tic_key_down) 3257 3255 || keyWasPressed(code->studio, tic_key_left) 3258 3256 || keyWasPressed(code->studio, tic_key_right)) 3259 3257 { 3260 - if(*code->popup.text) 3261 - { 3262 - bool reverse = keyWasPressed(code->studio, tic_key_up) || keyWasPressed(code->studio, tic_key_left); 3263 - char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; 3264 - char* from = reverse ? MIN(code->cursor.position, code->cursor.selection) : MAX(code->cursor.position, code->cursor.selection); 3265 - char* pos = func(code->src, from, code->popup.text); 3266 - updateFindCode(code, pos); 3267 - } 3258 + if(*code->popup.text) 3259 + { 3260 + bool reverse = keyWasPressed(code->studio, tic_key_up) || keyWasPressed(code->studio, tic_key_left); 3261 + char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; 3262 + char* from = reverse ? MIN(code->cursor.position, code->cursor.selection) : MAX(code->cursor.position, code->cursor.selection); 3263 + char* pos = func(code->src, from, code->popup.text); 3264 + if (!pos && !reverse) 3265 + { 3266 + // If not found in forward search, try from the beginning 3267 + pos = func(code->src, code->src, code->popup.text); 3268 + } 3269 + else if (!pos && reverse) 3270 + { 3271 + // If not found in reverse search, try from the end 3272 + pos = func(code->src, code->src + strlen(code->src), code->popup.text); 3273 + } 3274 + updateFindCode(code, pos); 3275 + } 3268 3276 } 3269 3277 else if(keyWasPressed(code->studio, tic_key_backspace)) 3270 3278 { ··· 3282 3290 { 3283 3291 char str[] = {sym , 0}; 3284 3292 strcat(code->popup.text, str); 3285 - updateFindCode(code, strstr(code->src, code->popup.text)); 3293 + 3294 + // Start searching after the current cursor position 3295 + char* pos = strstr(code->cursor.position, code->popup.text); 3296 + if (!pos) 3297 + { 3298 + // If no match, search from the beginning 3299 + pos = strstr(code->src, code->popup.text); 3300 + } 3301 + 3302 + updateFindCode(code, pos); 3286 3303 } 3287 3304 } 3288 3305