fix(activity): no crash when a row slides under the mouse after mark read
gpui computes group-hover style in prepaint from the previous frame's hit test and in paint from the new one. The check button toggled display (hidden -> flex) on row hover, so a row moving under a resting mouse (mark read in the Unread filter, list update) painted a child that was never prepainted: "must call prepaint before paint". Dot and button now toggle visibility, which prepaint ignores; the button overlays the dot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -279,32 +279,38 @@ fn status_slot(
279
279
if !unread {
280
280
return slot;
281
281
}
282
slot.child(
283
div()
284
.flex()
285
.group_hover(group.clone(), |wrapper| wrapper.hidden())
286
.mr(px(8.))
287
.child(dot(8.)),
288
)
289
.child(
290
div()
291
.id(ElementId::Name(format!("activity-mark-read-{id}").into()))
292
.hidden()
293
.group_hover(group, |button| button.flex())
294
.size(px(MARK_READ_SIZE))
295
.flex_none()
296
.items_center()
297
.justify_center()
298
.rounded(px(6.))
299
.bg(theme::surface_raised())
300
.cursor_pointer()
301
.child(icon(IconName::Check, 12., theme::text()))
302
.tooltip(|window, cx| Tooltip::new("Mark as read").build(window, cx))
303
.on_click(move |_, _, cx| {
304
cx.stop_propagation();
305
activity.update(cx, |activity, cx| activity.mark_read(id, cx));
306
}),
307
)
282
// Toggle visibility, never display: gpui reads hover in prepaint and paint from different frames.
283
slot.relative()
284
.w(px(MARK_READ_SIZE))
285
.child(
286
div()
287
.flex()
288
.group_hover(group.clone(), |wrapper| wrapper.invisible())
289
.mr(px(8.))
290
.child(dot(8.)),
291
)
292
.child(
293
div()
294
.id(ElementId::Name(format!("activity-mark-read-{id}").into()))
295
.absolute()
296
.top_0()
297
.right_0()
298
.invisible()
299
.group_hover(group, |button| button.visible())
300
.size(px(MARK_READ_SIZE))
301
.flex()
302
.items_center()
303
.justify_center()
304
.rounded(px(6.))
305
.bg(theme::surface_raised())
306
.cursor_pointer()
307
.child(icon(IconName::Check, 12., theme::text()))
308
.tooltip(|window, cx| Tooltip::new("Mark as read").build(window, cx))
309
.on_click(move |_, _, cx| {
310
cx.stop_propagation();
311
activity.update(cx, |activity, cx| activity.mark_read(id, cx));
312
}),
313
)
308
314
}
309
315
310
316
fn kind_marker(entry: &Entry, row_group: SharedString) -> Div {
@@ -455,12 +461,15 @@ impl Render for ActivityPanel {
455
461
#[cfg(test)]
456
462
mod tests {
457
463
use std::collections::HashMap;
464
use std::sync::Arc;
458
465
459
use chrono::{TimeZone, Utc};
460
use store::{ChatRecord, Sidebar};
466
use chrono::{Local, Offset, TimeZone, Utc};
467
use gpui_kit::{AppContext as _, Modifiers, TestAppContext};
468
use store::{ChatRecord, Sidebar, Store};
461
469
462
use super::{detail, headline};
463
use crate::activity::{Actor, Entry, Kind};
470
use super::{ActivityPanel, detail, headline};
471
use crate::activity::{ActivityCenter, Actor, Entry, Filter, Kind};
472
use crate::app_state::{AppState, Mode};
464
473
465
474
fn entry(kind: Kind, count: u32) -> Entry {
466
475
Entry {
@@ -529,4 +538,51 @@ mod tests {
529
538
"Unknown reacted"
530
539
);
531
540
}
541
542
#[gpui_kit::test]
543
fn row_sliding_under_a_resting_mouse_draws(cx: &mut TestAppContext) {
544
cx.update(gpui_kit::init);
545
let store = Arc::new(Store::open_in_memory().unwrap());
546
crate::demo::seed(&store);
547
let mode = Mode {
548
demo: true,
549
read_only: false,
550
demo_sync: None,
551
};
552
let app = cx.update(|cx| {
553
cx.new(|_| {
554
let mut state = AppState::new(store, mode);
555
crate::demo::seed_directory(&mut state);
556
state
557
})
558
});
559
let (panel, cx) = cx.add_window_view(|window, cx| {
560
let activity = cx.new(|cx| ActivityCenter::new(app.clone(), window, cx));
561
let mut panel = ActivityPanel::new(app.clone(), activity, cx);
562
panel.filter = Filter::Unread;
563
panel
564
});
565
cx.update(|window, cx| window.draw(cx).clear(cx));
566
let (activity, first_row) = cx.update(|_, cx| {
567
let panel = panel.read(cx);
568
(
569
panel.activity.clone(),
570
panel.scroll.bounds_for_item(1).unwrap(),
571
)
572
});
573
let first_unread = cx.update(|_, cx| {
574
let now = Local::now();
575
activity
576
.read(cx)
577
.feed()
578
.sections(Filter::Unread, now.date_naive(), now.offset().fix())[0]
579
.entries[0]
580
.id
581
});
582
cx.simulate_mouse_move(first_row.center(), None, Modifiers::none());
583
cx.update(|window, cx| window.draw(cx).clear(cx));
584
cx.update(|_, cx| activity.update(cx, |activity, cx| activity.mark_read(first_unread, cx)));
585
cx.update(|window, cx| window.draw(cx).clear(cx));
586
cx.update(|window, cx| window.draw(cx).clear(cx));
587
}
532
588
}
@@ -279,32 +279,38 @@ fn status_slot(279
if !unread {279
if !unread {280
return slot;280
return slot;281
}281
}282
slot.child(282
// Toggle visibility, never display: gpui reads hover in prepaint and paint from different frames.283
div()283
slot.relative()284
.flex()284
.w(px(MARK_READ_SIZE))285
.group_hover(group.clone(), |wrapper| wrapper.hidden())285
.child(286
.mr(px(8.))286
div()287
.child(dot(8.)),287
.flex()288
)288
.group_hover(group.clone(), |wrapper| wrapper.invisible())289
.child(289
.mr(px(8.))290
div()290
.child(dot(8.)),291
.id(ElementId::Name(format!("activity-mark-read-{id}").into()))291
)292
.hidden()292
.child(293
.group_hover(group, |button| button.flex())293
div()294
.size(px(MARK_READ_SIZE))294
.id(ElementId::Name(format!("activity-mark-read-{id}").into()))295
.flex_none()295
.absolute()296
.items_center()296
.top_0()297
.justify_center()297
.right_0()298
.rounded(px(6.))298
.invisible()299
.bg(theme::surface_raised())299
.group_hover(group, |button| button.visible())300
.cursor_pointer()300
.size(px(MARK_READ_SIZE))301
.child(icon(IconName::Check, 12., theme::text()))301
.flex()302
.tooltip(|window, cx| Tooltip::new("Mark as read").build(window, cx))302
.items_center()303
.on_click(move |_, _, cx| {303
.justify_center()304
cx.stop_propagation();304
.rounded(px(6.))305
activity.update(cx, |activity, cx| activity.mark_read(id, cx));305
.bg(theme::surface_raised())306
}),306
.cursor_pointer()307
)307
.child(icon(IconName::Check, 12., theme::text()))308
.tooltip(|window, cx| Tooltip::new("Mark as read").build(window, cx))309
.on_click(move |_, _, cx| {310
cx.stop_propagation();311
activity.update(cx, |activity, cx| activity.mark_read(id, cx));312
}),313
)308
}314
}309
315
310
fn kind_marker(entry: &Entry, row_group: SharedString) -> Div {316
fn kind_marker(entry: &Entry, row_group: SharedString) -> Div {@@ -455,12 +461,15 @@ impl Render for ActivityPanel {455
#[cfg(test)]461
#[cfg(test)]456
mod tests {462
mod tests {457
use std::collections::HashMap;463
use std::collections::HashMap;464
use std::sync::Arc;458
465
459
use chrono::{TimeZone, Utc};466
use chrono::{Local, Offset, TimeZone, Utc};460
use store::{ChatRecord, Sidebar};467
use gpui_kit::{AppContext as _, Modifiers, TestAppContext};468
use store::{ChatRecord, Sidebar, Store};461
469
462
use super::{detail, headline};470
use super::{ActivityPanel, detail, headline};463
use crate::activity::{Actor, Entry, Kind};471
use crate::activity::{ActivityCenter, Actor, Entry, Filter, Kind};472
use crate::app_state::{AppState, Mode};464
473
465
fn entry(kind: Kind, count: u32) -> Entry {474
fn entry(kind: Kind, count: u32) -> Entry {466
Entry {475
Entry {@@ -529,4 +538,51 @@ mod tests {529
"Unknown reacted"538
"Unknown reacted"530
);539
);531
}540
}541
542
#[gpui_kit::test]543
fn row_sliding_under_a_resting_mouse_draws(cx: &mut TestAppContext) {544
cx.update(gpui_kit::init);545
let store = Arc::new(Store::open_in_memory().unwrap());546
crate::demo::seed(&store);547
let mode = Mode {548
demo: true,549
read_only: false,550
demo_sync: None,551
};552
let app = cx.update(|cx| {553
cx.new(|_| {554
let mut state = AppState::new(store, mode);555
crate::demo::seed_directory(&mut state);556
state557
})558
});559
let (panel, cx) = cx.add_window_view(|window, cx| {560
let activity = cx.new(|cx| ActivityCenter::new(app.clone(), window, cx));561
let mut panel = ActivityPanel::new(app.clone(), activity, cx);562
panel.filter = Filter::Unread;563
panel564
});565
cx.update(|window, cx| window.draw(cx).clear(cx));566
let (activity, first_row) = cx.update(|_, cx| {567
let panel = panel.read(cx);568
(569
panel.activity.clone(),570
panel.scroll.bounds_for_item(1).unwrap(),571
)572
});573
let first_unread = cx.update(|_, cx| {574
let now = Local::now();575
activity576
.read(cx)577
.feed()578
.sections(Filter::Unread, now.date_naive(), now.offset().fix())[0]579
.entries[0]580
.id581
});582
cx.simulate_mouse_move(first_row.center(), None, Modifiers::none());583
cx.update(|window, cx| window.draw(cx).clear(cx));584
cx.update(|_, cx| activity.update(cx, |activity, cx| activity.mark_read(first_unread, cx)));585
cx.update(|window, cx| window.draw(cx).clear(cx));586
cx.update(|window, cx| window.draw(cx).clear(cx));587
}532
}588
}