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

Method set_cursor_pos

src/engine.rs:5922–5932  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 2

cursor_lenFunction · 0.85
reset_blinkMethod · 0.80

Tested by

no test coverage detected