fix: text selection when mouse goes out of the TextEdit area

This commit is contained in:
Emil Ernerfeldt 2020-11-15 11:48:41 +01:00
parent 13666755e1
commit b920822b6b

View file

@ -242,20 +242,20 @@ impl<'t> Widget for TextEdit<'t> {
}; };
let response = ui.interact(rect, id, sense); let response = ui.interact(rect, id, sense);
if enabled && response.hovered { if enabled {
if let Some(mouse_pos) = ui.input().mouse.pos { if let Some(mouse_pos) = ui.input().mouse.pos {
// TODO: triple-click to select whole paragraph // TODO: triple-click to select whole paragraph
// TODO: drag selected text to either move or clone (ctrl on windows, alt on mac) // TODO: drag selected text to either move or clone (ctrl on windows, alt on mac)
let cursor_at_mouse = galley.cursor_from_pos(mouse_pos - response.rect.min); let cursor_at_mouse = galley.cursor_from_pos(mouse_pos - response.rect.min);
{ if response.hovered {
// preview: // preview:
let end_color = Rgba::new(0.1, 0.6, 1.0, 1.0).multiply(0.5).into(); // TODO: from style let end_color = Rgba::new(0.1, 0.6, 1.0, 1.0).multiply(0.5).into(); // TODO: from style
paint_cursor_end(ui, response.rect.min, &galley, &cursor_at_mouse, end_color); paint_cursor_end(ui, response.rect.min, &galley, &cursor_at_mouse, end_color);
} }
if response.double_clicked { if response.hovered && response.double_clicked {
// Select word: // Select word:
let center = cursor_at_mouse; let center = cursor_at_mouse;
let primary = let primary =
@ -265,7 +265,7 @@ impl<'t> Widget for TextEdit<'t> {
.from_ccursor(ccursor_previous_word(&galley.text, primary.ccursor)), .from_ccursor(ccursor_previous_word(&galley.text, primary.ccursor)),
primary, primary,
}); });
} else if ui.input().mouse.pressed { } else if response.hovered && ui.input().mouse.pressed {
ui.memory().request_kb_focus(id); ui.memory().request_kb_focus(id);
state.cursorp = Some(CursorPair::one(cursor_at_mouse)); state.cursorp = Some(CursorPair::one(cursor_at_mouse));
} else if ui.input().mouse.down && response.active { } else if ui.input().mouse.down && response.active {