Skip to content
Snippets Groups Projects
Commit 3d1f68f2 authored by John Mitchell's avatar John Mitchell
Browse files

Fixed issue where graphemes weren't respected by the text box editing.

parent 43d8ea37
No related branches found
No related tags found
No related merge requests found
...@@ -218,13 +218,14 @@ pub fn text_box_render( ...@@ -218,13 +218,14 @@ pub fn text_box_render(
let cursor_pos = state.cursor_position; let cursor_pos = state.cursor_position;
if is_backspace(c) { if is_backspace(c) {
if !state.current_value.is_empty() { if !state.current_value.is_empty() {
// TODO: This doesn't respect graphemes! let char_pos: usize = state.graphemes[0..cursor_pos - 1].iter().map(|g| g.len()).sum();
state.current_value.remove(cursor_pos - 1); state.current_value.remove(char_pos);
state.cursor_position -= 1; state.cursor_position -= 1;
} }
} else if !c.is_control() { } else if !c.is_control() {
// TODO: This doesn't respect graphemes! let char_pos: usize = state.graphemes[0..cursor_pos].iter().map(|g| g.len()).sum();
state.current_value.insert(cursor_pos, c); state.current_value.insert(char_pos, c);
state.cursor_position += 1; state.cursor_position += 1;
} }
...@@ -387,6 +388,25 @@ fn set_graphemes( ...@@ -387,6 +388,25 @@ fn set_graphemes(
} }
} }
fn get_single_grapheme_length(
font_assets: &Res<Assets<KayakFont>>,
font_mapping: &FontMapping,
style_font: &StyleProp<String>,
text: &String,
) -> usize {
let font_handle = match style_font {
StyleProp::Value(font) => font_mapping.get_handle(font.clone()).unwrap(),
_ => font_mapping.get_handle(DEFAULT_FONT.into()).unwrap(),
};
if let Some(font) = font_assets.get(&font_handle) {
let graphemes = font.get_graphemes(&text);
return graphemes[0].len();
}
0
}
fn set_new_cursor_position( fn set_new_cursor_position(
state: &mut TextBoxState, state: &mut TextBoxState,
font_assets: &Res<Assets<KayakFont>>, font_assets: &Res<Assets<KayakFont>>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment