Skip to content

Commit

Permalink
fix: Properly emit keyboard events
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Feb 8, 2024
1 parent be10fdc commit 2fc5ad4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions crates/core/src/events/dom_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl DomEvent {
return does_event_move_cursor(self.name.as_str());
}

// Bubble all events except keyboard
pub fn should_bubble(&self) -> bool {
!matches!(self.data, DomEventData::Keyboard(_))
}

pub fn new(
node_id: NodeId,
element_id: ElementId,
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/events/events_measurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use freya_dom::{dom::DioxusDOM, prelude::FreyaDOM};

use freya_engine::prelude::*;
use freya_node_state::{Fill, Style};
use rustc_hash::FxHashMap;

pub use crate::events::{DomEvent, ElementsState, FreyaEvent};

Expand Down Expand Up @@ -81,7 +80,7 @@ pub fn measure_potential_event_listeners(
viewports: &Viewports,
fdom: &FreyaDOM,
) -> PotentialEvents {
let mut potential_events = FxHashMap::default();
let mut potential_events = PotentialEvents::default();

let layout = fdom.layout();

Expand All @@ -95,7 +94,7 @@ pub fn measure_potential_event_listeners(
let event_data = (*node_id, event.clone());
potential_events
.entry(name.clone())
.or_insert_with(|| vec![event_data.clone()])
.or_default()
.push(event_data);
} else {
let data = match event {
Expand Down Expand Up @@ -231,9 +230,10 @@ fn measure_dom_events(

let Style { background, .. } = &*node.get::<Style>().unwrap();

if background != &Fill::Color(Color::TRANSPARENT) {
if background != &Fill::Color(Color::TRANSPARENT) && !event.is_keyboard_event() {
// If the background isn't transparent,
// we must make sure that next nodes are parent of it
// This only matters for pointer-based events, and not to e.g keyboard events
child_node = Some(*node_id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/renderer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ impl<State: 'static + Clone> App<State> {
select! {
ev = self.event_receiver.recv() => {
if let Some(ev) = ev {
let bubble = ev.should_bubble();
let data = ev.data.any();
self.vdom.handle_event(&ev.name, data, ev.element_id, true);
self.vdom.handle_event(&ev.name, data, ev.element_id, bubble);

self.vdom.process_events();
}
Expand Down

0 comments on commit 2fc5ad4

Please sign in to comment.