Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlighting of escaped characters #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ impl Row {
*index += 1;
if let Some(next_char) = chars.get(*index) {
if *next_char == '"' {
if let Some(prev_char) = chars.get(*index - 1) {
if *prev_char != '\\' {
break;
} else {
continue;
}
};
break;
}
} else {
Expand Down Expand Up @@ -469,6 +476,10 @@ fn is_separator(c: char) -> bool {

#[cfg(test)]
mod test_super {
use std::iter::repeat;

use crate::FileType;

use super::*;

#[test]
Expand Down Expand Up @@ -509,4 +520,23 @@ mod test_super {
assert_eq!(row.find("t", 2, SearchDirection::Forward), Some(4));
assert_eq!(row.find("t", 5, SearchDirection::Forward), Some(5));
}

#[test]
fn string_highlighting_ignores_escaped_quotes() {
let mut row = Row::from(r#""foo\"bar\"""#);
let rust_ft = FileType::from("test.rs");
let opts = rust_ft.highlighting_options();
let mut index = 0;
let chars: Vec<char> = row.string.chars().collect();
let c = chars[index];

row.highlight_string(&mut index, &opts, c, &chars);

assert_eq!(
repeat(highlighting::Type::String)
.take(12)
.collect::<Vec<highlighting::Type>>(),
row.highlighting
)
}
}