Skip to content

Commit 59b71e8

Browse files
committed
Fix expression editor syntax highlighting for nested strings, fixed quirky CSS precendence issue
1 parent 93959e3 commit 59b71e8

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

rust/perspective-viewer/src/rust/components/style/style_cache.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ impl StyleCache {
6666
let style = Self::into_style(name, css, self.0.is_shadow);
6767
let first = map.values().next().cloned();
6868
map.insert(name, style.clone());
69-
if let Some(x) = first {
69+
let mut values = map.values();
70+
if let Some(mut x) = first {
71+
while let Some(y) = values.next() && y.get_attribute("name").as_deref() < Some(name) {
72+
x = y.clone();
73+
}
74+
7075
x.parent_node()
7176
.unwrap_or_else(|| x.get_root_node())
72-
.insert_before(&style, Some(&x))
77+
.insert_before(&style, x.next_sibling().as_ref())
7378
.unwrap();
7479
}
7580
}

rust/perspective-viewer/src/rust/exprtk/tokenize/string.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ fn parse_escaped_char(input: &str) -> IResult<&str, char> {
4343
)(input)
4444
}
4545

46-
fn parse_literal(input: &str) -> IResult<&str, &str> {
47-
let not_quote_slash = is_not("\'\"\\");
46+
fn parse_literal(sep: char, input: &str) -> IResult<&str, &str> {
47+
let not_quote_slash = if sep == '\'' {
48+
is_not("\'\\")
49+
} else {
50+
is_not("\"\\")
51+
};
52+
4853
verify(not_quote_slash, |s: &str| !s.is_empty())(input)
4954
}
5055

@@ -65,17 +70,24 @@ impl StringFragment {
6570
}
6671
}
6772

68-
fn parse_fragment(input: &str) -> IResult<&str, StringFragment> {
73+
fn parse_fragment(sep: char, input: &str) -> IResult<&str, StringFragment> {
6974
alt((
70-
map(parse_literal, |x| StringFragment::Literal(x.len())),
75+
map(
76+
|x| parse_literal(sep, x),
77+
|x| StringFragment::Literal(x.len()),
78+
),
7179
map(parse_escaped_char, |_| StringFragment::EscapedChar),
7280
value(StringFragment::EscapedWS, preceded(char('\\'), multispace1)),
7381
))(input)
7482
}
7583

7684
pub fn parse_string_literal(sep: char) -> impl for<'a> Fn(&'a str) -> IResult<&'a str, &'a str> {
7785
move |input| {
78-
let build_string = fold_many0(parse_fragment, || 2, |len, frag| frag.len() + len);
86+
let build_string = fold_many0(
87+
|x| parse_fragment(sep, x),
88+
|| 2,
89+
|len, frag| frag.len() + len,
90+
);
7991
let offset = delimited(char(sep), build_string, char(sep));
8092
map(offset, |x| &input[..x])(input)
8193
}

0 commit comments

Comments
 (0)