Skip to content

Commit

Permalink
highlight decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-streltsov committed Feb 22, 2024
1 parent f458dcd commit 6bf7fd0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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 {
Expand All @@ -180,11 +181,21 @@ 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))
|| (c == &'.' && 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;
}
self.highlighting = highlighting;
Expand Down

0 comments on commit 6bf7fd0

Please sign in to comment.