MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / process_text_input_char

Method process_text_input_char

src/engine.rs:5980–6016  ·  view source on GitHub ↗

Process a character input event for the focused text input. Returns true if the character was consumed by a text input.

(&mut self, ch: char)

Source from the content-addressed store, hash-verified

5978 /// Process a character input event for the focused text input.
5979 /// Returns true if the character was consumed by a text input.
5980 pub fn process_text_input_char(&mut self, ch: char) -> bool {
5981 if !self.is_text_input_focused() {
5982 return false;
5983 }
5984 let elem_id = self.focused_element_id;
5985
5986 // Get max_length from current config (if available this frame)
5987 let max_length = self.text_input_element_ids.iter()
5988 .position(|&id| id == elem_id)
5989 .and_then(|idx| self.text_input_configs.get(idx))
5990 .and_then(|cfg| cfg.max_length);
5991
5992 if let Some(state) = self.text_edit_states.get_mut(&elem_id) {
5993 let old_text = state.text.clone();
5994 state.push_undo(crate::text_input::UndoActionKind::InsertChar);
5995 #[cfg(feature = "text-styling")]
5996 {
5997 state.insert_char_styled(ch, max_length);
5998 }
5999 #[cfg(not(feature = "text-styling"))]
6000 {
6001 state.insert_text(&ch.to_string(), max_length);
6002 }
6003 if state.text != old_text {
6004 let new_text = state.text.clone();
6005 // Fire on_changed callback
6006 if let Some(item) = self.layout_element_map.get_mut(&elem_id) {
6007 if let Some(ref mut callback) = item.on_text_changed_fn {
6008 callback(&new_text);
6009 }
6010 }
6011 }
6012 true
6013 } else {
6014 false
6015 }
6016 }
6017
6018 /// Process a key event for the focused text input.
6019 /// `action` specifies which editing action to perform.

Callers 1

beginMethod · 0.80

Calls 7

is_text_input_focusedMethod · 0.80
positionMethod · 0.80
getMethod · 0.80
cloneMethod · 0.80
push_undoMethod · 0.80
insert_char_styledMethod · 0.80
insert_textMethod · 0.80

Tested by

no test coverage detected