fix(editor): address code review issues in dock module
- debug_assert → assert for empty tabs invariant - tabs.len() - 1 → saturating_sub(1) to prevent underflow - Add #[allow(dead_code)] for scaffolded structs/constants Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
const TAB_BAR_HEIGHT: f32 = 20.0;
|
const TAB_BAR_HEIGHT: f32 = 20.0;
|
||||||
const MIN_RATIO: f32 = 0.1;
|
const MIN_RATIO: f32 = 0.1;
|
||||||
const MAX_RATIO: f32 = 0.9;
|
const MAX_RATIO: f32 = 0.9;
|
||||||
|
#[allow(dead_code)]
|
||||||
const RESIZE_HANDLE_HALF: f32 = 3.0;
|
const RESIZE_HANDLE_HALF: f32 = 3.0;
|
||||||
|
#[allow(dead_code)]
|
||||||
const GLYPH_W: f32 = 8.0;
|
const GLYPH_W: f32 = 8.0;
|
||||||
|
#[allow(dead_code)]
|
||||||
const TAB_PADDING: f32 = 8.0;
|
const TAB_PADDING: f32 = 8.0;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
@@ -52,6 +55,7 @@ pub struct LeafLayout {
|
|||||||
pub content_rect: Rect,
|
pub content_rect: Rect,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
struct SplitLayout {
|
struct SplitLayout {
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
@@ -59,6 +63,7 @@ struct SplitLayout {
|
|||||||
path: Vec<usize>,
|
path: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
struct ResizeState {
|
struct ResizeState {
|
||||||
path: Vec<usize>,
|
path: Vec<usize>,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
@@ -68,10 +73,13 @@ struct ResizeState {
|
|||||||
|
|
||||||
pub struct DockTree {
|
pub struct DockTree {
|
||||||
root: DockNode,
|
root: DockNode,
|
||||||
|
#[allow(dead_code)]
|
||||||
names: Vec<&'static str>,
|
names: Vec<&'static str>,
|
||||||
cached_leaves: Vec<LeafLayout>,
|
cached_leaves: Vec<LeafLayout>,
|
||||||
cached_splits: Vec<SplitLayout>,
|
cached_splits: Vec<SplitLayout>,
|
||||||
|
#[allow(dead_code)]
|
||||||
resizing: Option<ResizeState>,
|
resizing: Option<ResizeState>,
|
||||||
|
#[allow(dead_code)]
|
||||||
prev_mouse_down: bool,
|
prev_mouse_down: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +93,13 @@ fn layout_recursive(
|
|||||||
) {
|
) {
|
||||||
match node {
|
match node {
|
||||||
DockNode::Leaf { tabs, active } => {
|
DockNode::Leaf { tabs, active } => {
|
||||||
debug_assert!(!tabs.is_empty(), "DockNode::Leaf must have at least one tab");
|
assert!(!tabs.is_empty(), "DockNode::Leaf must have at least one tab");
|
||||||
let idx = *leaf_counter;
|
let idx = *leaf_counter;
|
||||||
*leaf_counter += 1;
|
*leaf_counter += 1;
|
||||||
leaves.push(LeafLayout {
|
leaves.push(LeafLayout {
|
||||||
leaf_index: idx,
|
leaf_index: idx,
|
||||||
tabs: tabs.clone(),
|
tabs: tabs.clone(),
|
||||||
active: (*active).min(tabs.len() - 1),
|
active: (*active).min(tabs.len().saturating_sub(1)),
|
||||||
tab_bar_rect: Rect { x: rect.x, y: rect.y, w: rect.w, h: TAB_BAR_HEIGHT },
|
tab_bar_rect: Rect { x: rect.x, y: rect.y, w: rect.w, h: TAB_BAR_HEIGHT },
|
||||||
content_rect: Rect {
|
content_rect: Rect {
|
||||||
x: rect.x,
|
x: rect.x,
|
||||||
|
|||||||
Reference in New Issue
Block a user