freya_core/dom/
paragraphs.rs1use std::{
2 self,
3 ops::{
4 Deref,
5 DerefMut,
6 },
7};
8
9use freya_native_core::NodeId;
10use rustc_hash::{
11 FxHashMap,
12 FxHashSet,
13};
14use uuid::Uuid;
15
16#[derive(Default, Clone)]
17pub struct ParagraphElements(FxHashMap<Uuid, FxHashSet<NodeId>>);
18
19impl ParagraphElements {
20 pub fn insert_paragraph(&mut self, node_id: NodeId, text_id: Uuid) {
21 let text_group = self.0.entry(text_id).or_default();
22
23 text_group.insert(node_id);
24 }
25
26 pub fn remove_paragraph(&mut self, node_id: NodeId, text_id: &Uuid) {
27 let text_group = self.0.get_mut(text_id);
28
29 if let Some(text_group) = text_group {
30 text_group.retain(|id| *id != node_id);
31
32 if text_group.is_empty() {
33 self.0.remove(text_id);
34 }
35 }
36 }
37}
38
39impl Deref for ParagraphElements {
40 type Target = FxHashMap<Uuid, FxHashSet<NodeId>>;
41
42 fn deref(&self) -> &Self::Target {
43 &self.0
44 }
45}
46
47impl DerefMut for ParagraphElements {
48 fn deref_mut(&mut self) -> &mut Self::Target {
49 &mut self.0
50 }
51}