Highlight secondary keywords
This commit is contained in:
parent
6a43727240
commit
10e4c7ddb8
38
src/row.rs
38
src/row.rs
@ -242,11 +242,12 @@ impl Row {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_primary_keywords(
|
fn highlight_keywords(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &mut usize,
|
index: &mut usize,
|
||||||
opts: &HighlightingOptions,
|
|
||||||
chars: &[char],
|
chars: &[char],
|
||||||
|
keywords: &[String],
|
||||||
|
hl_type: highlighting::Type,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if *index > 0 {
|
if *index > 0 {
|
||||||
#[allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
|
#[allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
|
||||||
@ -256,7 +257,7 @@ impl Row {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for word in opts.primary_keywords() {
|
for word in keywords {
|
||||||
if *index < chars.len().saturating_sub(word.len()) {
|
if *index < chars.len().saturating_sub(word.len()) {
|
||||||
#[allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
|
#[allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
|
||||||
let next_char = chars[*index + word.len()];
|
let next_char = chars[*index + word.len()];
|
||||||
@ -265,7 +266,7 @@ impl Row {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.highlight_str(index, word, chars, highlighting::Type::PrimaryKeywords) {
|
if self.highlight_str(index, &word, chars, hl_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,6 +274,34 @@ impl Row {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn highlight_primary_keywords(
|
||||||
|
&mut self,
|
||||||
|
index: &mut usize,
|
||||||
|
opts: &HighlightingOptions,
|
||||||
|
chars: &[char],
|
||||||
|
) -> bool {
|
||||||
|
self.highlight_keywords(
|
||||||
|
index,
|
||||||
|
chars,
|
||||||
|
opts.primary_keywords(),
|
||||||
|
highlighting::Type::PrimaryKeywords,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn highlight_secondary_keywords(
|
||||||
|
&mut self,
|
||||||
|
index: &mut usize,
|
||||||
|
opts: &HighlightingOptions,
|
||||||
|
chars: &[char],
|
||||||
|
) -> bool {
|
||||||
|
self.highlight_keywords(
|
||||||
|
index,
|
||||||
|
chars,
|
||||||
|
opts.secondary_keywords(),
|
||||||
|
highlighting::Type::SecondaryKeywords,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn highlight_char(
|
fn highlight_char(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &mut usize,
|
index: &mut usize,
|
||||||
@ -399,6 +428,7 @@ impl Row {
|
|||||||
if self.highlight_char(&mut index, opts, *c, &chars)
|
if self.highlight_char(&mut index, opts, *c, &chars)
|
||||||
|| self.highlight_comment(&mut index, opts, *c, &chars)
|
|| self.highlight_comment(&mut index, opts, *c, &chars)
|
||||||
|| self.highlight_primary_keywords(&mut index, &opts, &chars)
|
|| self.highlight_primary_keywords(&mut index, &opts, &chars)
|
||||||
|
|| self.highlight_secondary_keywords(&mut index, &opts, &chars)
|
||||||
|| self.highlight_string(&mut index, opts, *c, &chars)
|
|| self.highlight_string(&mut index, opts, *c, &chars)
|
||||||
|| self.highlight_number(&mut index, opts, *c, &chars)
|
|| self.highlight_number(&mut index, opts, *c, &chars)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user