-
Notifications
You must be signed in to change notification settings - Fork 90
feat(windows): 支持运行配置列表左右拖拽调整宽度 #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
1lck
merged 5 commits into
1lck:preview
from
Rangsh:fix/462-windows-run-config-list-resize
Sep 4, 2026
+638
−61
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c511f85
feat(windows): 支持运行配置列表左右拖拽调整宽度
Rangsh ab99db1
fix(windows): 完善运行配置列表拖拽清理与键盘调整
Rangsh fcd604f
fix(windows): 修复 CI typecheck 对 Array.at 的兼容问题
Rangsh 5ebd466
Merge branch 'preview' into fix/462-windows-run-config-list-resize
1lck f195ac4
Merge branch 'preview' into fix/462-windows-run-config-list-resize
1lck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
windows/tauri/src/features/run/components/run-configuration-list-split.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { expect, test } from "bun:test"; | ||
|
|
||
| test("run configuration list split wires keyboard resize and drag session cleanup", async () => { | ||
| const source = await Bun.file( | ||
| new URL("./run-configuration-list-split.tsx", import.meta.url), | ||
| ).text(); | ||
|
|
||
| expect(source).toContain("onKeyDown={handleKeyDown}"); | ||
| expect(source).toContain("nextRunConfigurationListWidthForKey"); | ||
| expect(source).toContain("startDocumentResizeSession"); | ||
| expect(source).toContain('sessionRef.current?.dispose({ commit: true })'); | ||
| expect(source).toContain("onPointerDown={handlePointerDown}"); | ||
| }); |
177 changes: 177 additions & 0 deletions
177
windows/tauri/src/features/run/components/run-configuration-list-split.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import type React from "react"; | ||
| import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"; | ||
| import { useTranslation } from "@/i18n/locale-provider"; | ||
| import { cn } from "@/utils/cn"; | ||
| import { useRunPreferencesStore } from "../stores/run-preferences.store"; | ||
| import { | ||
| RUN_CONFIGURATION_LIST_HANDLE_THICKNESS, | ||
| RUN_CONFIGURATION_LIST_MIN_WIDTH, | ||
| clampRunConfigurationListWidth, | ||
| getRunConfigurationListMaxWidth, | ||
| } from "../utils/run-configuration-list-layout"; | ||
| import { | ||
| nextRunConfigurationListWidthForKey, | ||
| startDocumentResizeSession, | ||
| type DocumentResizeSession, | ||
| } from "../utils/run-configuration-list-resize-session"; | ||
|
|
||
| interface RunConfigurationListSplitProps { | ||
| list: React.ReactNode; | ||
| content: React.ReactNode; | ||
| } | ||
|
|
||
| /** | ||
| * Local layout container for the Run tool window's configuration list. | ||
| * Keeps drag width mutations out of RunPane and only commits when a resize | ||
| * session ends, matching macOS LitheSplitPaneView persistence. | ||
| */ | ||
| export function RunConfigurationListSplit({ list, content }: RunConfigurationListSplitProps) { | ||
| const { t } = useTranslation(); | ||
| const storedWidth = useRunPreferencesStore((state) => state.configurationListWidth); | ||
| const setConfigurationListWidth = useRunPreferencesStore( | ||
| (state) => state.actions.setConfigurationListWidth, | ||
| ); | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| const listRef = useRef<HTMLDivElement>(null); | ||
| const sessionRef = useRef<DocumentResizeSession | null>(null); | ||
| const isMountedRef = useRef(true); | ||
| const [containerWidth, setContainerWidth] = useState(0); | ||
| const [width, setWidth] = useState(() => | ||
| clampRunConfigurationListWidth(storedWidth, typeof window !== "undefined" ? window.innerWidth : 1280), | ||
| ); | ||
| const [isResizing, setIsResizing] = useState(false); | ||
|
|
||
| const clampWidth = useCallback( | ||
| (value: number) => clampRunConfigurationListWidth(value, containerWidth || 1280), | ||
| [containerWidth], | ||
| ); | ||
|
|
||
| const commitWidth = useCallback( | ||
| (nextWidth: number) => { | ||
| setConfigurationListWidth(nextWidth); | ||
| if (isMountedRef.current) { | ||
| setWidth(nextWidth); | ||
| setIsResizing(false); | ||
| } | ||
| sessionRef.current = null; | ||
| }, | ||
| [setConfigurationListWidth], | ||
| ); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const container = containerRef.current; | ||
| if (!container) return; | ||
|
|
||
| const updateWidth = () => { | ||
| const nextContainerWidth = container.getBoundingClientRect().width; | ||
| setContainerWidth(nextContainerWidth); | ||
| setWidth((current) => clampRunConfigurationListWidth(current, nextContainerWidth)); | ||
| }; | ||
|
|
||
| updateWidth(); | ||
| const observer = new ResizeObserver(updateWidth); | ||
| observer.observe(container); | ||
| return () => observer.disconnect(); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| setWidth(clampWidth(storedWidth)); | ||
| }, [storedWidth, clampWidth]); | ||
|
|
||
| useEffect(() => { | ||
| isMountedRef.current = true; | ||
| return () => { | ||
| isMountedRef.current = false; | ||
| // Persist the in-flight width, then drop listeners/body styles/RAF. | ||
| sessionRef.current?.dispose({ commit: true }); | ||
| sessionRef.current = null; | ||
| }; | ||
| }, []); | ||
|
|
||
| const handlePointerDown = useCallback( | ||
| (event: React.PointerEvent) => { | ||
| event.preventDefault(); | ||
| sessionRef.current?.dispose({ commit: true }); | ||
|
|
||
| const listEl = listRef.current; | ||
| sessionRef.current = startDocumentResizeSession({ | ||
| startX: event.clientX, | ||
| startWidth: width, | ||
| clampWidth, | ||
| applyWidth: (nextWidth) => { | ||
| if (listEl) { | ||
| listEl.style.width = `${nextWidth}px`; | ||
| } | ||
| }, | ||
| commitWidth, | ||
| onActiveChange: (active) => { | ||
| if (isMountedRef.current) { | ||
| setIsResizing(active); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| [width, clampWidth, commitWidth], | ||
| ); | ||
|
|
||
| const handleKeyDown = useCallback( | ||
| (event: React.KeyboardEvent) => { | ||
| const nextWidth = nextRunConfigurationListWidthForKey( | ||
| width, | ||
| event.key, | ||
| containerWidth || 1280, | ||
| ); | ||
| if (nextWidth == null) { | ||
| return; | ||
| } | ||
|
|
||
| event.preventDefault(); | ||
| setWidth(nextWidth); | ||
| setConfigurationListWidth(nextWidth); | ||
| }, | ||
| [width, containerWidth, setConfigurationListWidth], | ||
| ); | ||
|
|
||
| const minWidth = Math.min( | ||
| RUN_CONFIGURATION_LIST_MIN_WIDTH, | ||
| getRunConfigurationListMaxWidth(containerWidth || 1280), | ||
| ); | ||
| const maxWidth = getRunConfigurationListMaxWidth(containerWidth || 1280); | ||
|
|
||
| return ( | ||
| <div ref={containerRef} className="flex min-h-0 min-w-0 flex-1"> | ||
| <div | ||
| ref={listRef} | ||
| style={{ width: `${width}px` }} | ||
| className="relative flex min-h-0 shrink-0 flex-col border-border/70 border-r" | ||
| > | ||
| {list} | ||
| <div | ||
| onPointerDown={handlePointerDown} | ||
| onKeyDown={handleKeyDown} | ||
| style={{ width: RUN_CONFIGURATION_LIST_HANDLE_THICKNESS }} | ||
| className={cn( | ||
| "group absolute top-0 right-0 z-20 flex h-full translate-x-1/2 cursor-col-resize items-center justify-center", | ||
| "transition-colors duration-(--app-duration-fast) ease-(--app-ease-smooth) hover:bg-primary/8", | ||
| )} | ||
| role="separator" | ||
| aria-orientation="vertical" | ||
| aria-label={t("run.resizeConfigurationList")} | ||
| aria-valuenow={Math.round(width)} | ||
| aria-valuemin={Math.round(minWidth)} | ||
| aria-valuemax={Math.round(maxWidth)} | ||
| tabIndex={0} | ||
| > | ||
| <div | ||
| className={cn( | ||
| "h-full w-px bg-transparent transition-colors duration-(--app-duration-fast) ease-(--app-ease-smooth) group-hover:bg-primary", | ||
| isResizing && "bg-primary", | ||
| )} | ||
| /> | ||
| </div> | ||
| </div> | ||
| {isResizing ? <div className="fixed inset-0 z-40 cursor-col-resize" /> : null} | ||
| <div className="flex min-h-0 min-w-0 flex-1 flex-col">{content}</div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
windows/tauri/src/features/run/stores/run-preferences.store.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { create } from "zustand"; | ||
| import { persist } from "zustand/middleware"; | ||
| import { createSelectors } from "@/utils/zustand-selectors"; | ||
| import { createSafeJSONStorage } from "@/utils/zustand-storage"; | ||
| import { RUN_CONFIGURATION_LIST_DEFAULT_WIDTH } from "../utils/run-configuration-list-layout"; | ||
|
|
||
| interface RunPreferencesStore { | ||
| configurationListWidth: number; | ||
| actions: { | ||
| setConfigurationListWidth: (width: number) => void; | ||
| }; | ||
| } | ||
|
|
||
| const useRunPreferencesStoreBase = create<RunPreferencesStore>()( | ||
| persist( | ||
| (set) => ({ | ||
| configurationListWidth: RUN_CONFIGURATION_LIST_DEFAULT_WIDTH, | ||
| actions: { | ||
| setConfigurationListWidth: (configurationListWidth) => set({ configurationListWidth }), | ||
| }, | ||
| }), | ||
| { | ||
| name: "lithe-run-preferences", | ||
| storage: createSafeJSONStorage<Omit<RunPreferencesStore, "actions">>(), | ||
| partialize: ({ actions: _, ...preferences }) => preferences, | ||
| merge: (persistedState, currentState) => ({ | ||
| ...currentState, | ||
| ...(persistedState as Partial<RunPreferencesStore>), | ||
| actions: currentState.actions, | ||
| }), | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| export const useRunPreferencesStore = createSelectors(useRunPreferencesStoreBase); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.