Sets the cursor position for a text input element. When text-styling is enabled, `pos` is in visual space. Clamps to the text length and clears any selection.
(&mut self, element_id: u32, pos: usize)
| 5920 | /// When text-styling is enabled, `pos` is in visual space. |
| 5921 | /// Clamps to the text length and clears any selection. |
| 5922 | pub fn set_cursor_pos(&mut self, element_id: u32, pos: usize) { |
| 5923 | if let Some(state) = self.text_edit_states.get_mut(&element_id) { |
| 5924 | #[cfg(feature = "text-styling")] |
| 5925 | let max_pos = crate::text_input::styling::cursor_len(&state.text); |
| 5926 | #[cfg(not(feature = "text-styling"))] |
| 5927 | let max_pos = state.text.chars().count(); |
| 5928 | state.cursor_pos = pos.min(max_pos); |
| 5929 | state.selection_anchor = None; |
| 5930 | state.reset_blink(); |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | /// Returns the selection range (start, end) for a text input element, or None. |
| 5935 | /// When text-styling is enabled, these are visual positions. |
nothing calls this directly
no test coverage detected