core: Move caret to start or end of selection if shift is not held

Previously pressing left with a selection would set `selection.to = selection.start() - 1`, now it sets it to `selection.to = selection.start()`. The same is true for right/selection.end()
This commit is contained in:
jmckiern 2020-12-24 14:58:42 +00:00 committed by Mike Welsh
parent 464f2b63a9
commit 208a69d715
1 changed files with 20 additions and 6 deletions

View File

@ -1447,17 +1447,31 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
let text = edit_text.text_spans.text(); let text = edit_text.text_spans.text();
let length = text.len(); let length = text.len();
match key_code { match key_code {
ButtonKeyCode::Left if selection.to > 0 => { ButtonKeyCode::Left => {
if (context.input.is_key_down(KeyCode::Shift) || selection.is_caret())
&& selection.to > 0
{
selection.to = string_utils::prev_char_boundary(text, selection.to); selection.to = string_utils::prev_char_boundary(text, selection.to);
if !context.input.is_key_down(KeyCode::Shift) { if !context.input.is_key_down(KeyCode::Shift) {
selection.from = selection.to; selection.from = selection.to;
} }
} else if !context.input.is_key_down(KeyCode::Shift) {
selection.to = selection.start();
selection.from = selection.to;
} }
ButtonKeyCode::Right if selection.to < length => { }
ButtonKeyCode::Right => {
if (context.input.is_key_down(KeyCode::Shift) || selection.is_caret())
&& selection.to < length
{
selection.to = string_utils::next_char_boundary(text, selection.to); selection.to = string_utils::next_char_boundary(text, selection.to);
if !context.input.is_key_down(KeyCode::Shift) { if !context.input.is_key_down(KeyCode::Shift) {
selection.from = selection.to; selection.from = selection.to;
} }
} else if !context.input.is_key_down(KeyCode::Shift) {
selection.to = selection.end();
selection.from = selection.to;
}
} }
_ => {} _ => {}
} }