Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): place files/folders at the project root via drag + empty-space click (#1857)
mike-inkeepfb9dc97084d2
diff --git a/.changeset/deselect-to-create-at-root.md b/.changeset/deselect-to-create-at-root.mdnew file mode 100644index 000000000..04993eb4a--- /dev/null+++ b/.changeset/deselect-to-create-at-root.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Clicking the empty space in the sidebar file tree now clears the selection so that New File and New Folder create at the project root. The document you had open stays open in the main view — only the create target changes. Selecting another item, or navigating elsewhere, re-points creation at that item's folder as before.diff --git a/.changeset/drag-folder-to-root.md b/.changeset/drag-folder-to-root.mdnew file mode 100644index 000000000..24be7eedf--- /dev/null+++ b/.changeset/drag-folder-to-root.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Fix drag-and-drop so a nested folder can be moved back to the project root. Dragging a folder (or file) onto the empty space in the sidebar file tree now promotes it to the top level, with a highlight showing where it will land. Previously you could only drop items onto another folder, so there was no way to undo unwanted nesting by dragging.diff --git a/packages/app/package.json b/packages/app/package.jsonindex f6443ed1b..93ef147fa 100644--- a/packages/app/package.json+++ b/packages/app/package.json@@ -25,7 +25,7 @@"measure:fuzz": "bash scripts/measure-fuzz.sh","measure:stress": "bash scripts/measure-stress.sh","perf:compare": "bash scripts/perf-compare.sh",- "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/init-load-byte-stable.e2e.ts tests/stress/single-file-ephemeral.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts",+ "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/init-load-byte-stable.e2e.ts tests/stress/single-file-ephemeral.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts","test:e2e:install-browsers": "playwright install chromium webkit firefox","test:visual": "playwright test --config playwright.visual.config.ts","test:visual:update": "playwright test --config playwright.visual.config.ts --update-snapshots",diff --git a/packages/app/src/components/FileSidebar.dom.test.tsx b/packages/app/src/components/FileSidebar.dom.test.tsxindex 050af750e..7219131ff 100644--- a/packages/app/src/components/FileSidebar.dom.test.tsx+++ b/packages/app/src/components/FileSidebar.dom.test.tsx@@ -137,6 +137,7 @@ mock.module('@/components/FileTree', () => ({createFromTemplate: treeCalls.createFromTemplate,expandAll: treeCalls.expandAll,getFolderState: () => folderState,+ isCreationTargetCleared: () => false,startCreating: treeCalls.startCreating,startCreatingFromTemplate: treeCalls.startCreatingFromTemplate,subscribe: (listener: () => void) => {diff --git a/packages/app/src/components/FileSidebar.menu-action.dom.test.tsx b/packages/app/src/components/FileSidebar.menu-action.dom.test.tsxindex 898a6c77a..6c2c6c1fb 100644--- a/packages/app/src/components/FileSidebar.menu-action.dom.test.tsx+++ b/packages/app/src/components/FileSidebar.menu-action.dom.test.tsx@@ -81,6 +81,7 @@ mock.module('@/components/FileTree', () => ({collapseAll: treeCalls.collapseAll,expandAll: treeCalls.expandAll,getFolderState: () => ({ folderCount: 2, expandedCount: 1 }),+ isCreationTargetCleared: () => false,startCreating: treeCalls.startCreating,startCreatingFromTemplate: treeCalls.startCreatingFromTemplate,subscribe: () => () => {},diff --git a/packages/app/src/components/FileSidebar.tsx b/packages/app/src/components/FileSidebar.tsxindex c53a27358..ef5e10f3f 100644--- a/packages/app/src/components/FileSidebar.tsx+++ b/packages/app/src/components/FileSidebar.tsx@@ -126,10 +126,12 @@ function FileSidebarInner({ onOpenSearch }: FileSidebarProps) {const [tree, setTree] = useState<FileTreeHandle | null>(null);const { activeDocName, activeTarget } = useDocumentContext();- const initialCreateDir =+ const baseCreateDir =activeTarget?.kind === 'folder' || activeTarget?.kind === 'folder-index'? activeTarget.folderPath: defaultInitialDir(activeDocName);+ const [treeCreationCleared, setTreeCreationCleared] = useState(false);+ const initialCreateDir = treeCreationCleared ? '' : baseCreateDir;const isElectronHost = typeof window !== 'undefined' && window.okDesktop != null;@@ -142,10 +144,12 @@ function FileSidebarInner({ onOpenSearch }: FileSidebarProps) {const [folderState, setFolderState] = useState(EMPTY_FOLDER_STATE);useEffect(() => {if (tree === null) return;- setFolderState(tree.getFolderState());- return tree.subscribe(() => {+ const sync = () => {setFolderState(tree.getFolderState());- });+ setTreeCreationCleared(tree.isCreationTargetCleared());+ };+ sync();+ return tree.subscribe(sync);}, [tree]);useEffect(() => {diff --git a/packages/app/src/components/FileTree.tsx b/packages/app/src/components/FileTree.tsxindex e54410dec..33ac1ffec 100644--- a/packages/app/src/components/FileTree.tsx+++ b/packages/app/src/components/FileTree.tsx@@ -258,7 +258,39 @@ const FILE_TREE_DECORATION_SPRITE_SHEET = `<svg data-icon-sprite aria-hidden="tr${MARKDOWN_FILE_ICON_SYMBOL}</svg>`;-const FILE_TREE_UNSAFE_CSS = `${FILE_TREE_EXT_BADGE_CSS}\n${FILE_TREE_RENAME_CHIP_CSS}`;+const FILE_TREE_ROOT_DROP_CSS = `+ [data-file-tree-virtualized-root][data-file-tree-root-drag-target="true"] {+ position: relative;+ }+ [data-file-tree-virtualized-root][data-file-tree-root-drag-target="true"]::after {+ content: "";+ position: absolute;+ inset: 0;+ z-index: 20;+ border-radius: 0.375rem;+ box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--color-primary) 80%, transparent);+ background: color-mix(in oklab, var(--color-primary) 6%, transparent);+ pointer-events: none;+ }+ /* Forced-colors (Windows High Contrast) suppresses box-shadow and overrides+ color-mix backgrounds, so the ring above would vanish. Borders survive+ forced-colors — fall back to a system Highlight border (mirrors the JSX+ in-range halo fallback in globals.css). */+ @media (forced-colors: active) {+ [data-file-tree-virtualized-root][data-file-tree-root-drag-target="true"]::after {+ border: 2px solid Highlight;+ }+ }+`;++const FILE_TREE_CREATION_CLEARED_ATTR = 'data-ok-creation-cleared';+const FILE_TREE_CREATION_CLEARED_CSS = `+ :host([${FILE_TREE_CREATION_CLEARED_ATTR}]) [data-item-focused="true"] {+ --trees-focus-ring-color: transparent;+ }+`;++const FILE_TREE_UNSAFE_CSS = `${FILE_TREE_EXT_BADGE_CSS}\n${FILE_TREE_RENAME_CHIP_CSS}\n${FILE_TREE_ROOT_DROP_CSS}\n${FILE_TREE_CREATION_CLEARED_CSS}`;function createFileTreeStyle(resolvedTheme: string | undefined): CSSProperties {return {@@ -985,6 +1017,7 @@ export interface FileTreeHandle {expandAll(): void;collapseAll(): void;getFolderState(): { folderCount: number; expandedCount: number };+ isCreationTargetCleared(): boolean;subscribe(listener: () => void): () => void;}@@ -1083,6 +1116,9 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {const { conflicts: activeConflicts } = useConflicts();const [newItemRequest, setNewItemRequest] = useState<{ parentDir: string } | null>(null);const [workspace, setWorkspace] = useState<WorkspaceInfo | null>(null);+ const [creationDirCleared, setCreationDirCleared] = useState(false);+ const creationDirClearedRef = useRef(creationDirCleared);+ const handleListenersRef = useRef<Set<() => void>>(new Set());const documentsRef = useRef(documents);const pageMetaRef = useRef(pageMeta);@@ -1228,7 +1264,7 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {selectedFolderPath,navigationPath: activeNavigationPath,} = resolveFileTreeSelection(activeTarget, isNewTabActive ? null : activeDocName);- const activeTreePath = selectedFilePath+ const baseActiveTreePath = selectedFilePath? docNameToTreePath(selectedFilePath,documents.find(@@ -1240,6 +1276,7 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {: activeTarget?.kind === 'asset'? activeTarget.assetPath: null;+ const activeTreePath = creationDirCleared ? null : baseActiveTreePath;const handoffInstallStates = useInstalledAgents().states;const { dispatch: dispatchHandoff } = useHandoffDispatch();@@ -1836,6 +1873,16 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {treePathsSignature,);+ // biome-ignore lint/correctness/useExhaustiveDependencies: setCreationDirCleared is a stable state setter; baseActiveTreePath is the sole trigger.+ useEffect(() => {+ setCreationDirCleared(false);+ }, [baseActiveTreePath]);++ useEffect(() => {+ creationDirClearedRef.current = creationDirCleared;+ for (const listener of handleListenersRef.current) listener();+ }, [creationDirCleared]);+// biome-ignore lint/correctness/useExhaustiveDependencies: activeAncestorTreePathsSignature + treePathsSignature are re-run triggers — the row's visible index shifts when ancestors expand or the tree repopulates.useEffect(() => {if (loading || !activeTreePath) return;@@ -2343,7 +2390,10 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {if (suppressSelectionRef.current || sidebarDragInProgressRef.current) return;if (selectedPaths.length !== 1) return;const selected = selectedPaths[0];- if (selected) activateTreePath(normalizeSelectionPath(selected), documents);+ if (selected) {+ setCreationDirCleared(false);+ activateTreePath(normalizeSelectionPath(selected), documents);+ }};handleRenameErrorRef.current = (message) => {if (recoverMarkdownRenameConflict(message)) return;@@ -2530,8 +2580,16 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {folderStateCacheRef.current = next;return next;},+ isCreationTargetCleared() {+ return creationDirClearedRef.current;+ },subscribe(listener: () => void) {- return model.subscribe(listener);+ handleListenersRef.current.add(listener);+ const unsubscribeModel = model.subscribe(listener);+ return () => {+ handleListenersRef.current.delete(listener);+ unsubscribeModel();+ };},}),[model],@@ -2959,7 +3017,13 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;const item = findTreeItemElement(event.nativeEvent);- if (!item || item.getAttribute('aria-selected') !== 'true') return;+ if (!item) {+ if (clickIsInTreeContentArea(event.nativeEvent)) {+ setCreationDirCleared(true);+ }+ return;+ }+ if (item.getAttribute('aria-selected') !== 'true') return;const rawPath = item.dataset.itemPath;if (!rawPath) return;@@ -3035,6 +3099,7 @@ export function FileTree({ ref }: { ref?: Ref<FileTreeHandle | null> }) {}model={model}style={createFileTreeStyle(resolvedTheme)}+ {...{ [FILE_TREE_CREATION_CLEARED_ATTR]: creationDirCleared ? '' : undefined }}onClickCapture={handleTreeClickCapture}onMouseMove={handleTreeMouseMove}onMouseLeave={cancelCurrentHoverPrewarm}@@ -3161,6 +3226,15 @@ function findTreeItemElement(event: MouseEvent): HTMLElement | null {return null;}+function clickIsInTreeContentArea(event: MouseEvent): boolean {+ for (const entry of event.composedPath()) {+ if (entry instanceof HTMLElement && entry.matches('[data-file-tree-virtualized-scroll]')) {+ return true;+ }+ }+ return false;+}+const FILE_TREE_SKELETON_ROW_WIDTHS = ['w-3/4', 'w-2/3', 'w-4/5', 'w-1/2', 'w-3/5', 'w-2/3'];function FileTreeSkeleton() {diff --git a/packages/app/src/components/file-tree-adapter.test.ts b/packages/app/src/components/file-tree-adapter.test.tsindex f6d210ab2..21efb32e7 100644--- a/packages/app/src/components/file-tree-adapter.test.ts+++ b/packages/app/src/components/file-tree-adapter.test.ts@@ -115,6 +115,14 @@ describe('file-tree-adapter', () => {).toBe('archive/docs/');});+ test('promotes nested entries to root and treats already-root entries as no-ops', () => {+ const root = dropTarget({ kind: 'root', directoryPath: null });+ expect(computeTreeDropDestinationPath('docs/archive/', root)).toBe('archive/');+ expect(computeTreeDropDestinationPath('a/b/c/', root)).toBe('c/');+ expect(computeTreeDropDestinationPath('guide.md', root)).toBe('guide.md');+ expect(computeTreeDropDestinationPath('archive/', root)).toBe('archive/');+ });+test('converts context menu items to sidebar targets and relative paths', () => {const file = menuItem('docs/guide.md', 'file');const folder = menuItem('docs/', 'directory');diff --git a/packages/app/tests/stress/file-tree-deselect-to-root.e2e.ts b/packages/app/tests/stress/file-tree-deselect-to-root.e2e.tsnew file mode 100644index 000000000..4b5512e18--- /dev/null+++ b/packages/app/tests/stress/file-tree-deselect-to-root.e2e.ts@@ -0,0 +1,121 @@+/**+ * Clicking the file tree's empty space "deselects" the active item *for+ * creation purposes*: New File / New Folder then land at the project root,+ * while the editor keeps showing whatever was open (the main view is+ * untouched). Selecting a row — or navigating elsewhere — re-couples creation+ * to the active item.+ *+ * Drives the real browser path: open a nested doc (so the create target is its+ * folder), click the empty tree area, and assert (a) the row deselects, (b) the+ * editor tab is unchanged, (c) a freshly created file lands at the root. A+ * contrast case pins the default — without the empty-space click, creation+ * still lands inside the active folder.+ */+import type { Page } from '@playwright/test';+import { expect, test } from './_helpers';++const SIDEBAR = '[data-slot="sidebar-container"]';++async function clickEmptyTreeArea(page: Page): Promise<void> {+ const scroll = page.locator('[data-file-tree-virtualized-scroll]');+ await expect(scroll).toBeVisible();+ const box = await scroll.boundingBox();+ if (!box) throw new Error('tree scroll container has no bounding box');+ await page.mouse.click(box.x + box.width / 2, box.y + box.height - 8);+}++async function createFileAndGetDocName(+ page: Page,+ baseURL: string,+ name: string,+): Promise<string[]> {+ await page.getByRole('button', { name: 'New File', exact: true }).click();+ const input = page.getByRole('textbox', { name: /rename Untitled\.md/i });+ await expect(input).toBeVisible({ timeout: 10_000 });+ await input.fill(name);+ await input.press('Enter');++ let names: string[] = [];+ await expect(async () => {+ const docs = await page.evaluate(async (url) => {+ const r = await fetch(`${url}/api/documents`);+ return r.ok ? await r.json() : null;+ }, baseURL);+ names = (docs?.documents ?? [])+ .map((d: { docName?: string; path?: string }) => d.docName ?? d.path ?? '')+ .filter(Boolean);+ expect(names.some((n) => n.endsWith(`/${name}`) || n === name)).toBe(true);+ }).toPass({ timeout: 15_000 });+ return names;+}++test.describe('file-tree deselect-to-root', () => {+ test('empty-space click deselects the row for creation but leaves the editor view', async ({+ page,+ api,+ baseURL,+ }) => {+ await api.seedDocs([+ { name: 'folder/note', markdown: '# Note\n' },+ { name: 'top', markdown: '# Top\n' },+ ]);++ await page.goto('/#/folder/note');+ const sidebar = page.locator(SIDEBAR);+ const selectedNote = sidebar.getByRole('treeitem', {+ name: 'note.md',+ exact: true,+ selected: true,+ });+ await expect(selectedNote).toBeVisible({ timeout: 20_000 });+ await expect(page).toHaveURL(/folder\/note$/, { timeout: 10_000 });++ await selectedNote.click();+ const focusedRow = page.locator('[data-item-path="folder/note.md"][data-item-focused="true"]');+ await expect(focusedRow).toHaveCount(1, { timeout: 10_000 });+ const ringColorBefore = await focusedRow.evaluate((el) =>+ getComputedStyle(el).getPropertyValue('--trees-focus-ring-color').trim(),+ );+ expect(ringColorBefore).not.toBe('transparent');+ expect(ringColorBefore.length).toBeGreaterThan(0);++ await clickEmptyTreeArea(page);++ await expect(+ sidebar.getByRole('treeitem', { name: 'note.md', exact: true, selected: true }),+ ).toHaveCount(0, { timeout: 10_000 });+ await expect(async () => {+ const ringColorAfter = await page+ .locator('[data-item-path="folder/note.md"][data-item-focused="true"]')+ .evaluate((el) => getComputedStyle(el).getPropertyValue('--trees-focus-ring-color').trim());+ expect(ringColorAfter).toBe('transparent');+ }).toPass({ timeout: 10_000 });+ await expect(sidebar.getByRole('treeitem', { name: 'note.md', exact: true })).toBeVisible();+ await expect(page).toHaveURL(/folder\/note$/);++ const names = await createFileAndGetDocName(page, baseURL, 'created-at-root');+ expect(names).toContain('created-at-root');+ expect(names).not.toContain('folder/created-at-root');+ });++ test('without the empty-space click, New File still lands in the active folder', async ({+ page,+ api,+ baseURL,+ }) => {+ await api.seedDocs([+ { name: 'folder/note', markdown: '# Note\n' },+ { name: 'top', markdown: '# Top\n' },+ ]);++ await page.goto('/#/folder/note');+ const sidebar = page.locator(SIDEBAR);+ await expect(+ sidebar.getByRole('treeitem', { name: 'note.md', exact: true, selected: true }),+ ).toBeVisible({ timeout: 20_000 });++ const names = await createFileAndGetDocName(page, baseURL, 'created-in-folder');+ expect(names).toContain('folder/created-in-folder');+ expect(names).not.toContain('created-in-folder');+ });+});diff --git a/packages/app/tests/stress/file-tree-drag-to-root.e2e.ts b/packages/app/tests/stress/file-tree-drag-to-root.e2e.tsnew file mode 100644index 000000000..783e0c3ec--- /dev/null+++ b/packages/app/tests/stress/file-tree-drag-to-root.e2e.ts@@ -0,0 +1,174 @@+import type { Page } from '@playwright/test';+import { expect, test } from './_helpers';++async function dragRowToEmptyRootArea(+ page: Page,+ sourcePath: string,+ isFolder: boolean,+): Promise<void> {+ const setup = await page.evaluate(+ ({ sourcePath, isFolder }) => {+ const host = document+ .querySelector('[data-slot="sidebar-container"]')+ ?.querySelector('file-tree-container');+ const shadow = (host as Element & { shadowRoot: ShadowRoot | null })?.shadowRoot;+ if (!shadow) return { ok: false as const, reason: 'no-shadow-root' };++ const rows = Array.from(shadow.querySelectorAll<HTMLElement>('[data-type="item"]'));+ const sourceRow = rows.find((r) => {+ const path = (r.dataset.itemPath ?? '').replace(/\/$/, '').replace(/\.(md|mdx)$/i, '');+ const rowIsFolder = r.dataset.itemType === 'folder';+ return rowIsFolder === isFolder && path === sourcePath;+ });+ const scroll = shadow.querySelector<HTMLElement>('[data-file-tree-virtualized-scroll]');+ if (!sourceRow || !scroll) {+ return {+ ok: false as const,+ reason: 'missing-elements',+ paths: rows.map((r) => `${r.dataset.itemPath}|${r.dataset.itemType}`),+ };+ }++ const dataTransfer = new DataTransfer();+ const fire = (el: Element, type: string, extra: DragEventInit = {}) =>+ el.dispatchEvent(+ new DragEvent(type, {+ bubbles: true,+ cancelable: true,+ composed: true,+ dataTransfer,+ ...extra,+ }),+ );++ const rect = scroll.getBoundingClientRect();+ const x = rect.left + rect.width / 2;+ const y = rect.bottom - 4;+ (window as unknown as { __dndState: unknown }).__dndState = {+ dataTransfer,+ sourceRow,+ scroll,+ x,+ y,+ fire,+ };++ fire(sourceRow, 'dragstart', { clientX: 0, clientY: 0 });+ fire(scroll, 'dragover', { clientX: x, clientY: y });+ return { ok: true as const };+ },+ { sourcePath, isFolder },+ );++ expect(setup.ok, `drag setup failed: ${JSON.stringify(setup)}`).toBe(true);++ await expect+ .poll(+ () =>+ page.evaluate(() => {+ const host = document+ .querySelector('[data-slot="sidebar-container"]')+ ?.querySelector('file-tree-container');+ const shadow = (host as Element & { shadowRoot: ShadowRoot | null })?.shadowRoot;+ return !!shadow?.querySelector(+ '[data-file-tree-virtualized-root][data-file-tree-root-drag-target="true"]',+ );+ }),+ { timeout: 5_000 },+ )+ .toBe(true);++ await page.evaluate(() => {+ const state = (+ window as unknown as {+ __dndState: {+ sourceRow: Element;+ scroll: Element;+ x: number;+ y: number;+ fire: (el: Element, type: string, extra?: DragEventInit) => void;+ };+ }+ ).__dndState;+ state.fire(state.scroll, 'drop', { clientX: state.x, clientY: state.y });+ state.fire(state.sourceRow, 'dragend', { clientX: state.x, clientY: state.y });+ });+}++async function expectDocNames(+ page: Page,+ baseURL: string,+ { present, absent }: { present: string; absent: string },+): Promise<void> {+ await expect(async () => {+ const docs = await page.evaluate(async (url) => {+ const r = await fetch(`${url}/api/documents`);+ return r.ok ? await r.json() : null;+ }, baseURL);+ const names: string[] = (docs?.documents ?? [])+ .map((d: { docName?: string; path?: string }) => d.docName ?? d.path ?? '')+ .filter(Boolean);+ expect(names).toContain(present);+ expect(names).not.toContain(absent);+ }).toPass({ timeout: 15_000 });+}++test.describe('file-tree drag-to-root (PRD-7043)', () => {+ test('dropping a nested folder on empty tree space promotes it to the project root', async ({+ page,+ api,+ baseURL,+ }) => {+ await api.seedDocs([+ { name: 'parent/child/note', markdown: '# Note\n\nNested.\n' },+ { name: 'top', markdown: '# Top\n' },+ ]);++ await page.goto('/');+ const sidebar = page.locator('[data-slot="sidebar-container"]');+ const parentRow = sidebar.getByRole('treeitem', { name: 'parent', exact: true });+ await expect(parentRow).toBeVisible({ timeout: 20_000 });++ await parentRow.click();+ await expect(sidebar.getByRole('treeitem', { name: 'child', exact: true })).toBeVisible({+ timeout: 10_000,+ });++ await dragRowToEmptyRootArea(page, 'parent/child', true);++ await expectDocNames(page, baseURL, { present: 'child/note', absent: 'parent/child/note' });++ await expect(sidebar.getByRole('treeitem', { name: 'child', exact: true })).toBeVisible({+ timeout: 10_000,+ });+ });++ test('dropping a nested file on empty tree space promotes it to the project root', async ({+ page,+ api,+ baseURL,+ }) => {+ await api.seedDocs([+ { name: 'folder/note', markdown: '# Note\n\nNested file.\n' },+ { name: 'top', markdown: '# Top\n' },+ ]);++ await page.goto('/');+ const sidebar = page.locator('[data-slot="sidebar-container"]');+ const folderRow = sidebar.getByRole('treeitem', { name: 'folder', exact: true });+ await expect(folderRow).toBeVisible({ timeout: 20_000 });++ await folderRow.click();+ await expect(sidebar.getByRole('treeitem', { name: 'note.md', exact: true })).toBeVisible({+ timeout: 10_000,+ });++ await dragRowToEmptyRootArea(page, 'folder/note', false);++ await expectDocNames(page, baseURL, { present: 'note', absent: 'folder/note' });++ await expect(sidebar.getByRole('treeitem', { name: 'note.md', exact: true })).toBeVisible({+ timeout: 10_000,+ });+ });+});diff --git a/patches/@pierre%[email protected] b/patches/@pierre%[email protected]index 279e6c91d..420c13364 100644--- a/patches/@pierre%[email protected]+++ b/patches/@pierre%[email protected]@@ -24,3 +24,33 @@ index 95778fc6e74ef7262a54ffd473e670a6be14786c..d39b43e84a33187ebdec7c67348ca099getFocusedPath() {return this.#controller.getFocusedPath();}+diff --git a/dist/render/FileTreeView.js b/dist/render/FileTreeView.js+index 50a32001d7a7d3612b7f1929ccb11b3f1cbffd4f..260b5b0807ac3c844043c644c8a6760b3c642be2 100644+--- a/dist/render/FileTreeView.js++++ b/dist/render/FileTreeView.js+@@ -128,7 +128,16 @@ function getShadowPointElementByGeometry(rootNode, clientX, clientY) {+ }+ function resolveDropTargetFromElement(target) {+ const rowButton = target?.closest?.("[data-type=\"item\"]");+- if (!(rowButton instanceof HTMLElement)) return null;++ if (!(rowButton instanceof HTMLElement)) {++ const scrollArea = target?.closest?.("[data-file-tree-virtualized-scroll]");++ if (scrollArea instanceof HTMLElement) return {++ directoryPath: null,++ flattenedSegmentPath: null,++ hoveredPath: null,++ kind: "root"++ };++ return null;++ }+ const hoveredPath = rowButton.dataset.itemPath ?? null;+ if (hoveredPath == null) return null;+ const flattenedSegment = target?.closest?.("[data-item-flattened-subitem]");+@@ -1806,6 +1815,7 @@ function FileTreeView({ composition, controller, gitStatusByPath, ignoredGitDire+ "data-file-tree-has-context-menu-action-lane": contextMenuEnabled && contextMenuButtonTriggerEnabled ? "true" : void 0,+ "data-file-tree-has-git-lane": gitLaneActive ? "true" : void 0,+ "data-file-tree-virtualized-root": "true",++ "data-file-tree-root-drag-target": dragTarget?.kind === "root" ? "true" : void 0,+ onDragLeave: dragAndDropEnabled ? handleTreeDragLeave : void 0,+ onDragOver: dragAndDropEnabled ? handleTreeDragOver : void 0,+ onDrop: dragAndDropEnabled ? handleTreeDrop : void 0,