chore: audit components

This commit is contained in:
2026-11-10 15:06:16 +07:00
parent af2177c6c8
commit 03369f501e
92 changed files with 2744 additions and 1947 deletions
+48 -56
View File
@@ -32,6 +32,7 @@ type PanelBuilder = Box<dyn Fn(&mut Window, &mut App) -> AnyView>;
type OpenRightSidebarHandler = Rc<dyn Fn(&mut App)>;
/// A registered panel: its identity, chrome, and how its view is built.
#[must_use]
pub struct PanelDescriptor {
id: SharedString,
title: SharedString,
@@ -237,7 +238,7 @@ impl DockState {
/// Points the right sidebar at the panel's own view and asks the app to open it.
fn show_right_view_of(&mut self, id: &str, cx: &mut Context<Self>) {
let right_view = tab_in(&self.root, id).and_then(|tab| tab.right_view.clone());
let right_view = Self::tab_in(&self.root, id).and_then(|tab| tab.right_view.clone());
let Some(right_view) = right_view else {
return;
};
@@ -300,7 +301,7 @@ impl DockState {
// The sidebar showed the closed panel's view.
if self.right_view.as_ref() == closed_right_view.as_ref() {
self.right_view = first_right_view(&self.root);
self.right_view = Self::first_right_view(&self.root);
}
if emptied {
@@ -341,7 +342,7 @@ impl DockState {
})
})
.and_then(|tab| tab.right_view.clone())
.or_else(|| first_right_view(&self.root));
.or_else(|| Self::first_right_view(&self.root));
cx.notify();
}
}
@@ -372,7 +373,7 @@ impl DockState {
}
// The closed pane's views are gone; show the first remaining one.
self.right_view = first_right_view(&self.root);
self.right_view = Self::first_right_view(&self.root);
cx.notify();
}
@@ -495,7 +496,7 @@ impl DockState {
/// The active tab of the pane new panels open into.
pub fn active_panel(&self) -> Option<SharedString> {
let pane = pane_in(&self.root, self.target_pane_key())?;
let pane = Self::pane_in(&self.root, self.target_pane_key())?;
pane.active.clone()
}
@@ -522,7 +523,7 @@ impl DockState {
}
fn target_pane_key(&self) -> u64 {
if pane_in(&self.root, self.active_pane).is_some() {
if Self::pane_in(&self.root, self.active_pane).is_some() {
self.active_pane
} else {
self.first_pane_key().unwrap_or(0)
@@ -613,7 +614,7 @@ impl DockState {
) {
match node {
Node::Pane(pane) if pane.key == key => {
let old_pane = take_node(node);
let old_pane = Self::take_node(node);
let split = if direction.leads() {
Split {
key: split_key,
@@ -635,9 +636,9 @@ impl DockState {
}
Node::Pane(_) => {}
Node::Split(split) => {
if pane_in(&split.a, key).is_some() {
if Self::pane_in(&split.a, key).is_some() {
Self::wrap_in(&mut split.a, key, new_pane, direction, split_key);
} else if pane_in(&split.b, key).is_some() {
} else if Self::pane_in(&split.b, key).is_some() {
Self::wrap_in(&mut split.b, key, new_pane, direction, split_key);
}
}
@@ -654,14 +655,14 @@ impl DockState {
return;
};
let a_direct = direct_pane_key(&split.a) == Some(key);
let b_direct = direct_pane_key(&split.b) == Some(key);
let a_direct = Self::direct_pane_key(&split.a) == Some(key);
let b_direct = Self::direct_pane_key(&split.b) == Some(key);
if a_direct != b_direct {
let survivor = if a_direct {
take_node(&mut split.b)
Self::take_node(&mut split.b)
} else {
take_node(&mut split.a)
Self::take_node(&mut split.a)
};
*node = survivor;
} else {
@@ -699,52 +700,46 @@ impl DockState {
}
snap(&self.root)
}
}
/// Finds a pane by key anywhere in the tree.
fn pane_in(node: &Node, key: u64) -> Option<&Pane> {
match node {
Node::Pane(pane) => (pane.key == key).then_some(pane),
Node::Split(split) => pane_in(&split.a, key).or_else(|| pane_in(&split.b, key)),
/// Finds an open tab by panel id, anywhere in the tree.
fn tab_in<'a>(node: &'a Node, id: &str) -> Option<&'a PanelTab> {
match node {
Node::Pane(pane) => pane.tabs.iter().find(|tab| tab.panel.as_ref() == id),
Node::Split(split) => Self::tab_in(&split.a, id).or_else(|| Self::tab_in(&split.b, id)),
}
}
}
/// Finds an open tab by panel id, anywhere in the tree.
fn tab_in<'a>(node: &'a Node, id: &str) -> Option<&'a PanelTab> {
match node {
Node::Pane(pane) => pane.tabs.iter().find(|tab| tab.panel.as_ref() == id),
Node::Split(split) => tab_in(&split.a, id).or_else(|| tab_in(&split.b, id)),
/// The first open tab's right sidebar view, in display order.
fn first_right_view(node: &Node) -> Option<AnyView> {
match node {
Node::Pane(pane) => pane.tabs.iter().find_map(|tab| tab.right_view.clone()),
Node::Split(split) => {
Self::first_right_view(&split.a).or_else(|| Self::first_right_view(&split.b))
}
}
}
}
/// The first open tab's right sidebar view, in display order.
fn first_right_view(node: &Node) -> Option<AnyView> {
match node {
Node::Pane(pane) => pane.tabs.iter().find_map(|tab| tab.right_view.clone()),
Node::Split(split) => first_right_view(&split.a).or_else(|| first_right_view(&split.b)),
/// The pane key of a node that is a pane, for seam-level tree edits.
fn direct_pane_key(node: &Node) -> Option<u64> {
match node {
Node::Pane(pane) => Some(pane.key),
Node::Split(_) => None,
}
}
}
/// The pane key of a node that is a pane, for seam-level tree edits.
fn direct_pane_key(node: &Node) -> Option<u64> {
match node {
Node::Pane(pane) => Some(pane.key),
Node::Split(_) => None,
/// Takes a node out, leaving a placeholder that is never read again.
fn take_node(node: &mut Node) -> Node {
std::mem::replace(
node,
Node::Pane(Pane {
key: u64::MAX,
tabs: Vec::new(),
active: None,
}),
)
}
}
/// Takes a node out, leaving a placeholder that is never read again.
fn take_node(node: &mut Node) -> Node {
std::mem::replace(
node,
Node::Pane(Pane {
key: u64::MAX,
tabs: Vec::new(),
active: None,
}),
)
}
/// One open panel view, per frame.
#[derive(Clone)]
struct TabView {
@@ -776,6 +771,7 @@ enum TreeView {
/// A dock: renders the pane tree of a [`DockState`].
#[derive(IntoElement)]
#[must_use]
pub struct Dock {
id: ElementId,
state: Entity<DockState>,
@@ -1095,6 +1091,7 @@ fn render_pane(
});
let bar_id = SharedString::from(format!("{dock_id}-pane-{}-bar", pane.key));
let strip_id = SharedString::from(format!("{dock_id}-pane-{}-strip", pane.key));
h_flex()
.id(bar_id.clone())
@@ -1111,13 +1108,8 @@ fn render_pane(
.pr(padding_x)
.child(tabs)
.child(titlebar_strip(
div()
.id(SharedString::from(format!(
"{dock_id}-pane-{}-strip",
pane.key
)))
.flex_1()
.self_stretch(),
div().id(strip_id.clone()).flex_1().self_stretch(),
strip_id,
window,
cx,
))