Skip to content

fix: #3207 #3385 commit sidebar rename/create when clicking away - #5646

Merged
Jocs merged 4 commits into
developfrom
fix/3207-sidebar-rename-commit-on-blur
Oct 7, 2026
Merged

Jocs merged 4 commits into
developfrom
fix/3207-sidebar-rename-commit-on-blur

Conversation

@Jocs

@Jocs Jocs commented Oct 7, 2026

Copy link
Copy Markdown
Member

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:

  • rename: commits the typed name
  • new file: creates a file, unless the name is empty (guarded so no stray .md is written)
  • Escape still cancels

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's SIDEBAR::rename / SIDEBAR::new handlers, 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

  • Bug fix (non-breaking, fixes an issue)

Test plan

  • New tests added
  • Manually tested on: macOS

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:

pnpm run typecheck   # pass
pnpm run lint        # 0 errors
pnpm -C packages/desktop exec playwright test \
  test/e2e/issue-3207-sidebar-rename-commit.spec.ts \
  test/e2e/issue-1618-sidebar-rename-key.spec.ts \
  test/e2e/issue-3148-sidebar-delete-key.spec.ts \
  test/e2e/sidebar-focus-model.spec.ts \
  test/e2e/new-file-collapsed-folder-3439.spec.ts   # all pass

Notes for reviewers

#3207 and #3385 share 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:unit suite has 12 pre-existing failures from a Node 25 localStorage.clear is not a function environment issue; they fail identically on a clean develop.

…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
@Jocs
Jocs requested a balanced review from Copilot October 7, 2026 11:37
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5646:

Run: https://github.com/marktext/marktext/actions/runs/37619967835

Artifact Size Link
marktext-windows-arm64 278.2 MB Download
marktext-macos-arm64 285.6 MB Download
marktext-linux 635.0 MB Download
marktext-windows-x64 286.3 MB Download
marktext-macos-x64 295.9 MB Download

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Duplicate submissions, missed click-away targets, and stale context-menu paths remain unresolved.

Review effort: Balanced
Findings: 3 Medium severity

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()
Comment on lines +224 to +227
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.
@Jocs

Jocs commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review — all three findings are real. Verified and fixed in b5b125b:

  1. Click targets using @click.stop were missed. The document click listener is now registered in the capture phase (matching removeEventListener), so the project heading / collapse arrow and editor tabs reach the commit. Regression e2e added: renaming then clicking the project heading still commits.

  2. Stale context-menu target after commit. A successful rename now moves the sidebar selection to the new path (activeItem pathname/name), so a menu opened while the commit was in flight acts on the renamed node instead of a path that no longer exists. This also fixes the pre-existing staleness where pressing F2/Delete right after an Enter-rename targeted the old path. Unit test added.

  3. Duplicate submissions. Rename/create are now single-flight per input session (the caches are only cleared once the filesystem work resolves, so a second click could re-submit). A subsequent click while a commit is pending is ignored. Unit tests added for both rename and create.

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.
@Jocs

Jocs commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

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 activeItem after the rename) was not sufficient. Confirmed details:

  • Committing the pending rename from the contextmenu handler is fragile: the row opens the native menu synchronously and sets the selection to the old node, while the rename commits asynchronously, and the menu items read the selection only when clicked.
  • Even after activeItem was synced to the new path, New File from that menu still produced no input: the renamed folder is re-created collapsed, and the folder's handleInputFocus had already run (before the new node existed), so the create input never renders. Instrumented state: the create ran with the correct new dirname, but the target folder was collapsed (folder-contents count 0).

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 activeItem sync is retained so F2 / Delete immediately after a rename act on the renamed node rather than the old path.

…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.
@Jocs

Jocs commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Update on finding 3 (duplicate submissions) in a6fcc70.

Replaced the nameInputPending flag with a simpler rule, per review discussion: RENAME_IN_SIDEBAR / CREATE_FILE_DIRECTORY now capture the source/destination they need and clear the input state synchronously, before the async filesystem call. A second click-away then finds no open input and is a no-op, and the input closes immediately on submit instead of staying visible until the fs call resolves.

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.

@Jocs
Jocs merged commit 20ae0b9 into develop Oct 7, 2026
11 checks passed
@Jocs
Jocs deleted the fix/3207-sidebar-rename-commit-on-blur branch October 7, 2026 12:36
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.

Improve the rename short key in sidebar Sidebar: clicking out of renaming doesn't set new name

2 participants