Only move the sursor if needed on search #16
This commit is contained in:
parent
ae7d2b7a71
commit
02c58fa2bd
1 changed files with 9 additions and 2 deletions
11
src/search.c
11
src/search.c
|
@ -4,7 +4,7 @@
|
|||
#include <string.h> // 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);
|
||||
|
|
Loading…
Reference in a new issue