Properly highlight numeric literals

This commit is contained in:
Timothy Warren 2021-03-16 09:28:07 -04:00
parent 872253edc2
commit d207cb7884

View File

@ -208,6 +208,7 @@ impl Row {
} }
} }
let mut prev_is_separator = true;
let mut index = 0; let mut index = 0;
while let Some(c) = chars.get(index) { while let Some(c) = chars.get(index) {
if let Some(word) = word { 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) highlighting.push(highlighting::Type::Number)
} else { } else {
highlighting.push(highlighting::Type::None) highlighting.push(highlighting::Type::None)
} }
prev_is_separator = c.is_ascii_punctuation() || c.is_ascii_whitespace();
index += 1; index += 1;
} }