editorFindCallback prevents search results navigation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start at the editorFindCallback entry point in the kilo source and reproduce the issue by searching, then using the arrow keys to move between results. Done means both previous and next result navigation leaves the editor on the selected result instead of immediately returning to the original one.
Written by the indexing model from the issue text.
Description
Heyy, while doing the kilo guide, i stumbled across a bug with my editor, for some reason when i press the arrow keys to navigate to the previous and next search result the editor jumped to the next result (as expected) but then imediately jumps back to the previous result where we were originally (preventing search navigation)
To fix this, simply edit the editorFindCallback with the changes...
void editorFindCallback(char *query, int key) {
static int last_match = -1;
static int direction = 1;
// Empty queries reset searching from top
if (strlen(query) == 0) {
last_match = -1;
return;
}
int current;
if (key == '\r' || key == '\x1b') {
last_match = -1;
direction = 1;
return;
} else if (key == ARROW_RIGHT || key == ARROW_DOWN) {
current = last_match+1; // Search from next row
direction = 1;
} else if (key == ARROW_LEFT || key == ARROW_UP) {
current = last_match-1; // Search from previous row
direction = -1;
} else {
direction = 1;
current = last_match; // Keep search on current row with current result to terminate early
}
if (last_match == -1) direction = 1;
int i;
for (i = 0; i < E.numrows; i++) {
// Clamp current
if (current == -1) current = E.numrows - 1;
else if (current == E.numrows) current = 0;
// Immediately search without moving current positon
erow *row = &E.row[current];
char *match = strstr(row->render, query);
if (match) {
last_match = current;
E.cy = current;
E.cx = editorRowRxToCx(row, match - row->render);
E.rowoff = E.numrows;
break;
}
current += direction;
}
}
- Dominant language
- C
- Stars
- 9.1k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from antirez/kilo
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
Difficulty 1/5 Under an hour Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100