From d207cb78842cf7f78e17f3b7528e02a38544c81b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 16 Mar 2021 09:28:07 -0400 Subject: [PATCH] Properly highlight numeric literals --- src/row.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/row.rs b/src/row.rs index b71099c..9f7e61c 100644 --- a/src/row.rs +++ b/src/row.rs @@ -208,6 +208,7 @@ impl Row { } } + let mut prev_is_separator = true; let mut index = 0; while let Some(c) = chars.get(index) { if let Some(word) = word { @@ -221,12 +222,23 @@ impl Row { } } - if c.is_ascii_digit() { + let previous_highlight = if index > 0 { + highlighting + .get(index - 1) + .unwrap_or(&highlighting::Type::None) + } else { + &highlighting::Type::None + }; + + if c.is_ascii_digit() + && (prev_is_separator || previous_highlight == &highlighting::Type::Number) + { highlighting.push(highlighting::Type::Number) } else { highlighting.push(highlighting::Type::None) } + prev_is_separator = c.is_ascii_punctuation() || c.is_ascii_whitespace(); index += 1; }