Only move the sursor if needed on search #16

This commit is contained in:
Aaron Fischer 2019-01-22 12:03:38 +01:00
parent ae7d2b7a71
commit 02c58fa2bd

View file

@ -4,7 +4,7 @@
#include <string.h> // for memcpy, memset, strlen, strstr #include <string.h> // for memcpy, memset, strlen, strstr
#include "fn.h" // for E, editorConfig, erow, editorPrompt, editorHighl... #include "fn.h" // for E, editorConfig, erow, editorPrompt, editorHighl...
#include "row.h" // for editorRowRxToCx #include "row.h" // for editorRowRxToCx
#include "hl.h" #include "hl.h" // for editorSelectSyntaxHighlight
void editorSearchCallback(char *query, int key) { void editorSearchCallback(char *query, int key) {
@ -23,6 +23,7 @@ void editorSearchCallback(char *query, int key) {
if (key == '\r' || key == '\x1b') { if (key == '\r' || key == '\x1b') {
last_match = -1; last_match = -1;
direction = 1; direction = 1;
// Clean up the syntax highlighting
editorSelectSyntaxHighlight(); editorSelectSyntaxHighlight();
return; return;
} else if (key == ARROW_RIGHT || key == ARROW_DOWN) { } else if (key == ARROW_RIGHT || key == ARROW_DOWN) {
@ -49,7 +50,13 @@ void editorSearchCallback(char *query, int key) {
last_match = current; last_match = current;
E.cy = current; E.cy = current;
E.cx = editorRowRxToCx(row, match - row->render); // Substract pointers here 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_line = current;
saved_hl = malloc(row->rsize); saved_hl = malloc(row->rsize);