Skip to content

Commit 4362a24

Browse files
authored
web_demo: make hash anchor case insensitive (emilk#5446)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> * [X] I have followed the instructions in the PR template
1 parent f28080c commit 4362a24

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

crates/egui_demo_app/src/wrap_app.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,19 @@ impl Anchor {
111111
Self::Rendering,
112112
]
113113
}
114+
115+
#[cfg(target_arch = "wasm32")]
116+
fn from_str_case_insensitive(anchor: &str) -> Option<Self> {
117+
let anchor = anchor.to_lowercase();
118+
Self::all().into_iter().find(|x| x.to_string() == anchor)
119+
}
114120
}
115121

116122
impl std::fmt::Display for Anchor {
117123
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
118-
write!(f, "{self:?}")
124+
let mut name = format!("{self:?}");
125+
name.make_ascii_lowercase();
126+
f.write_str(&name)
119127
}
120128
}
121129

@@ -263,11 +271,15 @@ impl eframe::App for WrapApp {
263271

264272
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
265273
#[cfg(target_arch = "wasm32")]
266-
if let Some(anchor) = frame.info().web_info.location.hash.strip_prefix('#') {
267-
let anchor = Anchor::all().into_iter().find(|x| x.to_string() == anchor);
268-
if let Some(v) = anchor {
269-
self.state.selected_anchor = v;
270-
}
274+
if let Some(anchor) = frame
275+
.info()
276+
.web_info
277+
.location
278+
.hash
279+
.strip_prefix('#')
280+
.and_then(Anchor::from_str_case_insensitive)
281+
{
282+
self.state.selected_anchor = anchor;
271283
}
272284

273285
#[cfg(not(target_arch = "wasm32"))]

0 commit comments

Comments
 (0)