diff --git a/packages/blitz-dom/src/document.rs b/packages/blitz-dom/src/document.rs index 331ce81a..cd6c8a27 100644 --- a/packages/blitz-dom/src/document.rs +++ b/packages/blitz-dom/src/document.rs @@ -240,7 +240,7 @@ impl DocumentLike for Document { if let Some(input_data) = text_input_data { println!("Sent text event to {}", node_id); apply_keypress_event( - &mut input_data.editor, + input_data, &mut self.font_ctx, &mut self.layout_ctx, event, diff --git a/packages/blitz-dom/src/events/keyboard.rs b/packages/blitz-dom/src/events/keyboard.rs index 38f5ec43..3b2d34c9 100644 --- a/packages/blitz-dom/src/events/keyboard.rs +++ b/packages/blitz-dom/src/events/keyboard.rs @@ -1,12 +1,12 @@ -use crate::node::TextBrush; -use parley::{FontContext, LayoutContext, PlainEditor}; +use crate::node::{TextBrush, TextInputData}; +use parley::{FontContext, LayoutContext}; use winit::{ event::{KeyEvent, Modifiers}, keyboard::{Key, NamedKey}, }; pub(crate) fn apply_keypress_event( - editor: &mut PlainEditor, + input_data: &mut TextInputData, font_ctx: &mut FontContext, layout_ctx: &mut LayoutContext, event: KeyEvent, @@ -26,6 +26,8 @@ pub(crate) fn apply_keypress_event( } }; + let is_multiline = input_data.is_multiline; + let editor = &mut input_data.editor; let mut driver = editor.driver(font_ctx, layout_ctx); match event.logical_key { #[cfg(all(feature = "clipboard", not(target_os = "android")))] @@ -142,8 +144,9 @@ pub(crate) fn apply_keypress_event( } } Key::Named(NamedKey::Enter) => { - // TODO: support multi-line text inputs - // driver.insert_or_replace_selection("\n") + if is_multiline { + driver.insert_or_replace_selection("\n"); + } } Key::Named(NamedKey::Space) => driver.insert_or_replace_selection(" "), Key::Character(s) => driver.insert_or_replace_selection(&s), diff --git a/packages/blitz-dom/src/layout/construct.rs b/packages/blitz-dom/src/layout/construct.rs index 2f1b5338..3fd0e4e1 100644 --- a/packages/blitz-dom/src/layout/construct.rs +++ b/packages/blitz-dom/src/layout/construct.rs @@ -875,6 +875,7 @@ pub(crate) fn build_inline_layout( if *tag_name == local_name!("img") || *tag_name == local_name!("svg") || *tag_name == local_name!("input") + || *tag_name == local_name!("textarea") { builder.push_inline_box(InlineBox { id: node_id as u64, diff --git a/packages/blitz-dom/src/layout/mod.rs b/packages/blitz-dom/src/layout/mod.rs index db54fc1b..92c79acd 100644 --- a/packages/blitz-dom/src/layout/mod.rs +++ b/packages/blitz-dom/src/layout/mod.rs @@ -134,7 +134,18 @@ impl LayoutPartialTree for Document { return taffy::LayoutOutput::HIDDEN; } - // todo: need to handle shadow roots by actually descending into them + // TODO: deduplicate with single-line text input + if *element_data.name.local == *"textarea" { + return compute_leaf_layout( + inputs, + &node.style, + |_known_size, _available_space| taffy::Size { + width: 300.0, + height: resolved_line_height.unwrap_or(16.0) * 4.0, + }, + ); + } + if *element_data.name.local == *"input" { match element_data.attr(local_name!("type")) { // if the input type is hidden, hide it