Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e0bf89f

Browse files
Merge pull request #74 from Muscraft/one-past
fix: Allow highlighting one past end
2 parents 6a1ed2a + bc5398f commit e0bf89f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

‎src/renderer/display_list.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,15 @@ fn format_body(
934934
) -> Vec<DisplayLine<'_>> {
935935
let source_len = slice.source.chars().count();
936936
if let Some(bigger) = slice.annotations.iter().find_map(|x| {
937-
if source_len < x.range.1 {
937+
// Allow highlighting one past the last character in the source.
938+
if source_len + 1 < x.range.1 {
938939
Some(x.range)
939940
} else {
940941
None
941942
}
942943
}) {
943944
panic!(
944-
"SourceAnnotation range `{:?}` is bigger than source length `{}`",
945+
"SourceAnnotation range `{:?}` is beyond the end of buffer `{}`",
945946
bigger, source_len
946947
)
947948
}
@@ -1479,7 +1480,7 @@ mod tests {
14791480
footer: vec![],
14801481
slices: vec![snippet::Slice {
14811482
annotations: vec![snippet::SourceAnnotation {
1482-
range: (0, source.len() + 1),
1483+
range: (0, source.len() + 2),
14831484
label,
14841485
annotation_type: snippet::AnnotationType::Error,
14851486
}],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[snippet.title]
2+
label = "expected `.`, `=`"
3+
annotation_type = "Error"
4+
5+
[[snippet.slices]]
6+
source = "asdf"
7+
line_start = 1
8+
origin = "Cargo.toml"
9+
[[snippet.slices.annotations]]
10+
label = ""
11+
annotation_type = "Error"
12+
range = [4, 5]

‎tests/fixtures/no-color/one_past.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: expected `.`, `=`
2+
--> Cargo.toml:1:5
3+
|
4+
1 | asdf
5+
| ^
6+
|

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /