Fix keyword highlighting off-by-one errors, to fix keyword highlighting

This commit is contained in:
Timothy Warren 2019-09-11 10:37:18 -04:00
parent cec958932c
commit d45911767d

View File

@ -575,7 +575,7 @@ impl Editor {
let search_range = get_slice_range(i, keyword.len(), render_len); let search_range = get_slice_range(i, keyword.len(), render_len);
let next_char_offset = i + keyword.len() + 1; let next_char_offset = i + keyword.len();
let is_end_of_line = next_char_offset >= render_len; let is_end_of_line = next_char_offset >= render_len;
let next_char = if is_end_of_line { let next_char = if is_end_of_line {
'\0' '\0'
@ -585,7 +585,7 @@ impl Editor {
if &row.render[search_range.clone()] == keyword && is_separator(next_char) { if &row.render[search_range.clone()] == keyword && is_separator(next_char) {
highlight_range(&mut row.highlight, search_range, Highlight::Keyword1); highlight_range(&mut row.highlight, search_range, Highlight::Keyword1);
i += keyword.len(); i += keyword.len() - 1;
} }
} }
@ -596,7 +596,7 @@ impl Editor {
let search_range = get_slice_range(i, keyword.len(), render_len); let search_range = get_slice_range(i, keyword.len(), render_len);
let next_char_offset = i + keyword.len() + 1; let next_char_offset = i + keyword.len();
let is_end_of_line = next_char_offset >= render_len; let is_end_of_line = next_char_offset >= render_len;
let next_char = if is_end_of_line { let next_char = if is_end_of_line {
'\0' '\0'
@ -606,7 +606,7 @@ impl Editor {
if &row.render[search_range.clone()] == keyword && is_separator(next_char) { if &row.render[search_range.clone()] == keyword && is_separator(next_char) {
highlight_range(&mut row.highlight, search_range, Highlight::Keyword2); highlight_range(&mut row.highlight, search_range, Highlight::Keyword2);
i += keyword.len(); i += keyword.len() - 1;
} }
} }
} }