On touch screens, prioritize drag-to-scroll over drag-to-select text
On mobile, click first, then edit the text. Otherwise a lot of areas become difficult to scroll on mobile.
This commit is contained in:
parent
17f0ae22c9
commit
9a9b1b8746
1 changed files with 26 additions and 12 deletions
|
@ -591,8 +591,18 @@ impl<'t> TextEdit<'t> {
|
||||||
});
|
});
|
||||||
let mut state = ui.memory().id_data.get_or_default::<State>(id).clone();
|
let mut state = ui.memory().id_data.get_or_default::<State>(id).clone();
|
||||||
|
|
||||||
|
// On touch screens (e.g. mobile in egui_web), should
|
||||||
|
// dragging select text, or scroll the enclosing `ScrollArea` (if any)?
|
||||||
|
// Since currently copying selected text in not supported on `egui_web`,
|
||||||
|
// we prioritize touch-scrolling:
|
||||||
|
let allow_drag_to_select = !ui.input().any_touches() || ui.memory().has_focus(id);
|
||||||
|
|
||||||
let sense = if interactive {
|
let sense = if interactive {
|
||||||
Sense::click_and_drag()
|
if allow_drag_to_select {
|
||||||
|
Sense::click_and_drag()
|
||||||
|
} else {
|
||||||
|
Sense::click()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Sense::hover()
|
Sense::hover()
|
||||||
};
|
};
|
||||||
|
@ -630,20 +640,24 @@ impl<'t> TextEdit<'t> {
|
||||||
primary: galley.from_ccursor(ccursorp.primary),
|
primary: galley.from_ccursor(ccursorp.primary),
|
||||||
secondary: galley.from_ccursor(ccursorp.secondary),
|
secondary: galley.from_ccursor(ccursorp.secondary),
|
||||||
});
|
});
|
||||||
} else if response.hovered() && ui.input().pointer.any_pressed() {
|
} else if allow_drag_to_select {
|
||||||
ui.memory().request_focus(id);
|
if response.hovered() && ui.input().pointer.any_pressed() {
|
||||||
if ui.input().modifiers.shift {
|
ui.memory().request_focus(id);
|
||||||
if let Some(cursorp) = &mut state.cursorp {
|
if ui.input().modifiers.shift {
|
||||||
cursorp.primary = cursor_at_pointer;
|
if let Some(cursorp) = &mut state.cursorp {
|
||||||
|
cursorp.primary = cursor_at_pointer;
|
||||||
|
} else {
|
||||||
|
state.cursorp = Some(CursorPair::one(cursor_at_pointer));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
state.cursorp = Some(CursorPair::one(cursor_at_pointer));
|
state.cursorp = Some(CursorPair::one(cursor_at_pointer));
|
||||||
}
|
}
|
||||||
} else {
|
} else if ui.input().pointer.any_down() && response.is_pointer_button_down_on()
|
||||||
state.cursorp = Some(CursorPair::one(cursor_at_pointer));
|
{
|
||||||
}
|
// drag to select text:
|
||||||
} else if ui.input().pointer.any_down() && response.is_pointer_button_down_on() {
|
if let Some(cursorp) = &mut state.cursorp {
|
||||||
if let Some(cursorp) = &mut state.cursorp {
|
cursorp.primary = cursor_at_pointer;
|
||||||
cursorp.primary = cursor_at_pointer;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue