Skip to content

Commit 6bf7fd0

Browse files
highlight decimal numbers
1 parent f458dcd commit 6bf7fd0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/row.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl Row {
168168
}
169169
}
170170

171+
let mut prev_is_separator = true;
171172
let mut index = 0;
172173
while let Some(c) = chars.get(index) {
173174
if let Some(word) = word {
@@ -180,11 +181,21 @@ impl Row {
180181
}
181182
}
182183

183-
if c.is_ascii_digit() {
184+
let previous_highlight = if index > 0 {
185+
highlighting.get(index - 1).unwrap_or(&highlighting::Type::None)
186+
} else {
187+
&highlighting::Type::None
188+
};
189+
190+
if (c.is_ascii_digit()
191+
&& (prev_is_separator || previous_highlight == &highlighting::Type::Number))
192+
|| (c == &'.' && previous_highlight == &highlighting::Type::Number)
193+
{
184194
highlighting.push(highlighting::Type::Number);
185195
} else {
186196
highlighting.push(highlighting::Type::None);
187197
}
198+
prev_is_separator = c.is_ascii_punctuation() || c.is_ascii_whitespace();
188199
index += 1;
189200
}
190201
self.highlighting = highlighting;

0 commit comments

Comments
 (0)