T44d Web · Hidden builders start nothing, fields blink only in focus, grids paste with Control

This commit is contained in:
ZacharyZhang-NY committed 2026-09-29 23:02:37 -04:00
1 parent 81adec5c47
commit dcdd46038e
8 files changed
+107 -55

No files matched your search

+28
View File
@@ -330,3 +330,31 @@ fn shift_enter_breaks_only_a_field_of_many_lines(cx: &mut TestAppContext) {
"a single line stays single"
);
}
#[gpui::test]
fn only_a_focused_field_blinks(cx: &mut TestAppContext) {
let (fields, cx) = open(1, false, cx);
let field = fields[0].clone();
let redraws = std::rc::Rc::new(std::cell::Cell::new(0));
let counted = redraws.clone();
let _count = cx.update(|_, cx| cx.observe(&field, move |_, _| counted.set(counted.get() + 1)));
field.update(cx, |input, cx| {
input.set_text("seeded", cx);
let word = 0..4;
input.select(word, cx);
});
cx.run_until_parked();
redraws.set(0);
cx.executor()
.advance_clock(std::time::Duration::from_secs(3));
cx.run_until_parked();
assert_eq!(redraws.get(), 0, "an unfocused field keeps still");
cx.update(|window, _| window.activate_window());
focus(&field, cx);
cx.run_until_parked();
redraws.set(0);
cx.executor()
.advance_clock(std::time::Duration::from_secs(3));
cx.run_until_parked();
assert!(redraws.get() > 2, "a focused one blinks");
}
+6 -1
View File
@@ -69,6 +69,8 @@ pub struct TextInput {
pub(crate) scroll: Point<Pixels>,
selecting: bool,
caret_on: bool,
/// Blink runs only while focused, or unseen carets redraw forever.
focused: bool,
blink_epoch: u64,
_blink: Option<Task<()>>,
_subscriptions: Vec<Subscription>,
@@ -87,10 +89,12 @@ impl TextInput {
let focus = cx.focus_handle().tab_stop(true);
let subscriptions = vec![
cx.on_focus(&focus, window, |input, _, cx| {
input.focused = true;
input.restart_blink(cx);
cx.emit(InputEvent::Focus);
}),
cx.on_blur(&focus, window, |input, _, cx| {
input.focused = false;
input.selecting = false;
input._blink = None;
cx.emit(InputEvent::Blur);
@@ -118,6 +122,7 @@ impl TextInput {
scroll: Point::default(),
selecting: false,
caret_on: true,
focused: false,
blink_epoch: 0,
_blink: None,
_subscriptions: subscriptions,
@@ -367,7 +372,7 @@ impl TextInput {
self.blink_epoch += 1;
let epoch = self.blink_epoch;
let still = cx.theme().reduced_motion;
self._blink = (!still).then(|| {
self._blink = (!still && self.focused).then(|| {
cx.spawn(async move |input, cx| {
loop {
cx.background_executor().timer(BLINK).await;