Skip to content

Commit

Permalink
eframe web fix: save() on "blur" event
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jul 1, 2024
1 parent 051b90b commit f3a0ac1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl AppRunner {
pub fn update_focus(&mut self) {
let has_focus = self.has_focus();
if self.input.raw.focused != has_focus {
// log::debug!("{} Focus changed to {has_focus}", self.canvas().id());
log::trace!("{} Focus changed to {has_focus}", self.canvas().id());
self.input.set_focus(has_focus);

if !has_focus {
Expand Down
7 changes: 6 additions & 1 deletion crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ fn install_blur_focus(runner_ref: &WebRunner, target: &EventTarget) -> Result<()
// so we also poll the focus state each frame in `AppRunner::logic`.
for event_name in ["blur", "focus"] {
let closure = move |_event: web_sys::MouseEvent, runner: &mut AppRunner| {
// log::debug!("{} {event_name:?}", runner.canvas().id());
log::trace!("{} {event_name:?}", runner.canvas().id());
runner.update_focus();

if event_name == "blur" {
// This might be a good time to save the state
runner.save();
}
};

runner_ref.add_event_listener(target, event_name, closure)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/web/text_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl TextAgent {
return;
}

// log::debug!("Focusing text agent");
log::trace!("Focusing text agent");

if let Err(err) = self.input.focus() {
log::error!("failed to set focus: {}", super::string_from_js_value(&err));
Expand All @@ -160,7 +160,7 @@ impl TextAgent {
return;
}

// log::debug!("Blurring text agent");
log::trace!("Blurring text agent");

if let Err(err) = self.input.blur() {
log::error!("failed to set focus: {}", super::string_from_js_value(&err));
Expand Down

0 comments on commit f3a0ac1

Please sign in to comment.