Skip to content

fix(sidebar): sort projects by creation time and auto-scroll while dragging - #1272

Open
130rockirt wants to merge 1 commit into
KunAgent:developfrom
130rockirt:codex/fix-sidebar-project-order
Open

fix(sidebar): sort projects by creation time and auto-scroll while dragging#1272
130rockirt wants to merge 1 commit into
KunAgent:developfrom
130rockirt:codex/fix-sidebar-project-order

Conversation

@130rockirt

Copy link
Copy Markdown

Summary

Fix two sidebar project-list issues:

  1. Sort projects by creation date (newest first). The project list previously fell back to alphabetical order (localeCompare on paths). Now the sidebar reads each workspace folder's filesystem creation time (birthtime, with mtime fallback for filesystems without birthtime support) via a new bounded workspace:creation-times IPC channel and sorts project groups newest-first. Projects whose creation time is unavailable sink below dated projects and keep the legacy active-first/name order relative to each other. Explicit user drag ordering (saved in kun.sidebarOrder.v1) still wins when present.

  2. Auto-scroll while dragging. HTML5 drag-and-drop never scrolls containers, so when a project list is taller than the sidebar, dragging a row (e.g. dragging zhihu to above kun at the top) could not reach targets outside the viewport. Scroll containers marked data-kun-drag-scroll now auto-scroll when the dragged pointer hovers near their top/bottom edge (capture-phase document listeners, so row-level stopPropagation in drop-position handlers cannot silence it; dragend/drop always stop the scroller).

Changes

  • src/main/ipc: new workspace:creation-times handler + workspaceCreationTimesPayloadSchema (max 256 roots, strict, trimmed paths).
  • src/shared/kun-gui-api*: WorkspaceCreationTimeEntry type + getWorkspaceCreationTimes surface.
  • src/preload: expose getWorkspaceCreationTimes; extract dataMigration into its own module to keep index.ts under the 700-line file gate.
  • src/renderer/.../sidebar-project-selectors.ts: compareWorkspacePathsByCreation — newest-first by creation time, undated projects sink, tie/unknown falls back to legacy comparator.
  • src/renderer/.../sidebar-project-creation-times.ts: useSidebarWorkspaceCreationTimes hook (identity-keyed, deduped, keeps stale map while refetching to avoid double reshuffle).
  • src/renderer/.../sidebar-worktree-discovery.ts: extract useSidebarWorktreeDiscovery hook from SidebarProjectsSection (keeps the file under the 700-line gate after wiring creation times).
  • src/renderer/.../sidebar-drag-auto-scroll.ts: edge-proximity velocity + rAF scroller + document-level capture registration; Sidebar.tsx registers it once, projects list container opts in via the attribute.

Tests

  • New: sidebar-project-selectors.creation-order.test.ts (ordering, case-insensitive key matching, undated sink, tie active-first, legacy fallback), sidebar-drag-auto-scroll.test.ts (velocity ramp/clamp/minimum, continuous scrolling, stop on middle/drop/dragend, capture-phase), workspace:creation-times handler test (real tmpdir, missing path → null, schema rejection), schema test.
  • npm run typecheck
  • npm run check:file-lines
  • npx eslint on all touched files ✅
  • Sidebar selector/drag/order vitest suites (94 tests) ✅; workspace IPC suite ✅
  • Full npm run test: all sidebar/preload/IPC/shared tests pass. 20 pre-existing failures in src/main symlink/daemon/migration/installer suites reproduce on a clean origin/develop checkout (Windows sandbox, e.g. daemon-runtime.test.ts fails identically on develop) and are unrelated to this change.

…agging

Project groups now sort newest-first by workspace folder creation time
(birthtime via a new workspace:creation-times IPC, mtime fallback on
filesystems without birthtime); undated projects sink below dated ones and
keep the legacy active-first/name order. Explicit drag ordering saved in
kun.sidebarOrder.v1 still wins.

HTML5 drag-and-drop never scrolls containers, so rows outside the viewport
were unreachable drop targets. Sidebar scroll containers marked
data-kun-drag-scroll now auto-scroll while the dragged pointer hovers near
their top/bottom edge, via document-level capture listeners that survive
row-level stopPropagation and always stop on dragend/drop.

Also extract preload dataMigration and the worktree-discovery effect into
their own modules to stay under the 700-line file gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant