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

Method process_text_input_action

src/engine.rs:6021–6268  ·  view source on GitHub ↗

Process a key event for the focused text input. `action` specifies which editing action to perform. Returns true if the key was consumed.

(&mut self, action: TextInputAction)

Source from the content-addressed store, hash-verified

6019 /// `action` specifies which editing action to perform.
6020 /// Returns true if the key was consumed.
6021 pub fn process_text_input_action(&mut self, action: TextInputAction) -> bool {
6022 if !self.is_text_input_focused() {
6023 return false;
6024 }
6025 let elem_id = self.focused_element_id;
6026
6027 // Get config for the focused element
6028 let config_idx = self.text_input_element_ids.iter()
6029 .position(|&id| id == elem_id);
6030 let (max_length, is_multiline, font_asset, font_size) = config_idx
6031 .and_then(|idx| self.text_input_configs.get(idx))
6032 .map(|cfg| (cfg.max_length, cfg.is_multiline, cfg.font_asset, cfg.font_size))
6033 .unwrap_or((None, false, None, 16));
6034
6035 // For multiline visual navigation, compute visual lines
6036 let visual_lines_opt = if is_multiline {
6037 let visible_width = self.layout_element_map
6038 .get(&elem_id)
6039 .map(|item| item.bounding_box.width)
6040 .unwrap_or(0.0);
6041 if visible_width > 0.0 {
6042 if let Some(state) = self.text_edit_states.get(&elem_id) {
6043 if let Some(ref measure_fn) = self.measure_text_fn {
6044 Some(crate::text_input::wrap_lines(
6045 &state.text,
6046 visible_width,
6047 font_asset,
6048 font_size,
6049 measure_fn.as_ref(),
6050 ))
6051 } else { None }
6052 } else { None }
6053 } else { None }
6054 } else { None };
6055
6056 if let Some(state) = self.text_edit_states.get_mut(&elem_id) {
6057 let old_text = state.text.clone();
6058
6059 // Push undo before text-modifying actions
6060 match &action {
6061 TextInputAction::Backspace => state.push_undo(crate::text_input::UndoActionKind::Backspace),
6062 TextInputAction::Delete => state.push_undo(crate::text_input::UndoActionKind::Delete),
6063 TextInputAction::BackspaceWord => state.push_undo(crate::text_input::UndoActionKind::DeleteWord),
6064 TextInputAction::DeleteWord => state.push_undo(crate::text_input::UndoActionKind::DeleteWord),
6065 TextInputAction::Cut => state.push_undo(crate::text_input::UndoActionKind::Cut),
6066 TextInputAction::Paste { .. } => state.push_undo(crate::text_input::UndoActionKind::Paste),
6067 TextInputAction::Submit if is_multiline => state.push_undo(crate::text_input::UndoActionKind::InsertChar),
6068 _ => {}
6069 }
6070
6071 match action {
6072 TextInputAction::MoveLeft { shift } => {
6073 #[cfg(feature = "text-styling")]
6074 { state.move_left_styled(shift); }
6075 #[cfg(not(feature = "text-styling"))]
6076 { state.move_left(shift); }
6077 }
6078 TextInputAction::MoveRight { shift } => {

Callers 1

beginMethod · 0.80

Calls 15

wrap_linesFunction · 0.85
visual_line_homeFunction · 0.85
visual_line_endFunction · 0.85
visual_move_upFunction · 0.85
visual_move_downFunction · 0.85
escape_strFunction · 0.85
is_text_input_focusedMethod · 0.80
positionMethod · 0.80
getMethod · 0.80
cloneMethod · 0.80
push_undoMethod · 0.80
move_left_styledMethod · 0.80

Tested by

no test coverage detected