antirez / antirez/kilo

editorFindCallback prevents search results navigation

オープン
#127 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C
スター
9.1k
フォーク
995
PR マージ指標
30日以内にマージされた PR はありません

説明

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...

```c
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;
}
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。