Repository navigation
feat(desktop): rename sidebar selection with F2 / Enter (#1618) - #5638
Merged
Merged
Conversation
F2 (VS Code) and Enter (Finder / Windows Explorer) open the inline rename input on the selected file or folder, reusing the context-menu flow. The input preselects the file stem so typing replaces the name and keeps the extension, matching VS Code's explorer. Folders select the whole name. Enter stays a line break in the WYSIWYG editor: the shortcut defers to editable surfaces, except F2 which has no editor meaning.
Clicking the project tree now takes DOM focus and clicking outside moves it away, so F2 / Enter / Delete act on the sidebar only while the tree is focused. A single click opens a file but keeps that focus; a double click hands it to the editor. Delete no longer hijacks the editor's forward-delete. Adds focusOutline/inactive-selection styling and click-empty-space-clears-selection, matching VS Code.
…1618) Restoring the target tab's caret sets a DOM selection inside the contenteditable, which pulls DOM focus into the editor. After a sidebar-initiated switch, ask the tree to take the focus back so the keyboard scope stays in the sidebar.
Keep only the ones recording behaviour the code cannot express: the browser's mousedown focus default, the DOM-selection focus pull, and the double-click/pending-focus mechanism.
…1618) pendingFocusPath, preserveFocusOnMount and the file-loaded preserveFocus payload are replaced by a single pathname-keyed open intent in the editor store, read at whichever focus point runs (first mount or file-loaded). TabOptions.preserveFocus and its main-process passthrough are gone.
Escape clears the selection directly and the trailing "any other key ends the selection" block is gone — the keydown handler is focus-scoped now, so a stale selection cannot happen. Drop the name-input early return (both predicates already bail on editableTarget / isEditingName), collapse the closest() guards, and remove the now-unused isModifierKey and its test.
3 tasks done
Jocs
added a commit
that referenced
this pull request
Oct 7, 2026
* fix(desktop): commit sidebar rename/create when clicking away (#3207, #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 * fix(desktop): address click-away review findings (#3207, #3385) 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. * fix(desktop): don't commit sidebar rename on right-click (#3207) 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. * refactor(desktop): close the name input on submit instead of a pending 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.
4 of 6 tasks
3 of 6 tasks
csells
added a commit
to csells/MarkText
that referenced
this pull request
Oct 13, 2026
Upstream's tree keeps focus when a single click opens or switches to a file (marktext#5638). A Core document view mounts for each document and placing its restored caret moves the browser's focus into it. The leased view now owns the open intent, and a view mounted while the tree, or a name being edited in it, had focus returns focus there unless the open asked for the editor.
csells
added a commit
to csells/MarkText
that referenced
this pull request
Oct 13, 2026
Upstream marktext#5638 focused the contenteditable before Muya's focus() so a double click on a sidebar file leaves a blinking caret. Muya's own focus() here takes DOM focus on every path before restoring the model's exact selection, which keeps command-palette review commands on their selection.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1618
Summary
Make the sidebar project tree a DOM focus scope, then build the keyboard rename on top of it.
Focus scope
.tree-wrapperis focusable (tabindex="0"). Clicking the tree takes focus; clicking outside moves it away (browser default).setFocus([]) + setSelection([])on empty click, inactive selection on blur).documentcapture listener to the tree container, so keys only act on the sidebar while the tree owns focus. TheisMuyaEditorTargetallow-list is gone.Open / focus semantics
Enter/F2rename work right after opening a file (issue Press Enter on file name to rename selected file #1618's original request).file-loaded— so no flag has to travel through main's open path. A newMuya.init({ focus })option lets the pane skip its initial caret.Rename
F2/Enteropen the same inline rename input the context menu uses, with the file stem preselected (extension kept).Delete
Delete(andCmd+Backspace) still moves the selected file/folder to the trash, but only while the tree has focus. In the editor, forward-delete edits text again instead of trashing the sidebar selection (feat(desktop): move sidebar selection to trash with Delete key #5609's global hijack).Styling
--focusColor, matchinglist.focusOutline), selection dims once focus leaves (matchinglist.inactiveSelectionBackground), and inline name inputs use the focus border.Type of change
Test plan
New tests added (or explain why not needed)
Manually tested on: macOS
test/unit/specs/sidebar-rename-key.spec.ts,sidebar-trash-key.spec.ts— shortcut/selection rules and stem preselection.test/e2e/sidebar-focus-model.spec.ts— click row / empty space / outside, double-click focus.test/e2e/issue-1618-sidebar-rename-key.spec.ts— single click keeps tree focus then F2 renames; double click focuses the editor where Enter stays a line break; Enter renames a folder; focus returns to the tree after committing.test/e2e/issue-3148-sidebar-delete-key.spec.ts— Delete trashes the tree selection; Delete inside the editor edits text and leaves the file alone.pnpm run lint,pnpm run typecheck, the muya suite (2361 tests) and the existing sidebar specs (Sidebar collapse state memory inconsistant #2421, failed to new file | 新建文件失败 #3439, Find panel behaviour wanting #3458) pass.Notes for reviewers
F2/Enter/Deleteonly apply to the sidebar while the tree has focus.packages/muya/src/editor/index.tsgained an optionalinit({ focus })argument (defaulttrue, so existing callers are unchanged).By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.