add caret blink to input
This commit is contained in:
@@ -262,6 +262,44 @@ fn read_only_refuses_edits_but_keeps_selection_and_copy() {
|
||||
.unwrap_or_default()
|
||||
});
|
||||
assert_eq!(clipboard, "lo");
|
||||
|
||||
// The caret is suppressed entirely while read-only.
|
||||
let caret = cx.update(|cx| state.update(cx, |state, cx| state.caret_visible(true, cx)));
|
||||
assert!(!caret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caret_blinks_while_focused_and_holds_solid_while_typing() {
|
||||
let (cx, state, mut visual) = input_window("", false);
|
||||
focus(&mut visual, &state);
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
visual.run_until_parked();
|
||||
|
||||
let caret = || cx.update(|cx| state.update(cx, |state, cx| state.caret_visible(true, cx)));
|
||||
|
||||
// The caret shows on focus, hides after one interval, and reappears
|
||||
// after another.
|
||||
assert!(caret());
|
||||
cx.executor().advance_clock(Duration::from_millis(500));
|
||||
visual.run_until_parked();
|
||||
assert!(!caret());
|
||||
cx.executor().advance_clock(Duration::from_millis(500));
|
||||
visual.run_until_parked();
|
||||
assert!(caret());
|
||||
|
||||
// Typing holds the caret solid and restarts the cycle.
|
||||
visual.simulate_keystrokes("a");
|
||||
assert!(caret());
|
||||
cx.executor().advance_clock(Duration::from_millis(500));
|
||||
visual.run_until_parked();
|
||||
assert!(!caret());
|
||||
|
||||
// An unfocused field reports no caret.
|
||||
let caret_unfocused =
|
||||
cx.update(|cx| state.update(cx, |state, cx| state.caret_visible(false, cx)));
|
||||
assert!(!caret_unfocused);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user