返回 DeepSeek-Reasonix
workspaceSplit.ts
根目录 / desktop / frontend / src / lib / workspaceSplit.ts
1 export function clampWorkspaceSplitTreeWidth({
2 width,
3 panelWidth,
4 railWidth = 0,
5 treeMinWidth,
6 previewMinWidth,
7 }: {
8 width: number;
9 panelWidth?: number;
10 railWidth?: number;
11 treeMinWidth: number;
12 previewMinWidth: number;
13 }): number {
14 const min = Math.round(treeMinWidth);
15 const rounded = Math.round(width);
16 if (typeof panelWidth !== "number" || !Number.isFinite(panelWidth)) {
17 return Math.max(min, rounded);
18 }
19 const splitWidth = Math.max(0, Math.round(panelWidth) - Math.round(railWidth));
20 const max = Math.max(min, splitWidth - Math.round(previewMinWidth));
21 return Math.min(max, Math.max(min, rounded));
22 }
23
24 export function initialWorkspaceSplitTreeWidth({
25 panelWidth,
26 railWidth = 0,
27 savedTreeWidth,
28 treeMinWidth,
29 previewMinWidth,
30 }: {
31 panelWidth?: number;
32 railWidth?: number;
33 savedTreeWidth: number | null;
34 treeMinWidth: number;
35 previewMinWidth: number;
36 }): number {
37 const target =
38 savedTreeWidth !== null && Number.isFinite(savedTreeWidth)
39 ? savedTreeWidth
40 : typeof panelWidth === "number" && Number.isFinite(panelWidth)
41 ? Math.max(0, panelWidth - railWidth) / 2
42 : treeMinWidth;
43 return clampWorkspaceSplitTreeWidth({ width: target, panelWidth, railWidth, treeMinWidth, previewMinWidth });
44 }
45
46 export type WorkspaceSplitTreeWidthMode = "even" | "manual";
47
48 export function shouldInitializeWorkspaceSplitOnFileSelect({
49 previewVisible,
50 treeVisible,
51 }: {
52 previewVisible: boolean;
53 treeVisible: boolean;
54 }): boolean {
55 return !previewVisible || !treeVisible;
56 }
57
58 export function resolveWorkspaceSplitTreeWidth({
59 mode,
60 currentTreeWidth,
61 panelWidth,
62 railWidth = 0,
63 treeMinWidth,
64 previewMinWidth,
65 }: {
66 mode: WorkspaceSplitTreeWidthMode;
67 currentTreeWidth: number;
68 panelWidth?: number;
69 railWidth?: number;
70 treeMinWidth: number;
71 previewMinWidth: number;
72 }): number {
73 if (mode === "even") {
74 return initialWorkspaceSplitTreeWidth({
75 panelWidth,
76 railWidth,
77 savedTreeWidth: null,
78 treeMinWidth,
79 previewMinWidth,
80 });
81 }
82 return clampWorkspaceSplitTreeWidth({
83 width: currentTreeWidth,
84 panelWidth,
85 railWidth,
86 treeMinWidth,
87 previewMinWidth,
88 });
89 }
90
91 export function workspaceSplitCanFit({
92 panelWidth,
93 railWidth = 0,
94 treeMinWidth,
95 previewMinWidth,
96 }: {
97 panelWidth?: number;
98 railWidth?: number;
99 treeMinWidth: number;
100 previewMinWidth: number;
101 }): boolean {
102 if (typeof panelWidth !== "number" || !Number.isFinite(panelWidth)) {
103 return true;
104 }
105 return Math.round(panelWidth) >= Math.round(railWidth) + Math.round(treeMinWidth) + Math.round(previewMinWidth);
106 }
107
108 export function workspaceSplitTreeWidthFromPointer({
109 clientX,
110 panelLeft,
111 panelWidth,
112 railWidth = 0,
113 treeMinWidth,
114 previewMinWidth,
115 }: {
116 clientX: number;
117 panelLeft: number;
118 panelWidth?: number;
119 railWidth?: number;
120 treeMinWidth: number;
121 previewMinWidth: number;
122 }): number {
123 return clampWorkspaceSplitTreeWidth({
124 width: clientX - panelLeft - railWidth,
125 panelWidth,
126 railWidth,
127 treeMinWidth,
128 previewMinWidth,
129 });
130 }
131
131 lines TYPESCRIPT