Repository navigation
fix: #3207 #3385 commit sidebar rename/create when clicking away - #5646
Conversation
…3385) The sidebar's inline rename and new-file inputs only committed on Enter; clicking or focusing away ran CLEAR_NAME_INPUT_STATE() and discarded the edit (and cancelled a pending file creation). This matches neither Finder nor Windows Explorer, which accept the edit on click-away. The pending text now lives in the project store (nameInputValue) so the tree's click / context-menu handlers can commit it via the new COMMIT_NAME_INPUT() action, mirroring Enter. Escape still cancels. Seeding the value in the store's SIDEBAR::rename / SIDEBAR::new handlers keeps the single shared ref from being overwritten by every mounted row component. The existing stem-only preselection for files (#5638) is unchanged. Tests: - unit: sidebar-name-input-commit.spec.ts - e2e: issue-3207-sidebar-rename-commit.spec.ts
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Duplicate submissions, missed click-away targets, and stale context-menu paths remain unresolved.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Updates sidebar rename and creation flows to accept pending edits on click-away, addressing #3207 and #3385 while preserving Escape cancellation.
Changes:
- Centralizes pending input text and commit dispatch in the project store.
- Connects sidebar inputs and click-away handlers to shared state.
- Adds unit and end-to-end regression tests.
| File | Description |
|---|---|
| packages/desktop/test/unit/specs/sidebar-name-input-commit.spec.ts | Tests commit dispatch and empty-create handling. |
| packages/desktop/test/e2e/issue-3207-sidebar-rename-commit.spec.ts | Tests rename and creation on click-away. |
| packages/desktop/src/renderer/src/store/project.ts | Adds shared input state and commit action. |
| packages/desktop/src/renderer/src/components/sideBar/treeFolder.vue | Uses shared folder input state. |
| packages/desktop/src/renderer/src/components/sideBar/treeFile.vue | Uses shared file rename state. |
| packages/desktop/src/renderer/src/components/sideBar/tree.vue | Commits pending edits on document clicks and context menus. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| projectStore.CHANGE_ACTIVE_ITEM({}) | ||
| } | ||
| projectStore.CLEAR_NAME_INPUT_STATE() | ||
| projectStore.COMMIT_NAME_INPUT() |
| if (isNameInput(target)) return | ||
|
|
||
| projectStore.CLEAR_NAME_INPUT_STATE() | ||
| projectStore.COMMIT_NAME_INPUT() |
| function COMMIT_NAME_INPUT(): void { | ||
| const value = nameInputValue.value | ||
| if (renameCache.value) { | ||
| RENAME_IN_SIDEBAR(value) |
Three follow-ups from the Copilot review of #5646: - Listen for the document click in the capture phase. Targets that call event.stopPropagation() (project heading / collapse arrow, editor tabs) never reached the bubbling handler, so the pending edit was not committed — collapsing the tree even hid the input without saving. - Keep the sidebar selection on the renamed path. A context menu opened while the commit was in flight kept the old pathname, so its actions targeted a path that no longer existed (Delete/Rename no-op, New File created nowhere). The selection now follows the rename. - Make rename/create single-flight per input session. The caches are only cleared once the filesystem work resolves, so a second click could submit the same edit again (double move -> spurious error, double write). Regression coverage: capture-phase e2e (project heading), duplicate-commit unit tests, and a selection-sync unit test.
|
Thanks for the review — all three findings are real. Verified and fixed in b5b125b:
|
Committing the pending name on contextmenu was fragile: the row opens the native menu (and sets the selection) synchronously, while the rename commits asynchronously, and the menu's items read the selection when clicked. Even after syncing the selection to the new path, "New File" from that menu still produced no input, because the renamed folder is re-created collapsed and handleInputFocus had already run before the node existed. Keep the click-away commit for left clicks (the #3207 behaviour) and restore the pre-existing cancel-on-right-click. The selection is still synced to the renamed path so F2 / Delete right after a rename act on the new node.
|
Update on finding 2 (stale context-menu target) in ed1d5dc. I reproduced and re-examined it with an instrumented build, and the earlier fix (syncing
So committing on right-click cannot be made robust here without also reworking when the menu opens and how the renamed (collapsed) node is revealed. The issues (#3207 / #3385) ask for click-away with the left button, which is what the PR now does:
The |
…g flag Replace the `nameInputPending` single-flight guard with a simpler rule: `RENAME_IN_SIDEBAR` / `CREATE_FILE_DIRECTORY` capture what they need from the caches and clear the input state synchronously, before the async filesystem work. A second click-away then finds no open input and is a no-op, and the input closes immediately (like Finder) rather than staying visible until the filesystem call resolves. Trade-off: on failure the input no longer stays open for a retry; the error notification is shown and the user can rename/create again. Also drops the now-unneeded `finally` plumbing.
|
Update on finding 3 (duplicate submissions) in a6fcc70. Replaced the Trade-off: on failure the input no longer stays open for retry — an error notification is shown and the user can rename/create again. Verified: unit tests (rename/create submitted once per session, selection sync) and the sidebar e2e set (17 tests) pass. |

Closes #3207
Closes #3385
Summary
The sidebar's inline rename and new-file inputs only committed on Enter. Clicking or focusing away ran
CLEAR_NAME_INPUT_STATE()and silently discarded the edit — and cancelled a pending file creation. That matches neither Finder nor Windows Explorer, which accept the edit on click-away.This changes click-away / context-menu-away to commit the pending edit (via a new
COMMIT_NAME_INPUT()store action), mirroring Enter:.mdis written)The pending text is moved into the project store (
nameInputValue) so the tree's document-level click handler can read and commit it. The value is seeded in the store'sSIDEBAR::rename/SIDEBAR::newhandlers, so the single shared ref is not overwritten by every mounted row component (an earlier attempt that set it per-component broke folder rename because each row clobbered it).The stem-only preselection for files introduced in #5638 is unchanged, which covers the cursor request in #3385.
Type of change
Test plan
New tests:
packages/desktop/test/unit/specs/sidebar-name-input-commit.spec.ts— rename commit, create commit, empty-create drop, no-op.packages/desktop/test/e2e/issue-3207-sidebar-rename-commit.spec.ts— click another row, click the editor area, and New File then click away.Verified locally:
Notes for reviewers
#3207and#3385share the same root cause (click-away discards the edit) so they are fixed together; #3385's "select the name without the extension" half was already handled by #5638.The full
pnpm run test:unitsuite has 12 pre-existing failures from a Node 25localStorage.clear is not a functionenvironment issue; they fail identically on a cleandevelop.