fix tab bar

This commit is contained in:
2026-08-01 10:52:38 +07:00
parent 53f3e77a5d
commit 4915d4fd60
2 changed files with 16 additions and 6 deletions

View File

@@ -51,7 +51,7 @@ impl Render for DragPanel {
.overflow_hidden() .overflow_hidden()
.whitespace_nowrap() .whitespace_nowrap()
.rounded(cx.theme().radius) .rounded(cx.theme().radius)
.text_xs() .text_sm()
.text_color(cx.theme().text) .text_color(cx.theme().text)
.text_ellipsis() .text_ellipsis()
.when(cx.theme().shadow, |this| this.shadow_xs()) .when(cx.theme().shadow, |this| this.shadow_xs())
@@ -312,6 +312,7 @@ impl TabPanel {
cx.emit(PanelEvent::ZoomOut); cx.emit(PanelEvent::ZoomOut);
cx.emit(PanelEvent::LayoutChanged); cx.emit(PanelEvent::LayoutChanged);
cx.notify();
} }
fn detach_panel( fn detach_panel(
@@ -321,10 +322,22 @@ impl TabPanel {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
let panel_view = panel.view(); let panel_view = panel.view();
let removed_ix = self.panels.iter().position(|p| p.view() == panel_view);
self.panels.retain(|p| p.view() != panel_view); self.panels.retain(|p| p.view() != panel_view);
if self.active_ix >= self.panels.len() { if self.active_ix >= self.panels.len() {
self.set_active_ix(self.panels.len().saturating_sub(1), window, cx) self.set_active_ix(self.panels.len().saturating_sub(1), window, cx)
} else if let Some(removed_ix) = removed_ix {
if removed_ix < self.active_ix {
self.active_ix = self.active_ix.saturating_sub(1);
} else if removed_ix == self.active_ix {
// The active panel was removed and another panel shifted into
// its position. Activate the new panel at the same index.
if let Some(new_active) = self.panels.get(self.active_ix) {
new_active.set_active(true, cx);
}
self.focus_active_panel(window, cx);
}
} }
} }
@@ -613,7 +626,7 @@ impl TabPanel {
div() div()
.w_full() .w_full()
.text_ellipsis() .text_ellipsis()
.text_xs() .text_sm()
.child(panel.title(cx)), .child(panel.title(cx)),
) )
.when(state.draggable, |this| { .when(state.draggable, |this| {
@@ -687,8 +700,8 @@ impl TabPanel {
.on_click(cx.listener({ .on_click(cx.listener({
let panel = panel.clone(); let panel = panel.clone();
move |view, _ev, window, cx| { move |view, _ev, window, cx| {
cx.stop_propagation();
view.remove_panel(&panel, window, cx); view.remove_panel(&panel, window, cx);
view.set_active_ix(ix, window, cx);
} }
})), })),
) )

View File

@@ -187,9 +187,6 @@ impl RenderOnce for Tab {
.overflow_hidden() .overflow_hidden()
.text_color(fg) .text_color(fg)
.text_sm() .text_sm()
.when(!self.selected && !self.disabled, |this| {
this.hover(|this| this.text_color(cx.theme().secondary_foreground))
})
.when_some(self.prefix, |this, prefix| this.child(prefix)) .when_some(self.prefix, |this, prefix| this.child(prefix))
.child( .child(
h_flex() h_flex()