Skip to content

Commit 53c58ea

Browse files
committed
fix: address PR #41 round 4 (truncation, throttle persist, clamp width)
1 parent ceef527 commit 53c58ea

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

app-prefixable/src/context/layout.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const LAYOUT_STORAGE_KEY = "opencode.layout";
1212
const DEFAULT_REVIEW_WIDTH = 320;
1313
const DEFAULT_INFO_WIDTH = 256;
1414
const DEFAULT_SIDEBAR_WIDTH = 256;
15+
const SIDEBAR_MIN_WIDTH = 180;
16+
const SIDEBAR_MAX_WIDTH = 480;
1517

1618
interface PanelState {
1719
opened: boolean;
@@ -54,6 +56,7 @@ interface LayoutContextValue {
5456
sidebar: {
5557
width: () => number;
5658
resize: (width: number) => void;
59+
persist: () => void;
5760
};
5861
// File tabs
5962
tabs: {
@@ -135,9 +138,11 @@ export function LayoutProvider(props: ParentProps) {
135138
initial.info.width ?? DEFAULT_INFO_WIDTH,
136139
);
137140

138-
// Sidebar state
141+
// Sidebar state (clamp loaded value to valid range)
139142
const [sidebarWidth, setSidebarWidth] = createSignal(
140-
initial.sidebar?.width ?? DEFAULT_SIDEBAR_WIDTH,
143+
Math.max(SIDEBAR_MIN_WIDTH, Math.min(SIDEBAR_MAX_WIDTH,
144+
Number.isFinite(initial.sidebar?.width) ? initial.sidebar!.width! : DEFAULT_SIDEBAR_WIDTH,
145+
)),
141146
);
142147

143148
// File tabs state
@@ -201,9 +206,9 @@ export function LayoutProvider(props: ParentProps) {
201206
sidebar: {
202207
width: sidebarWidth,
203208
resize: (width: number) => {
204-
setSidebarWidth(width);
205-
persist();
209+
setSidebarWidth(Math.max(SIDEBAR_MIN_WIDTH, Math.min(SIDEBAR_MAX_WIDTH, width)));
206210
},
211+
persist,
207212
},
208213
tabs: {
209214
all: fileTabs,

app-prefixable/src/pages/layout.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ export function Layout(props: ParentProps) {
904904
>
905905
<Archive class="w-4 h-4" />
906906
</span>
907-
<span class="truncate">
907+
<span class="min-w-0 flex-1 truncate">
908908
{session.title || "Untitled"}
909909
</span>
910910
</A>
@@ -996,7 +996,10 @@ export function Layout(props: ParentProps) {
996996
setSidebarDragging(true);
997997
layout.sidebar.resize(width);
998998
}}
999-
onDragEnd={() => setSidebarDragging(false)}
999+
onDragEnd={() => {
1000+
setSidebarDragging(false);
1001+
layout.sidebar.persist();
1002+
}}
10001003
onCollapse={toggleSidebar}
10011004
collapseThreshold={100}
10021005
/>

0 commit comments

Comments
 (0)