mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 12:32:10 +01:00
Text fields: an open edit menu is no focus loss
The adapter keeps the part's focused state through its edit menu, which holds the editing focus, so was_focused stayed true while key focus was with the menu and text_lost_focus was reported on every pass the menu was open. It is now reported only when the menu is not holding the focus, that is when key focus has really left. The new trial opens the edit menu on a field and checks that no pass reports a loss.
This commit is contained in:
1 parent
f996bdca9d
commit
b58d43ffbc
2 files changed
+23
-3
No files matched your search
@@ -409,6 +409,8 @@ struct PreparedText {
|
||||
caret_visible: bool,
|
||||
commit_now: bool,
|
||||
was_focused: bool,
|
||||
/// The part's edit menu is open and holds its editing focus.
|
||||
menu_open: bool,
|
||||
}
|
||||
|
||||
/// Run the text adapter and adjust focus before the component's typed resolver handles its value.
|
||||
@@ -520,7 +522,7 @@ fn prepare(core: &mut CxCore<'_>, ui: &mut Ui, decl: &TextPart, state: &mut Text
|
||||
state.select_on_click = false;
|
||||
}
|
||||
}
|
||||
PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused }
|
||||
PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, menu_open: held }
|
||||
}
|
||||
|
||||
/// Places the caret of the text part's widget `widget` as focus arrives on the part: where the codec puts it, or over
|
||||
@@ -574,7 +576,7 @@ pub(crate) fn run<C: Component>(
|
||||
}
|
||||
(decl.values.resync)(&mut state, shown_copy(cx).as_ref());
|
||||
let text = prepare(cx.core, ui, part, &mut state, AdapterSettings { keys, rtl, ink, underline }, step.commit_now);
|
||||
let PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused } = text;
|
||||
let PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, menu_open } = text;
|
||||
if part.options.complete.is_some() {
|
||||
drive_completions(cx, &mut state);
|
||||
}
|
||||
@@ -627,7 +629,9 @@ pub(crate) fn run<C: Component>(
|
||||
outcome.clicked = out.clicked;
|
||||
// The focus service moved focus off the widget with Tab before this pass's widgets ran.
|
||||
let left_by_tab = if was_focused && !out.focused { crate::runtime::focus::tabbed_off(&ctx, widget) } else { None };
|
||||
let text_lost_focus = was_focused && !out.focused;
|
||||
// The edit menu holds the part's editing focus while it is open (`was_focused` stays true through it): key focus
|
||||
// that is with the menu is not lost until the menu is gone and focus is not back.
|
||||
let text_lost_focus = was_focused && !out.focused && !menu_open;
|
||||
cx.core.texts =
|
||||
Some((part.key, Box::new(RecordedText { outcome, submit_mods: resolved.submit_mods, left_by_tab, tab: out.tab, caret, text_lost_focus })));
|
||||
apply_events(cx, resolved.events);
|
||||
|
||||
@@ -238,3 +238,19 @@ fn a_field_removed_with_its_edit_menu_open_starts_afresh() {
|
||||
rig.escape();
|
||||
assert_eq!(rig.text(), "Porto", "Escape gives back the text the new run began with");
|
||||
}
|
||||
|
||||
/// The edit menu holds the field's editing focus while it is open: that is no focus loss, so the field reports none in
|
||||
/// the passes the menu is open.
|
||||
#[trial]
|
||||
fn an_open_edit_menu_is_no_focus_loss() {
|
||||
let mut rig = rig("Lisbon", false);
|
||||
rig.retype("Rome");
|
||||
rig.fixture.advance(1.0);
|
||||
let at = rig.at();
|
||||
rig.fixture.frame(vec![pointer::secondary(at, true)]);
|
||||
rig.fixture.frame(vec![pointer::secondary(at, false)]);
|
||||
rig.fixture.settle();
|
||||
assert!(rig.fixture.by_label("Cut").is_some(), "the edit menu is open");
|
||||
rig.fixture.idle(4);
|
||||
assert_eq!(rig.lost_focus(), 0, "the passes with the menu open report no focus loss");
|
||||
}
|
||||
Reference in new issue
Block a user