Highlight only the current search match
This commit is contained in:
parent
dc71f7f9a3
commit
600a5896d1
21
kilo.c
21
kilo.c
@ -40,7 +40,8 @@ enum editorKey {
|
||||
|
||||
enum editorHighlight {
|
||||
HL_NORMAL = 0,
|
||||
HL_NUMBER
|
||||
HL_NUMBER,
|
||||
HL_MATCH
|
||||
};
|
||||
|
||||
/*** data ***/
|
||||
@ -280,6 +281,9 @@ int editorSyntaxToColor(int hl)
|
||||
case HL_NUMBER:
|
||||
return 31;
|
||||
|
||||
case HL_MATCH:
|
||||
return 34;
|
||||
|
||||
default:
|
||||
return 37;
|
||||
}
|
||||
@ -599,6 +603,16 @@ void editorFindCallback(char *query, int key)
|
||||
static int last_match = -1;
|
||||
static int direction = 1;
|
||||
|
||||
static int saved_hl_line;
|
||||
static char *saved_hl = NULL;
|
||||
|
||||
if (saved_hl)
|
||||
{
|
||||
memcpy(E.row[saved_hl_line].hl, saved_hl, E.row[saved_hl_line].rsize);
|
||||
free(saved_hl);
|
||||
saved_hl = NULL;
|
||||
}
|
||||
|
||||
if (key == '\r' || key == '\x1b')
|
||||
{
|
||||
last_match = -1;
|
||||
@ -645,6 +659,11 @@ void editorFindCallback(char *query, int key)
|
||||
E.cy = current;
|
||||
E.cx = editorRowRxToCx(row, match - row->render);
|
||||
E.rowoff = E.numrows;
|
||||
|
||||
saved_hl_line = current;
|
||||
saved_hl = malloc(row->rsize);
|
||||
memcpy(saved_hl, row->hl, row->rsize);
|
||||
memset(&row->hl[match - row->render], HL_MATCH, strlen(query));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user