From 10e4c7ddb87cf40114cff4d74108c0a6070e2d47 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 16 Mar 2021 12:40:02 -0400 Subject: [PATCH] Highlight secondary keywords --- src/row.rs | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/row.rs b/src/row.rs index d6afc08..f2133eb 100644 --- a/src/row.rs +++ b/src/row.rs @@ -242,11 +242,12 @@ impl Row { true } - fn highlight_primary_keywords( + fn highlight_keywords( &mut self, index: &mut usize, - opts: &HighlightingOptions, chars: &[char], + keywords: &[String], + hl_type: highlighting::Type, ) -> bool { if *index > 0 { #[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()) { #[allow(clippy::indexing_slicing, clippy::integer_arithmetic)] 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; } } @@ -273,6 +274,34 @@ impl Row { 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( &mut self, index: &mut usize, @@ -399,6 +428,7 @@ impl Row { if self.highlight_char(&mut index, opts, *c, &chars) || self.highlight_comment(&mut index, opts, *c, &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_number(&mut index, opts, *c, &chars) { @@ -415,4 +445,4 @@ impl Row { fn is_separator(c: char) -> bool { c.is_ascii_punctuation() || c.is_ascii_whitespace() -} \ No newline at end of file +}