From 02c58fa2bdac6d3ab02838d6a6e0c7217eb8aa11 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 22 Jan 2019 12:03:38 +0100 Subject: [PATCH] Only move the sursor if needed on search #16 --- src/search.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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);