diff --git a/src/search.c b/src/search.c index 652a13f..520423d 100644 --- a/src/search.c +++ b/src/search.c @@ -4,7 +4,7 @@ #include // for memcpy, memset, strlen, strstr #include "fn.h" // for E, editorConfig, erow, editorPrompt, editorHighl... #include "row.h" // for editorRowRxToCx -#include "hl.h" +#include "hl.h" // for editorSelectSyntaxHighlight void editorSearchCallback(char *query, int key) { @@ -23,6 +23,7 @@ void editorSearchCallback(char *query, int key) { if (key == '\r' || key == '\x1b') { last_match = -1; direction = 1; + // Clean up the syntax highlighting editorSelectSyntaxHighlight(); return; } else if (key == ARROW_RIGHT || key == ARROW_DOWN) { @@ -49,7 +50,13 @@ void editorSearchCallback(char *query, int key) { last_match = current; E.cy = current; E.cx = editorRowRxToCx(row, match - row->render); // Substract pointers here - E.rowoff = E.numrows; + // Reposition the cursor if needed + if (E.cy < E.rowoff) { + E.rowoff = E.cy; + } + if (E.cy >= E.rowoff + E.screenrows) { + E.rowoff = E.cy - E.screenrows + 1; + } saved_hl_line = current; saved_hl = malloc(row->rsize);