Skip to content

Commit

Permalink
Remove direct parley dependency from dioxus-blitz crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 11, 2024
1 parent 7bce94e commit c4503ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
14 changes: 14 additions & 0 deletions packages/blitz-dom/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use atomic_refcell::{AtomicRef, AtomicRefCell};
use html5ever::{local_name, LocalName, QualName};
use image::DynamicImage;
use parley::{FontContext, LayoutContext, PlainEditorOp};
use peniko::kurbo;
use selectors::matching::{ElementSelectorFlags, QuirksMode};
use slab::Slab;
Expand Down Expand Up @@ -508,6 +509,19 @@ impl TextInputData {
is_multiline,
}
}

pub fn set_text(
&mut self,
font_ctx: &mut FontContext,
layout_ctx: &mut LayoutContext<TextBrush>,
text: &str,
) {
let text = Arc::from(text);
if *self.editor.text() != *text {
self.editor
.transact(font_ctx, layout_ctx, [PlainEditorOp::SetText(text)]);
}
}
}

/// Heterogeneous data that depends on the element's type.
Expand Down
3 changes: 0 additions & 3 deletions packages/dioxus-blitz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ dioxus = { workspace = true }
dioxus-cli-config = { workspace = true, optional = true }
dioxus-devtools = { workspace = true, optional = true }

# Linebender dependencies
parley = { workspace = true }

# Windowing & Input
winit = { workspace = true }
muda = { workspace = true, features = ["serde"], optional = true }
Expand Down
17 changes: 2 additions & 15 deletions packages/dioxus-blitz/src/documents/dioxus_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
any::Any,
collections::{HashMap, HashSet},
rc::Rc,
sync::Arc,
};

use blitz_dom::{
Expand All @@ -24,7 +23,6 @@ use dioxus::{
prelude::set_event_converter,
};
use futures_util::{pin_mut, FutureExt};
use parley::PlainEditorOp;
use rustc_hash::FxHashMap;
use style::{
data::{ElementData, ElementStyles},
Expand Down Expand Up @@ -752,14 +750,7 @@ impl WriteMutations for MutationWriter<'_> {
else if let AttributeValue::Text(val) = value {
// Update text input value
if let Some(input_data) = element.text_input_data_mut() {
let val: &str = val;
if &*input_data.editor.text() != val {
input_data.editor.transact(
&mut self.doc.font_ctx,
&mut self.doc.layout_ctx,
[PlainEditorOp::SetText(Arc::from(val))],
);
}
input_data.set_text(&mut self.doc.font_ctx, &mut self.doc.layout_ctx, val);
}

// FIXME check namespace
Expand Down Expand Up @@ -789,11 +780,7 @@ impl WriteMutations for MutationWriter<'_> {
if let AttributeValue::None = value {
// Update text input value
if let Some(input_data) = element.text_input_data_mut() {
input_data.editor.transact(
&mut self.doc.font_ctx,
&mut self.doc.layout_ctx,
[PlainEditorOp::SetText(Arc::from(""))],
);
input_data.set_text(&mut self.doc.font_ctx, &mut self.doc.layout_ctx, "");
}

// FIXME: check namespace
Expand Down

0 comments on commit c4503ab

Please sign in to comment.