Repository navigation
feat(desktop): move sidebar selection to trash with Delete key - #5609
Merged
Merged
Conversation
Left-clicking a file or folder in the sidebar now selects it. Pressing Delete on Windows/Linux, or Delete / Cmd+Backspace on macOS, moves the selection to the OS trash after a native confirmation dialog. The same confirmation now also guards the sidebar context menu's "Move To Trash". Delete keeps its normal behavior in the editor, search box, rename input and other fields. Closes #3148.
Opening another project left `activeItem` pointing at a node from the previous tree, so the Delete shortcut could trash a file the user was no longer viewing. Clear the selection and the rename/create caches in OPEN_PROJECT / RESTORE_BUFFERED_STATE, and reject a selection whose pathname is not inside the current project root. Route the repeated createCache/renameCache resets through a new CLEAR_NAME_INPUT_STATE store action.
The Delete / Cmd+Backspace shortcut dropped the sidebar selection as soon as the event was handled, even when the user cancelled the confirmation. A second press then had nothing to act on, so the shortcut looked broken right after the first (cancelled) attempt — Cmd+Backspace in particular, since macOS users try Backspace first. The selection now stays until the store confirms the item reached the trash, which is also the only place it is cleared. Refs #3148.
… cancelled" This reverts commit f6d40f9.
macOS delivers a keydown for the modifier itself, so holding Cmd before Backspace fires a `Meta` keydown first. The sidebar treated that as typing in the editor and dropped the selection, which left Cmd+Backspace with nothing to trash: the editor then ran its own delete-to-line-start and no confirmation appeared. Fn+Backspace worked because `fn` reports no keydown of its own. Modifier presses are now ignored when deciding whether the editor took over the selection. Fixes the Cmd+Backspace path of #3148.
The selection used to survive any click inside `.project-tree`, including the project title, the empty area and the pending new-file input, while clicks on inputs elsewhere (command palette, editor find) kept it too because the INPUT guard returned before the clear ran. Only a click on a file/folder row — or on the new-file input that belongs to one — now keeps the selection; everything else ends it, matching how the editor and the opened-files list already behaved.
The selection was only a text colour, which several themes define as the same value as the plain label — and folders had no `.active` rule at all — so a keyboard-armed selection was invisible. Both rows now use the theme's 20% accent, which every bundled theme already defines, so no theme file needs to change.
The outside-click guard treated every `<input>` as the rename / new-file box, so clicking the command palette or the editor find field left a pending rename open. It now matches the two inline boxes only; all other inputs behave like any other outside click.
The bar carried a blanket `@click.stop`, so the sidebar's document-level click handler never saw clicks inside it and an open rename input stayed open. Keep the bar open by testing the click target instead.
…ortcut Condense the rationale comments to one or two lines each and keep only the behavioural test cases: 21 down to 12.
Align the renderer's platform flag with `isMac`/`isWindows`/`isLinux`. The local aliases (`isOsxPlatform`, `checkIsOsx`) stay, so templates and CSS class names are untouched. The main process keeps its own `isOsx` export.
… dialog Drop the eager selection reset when Delete fires: the store clears it once the item is really trashed, so cancelling the dialog no longer disarms the shortcut. Also read the event fields directly, and let any non-modifier key end the selection rather than only keys landing on an editable surface.
The built-in TypeScript formatter rewrites `async()` to `async ()`, which the repo's ESLint config rejects, so saving a file fought the linter. Formatting stays available on demand via the ESLint formatter.
3 tasks done
3 of 6 tasks
Wangqkoe
pushed a commit
to Wangqkoe/marktext
that referenced
this pull request
Oct 24, 2026
…ext#5609) Local changes to the pick: - tree.vue keeps the local opened-files divider, sorting and filter and adds the Delete-key handling and its document listeners; the listener cleanup joins the existing onBeforeUnmount. - A folder click selects the folder and still toggles it through the local onToggleFolder. - project.ts already clears the selection and name inputs with the Folder root (clearRootOwnedState), so upstream's extra resets there are not taken; CLEAR_NAME_INPUT_STATE is kept for tree.vue. - The isOsx -> isMac rename the upstream commit carried across unrelated files is not taken; tree.vue passes isOsx to the trash-key helper. - Main keeps screen and createHash, which local code still uses. - nl/ru locales and the .vscode cSpell words are left out. (cherry picked from commit 0d8dba0) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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 #3148
Summary
Pressing
Deletewith a file or folder selected in the sidebar now moves it tothe OS trash, after a native confirmation dialog.
the selection).
Deleteworks on Windows/Linux; on macOS bothDelete(forward delete) andCmd+Backspacework. A bareBackspacenever triggers it.dialog.showMessageBoxwith the cancel button asthe default; it also now guards the sidebar context menu's "Move To Trash".
Deletekeeps its normal behavior in the editor, sidebar search, rename inputand other fields. The project root cannot be trashed from the shortcut.
Type of change
Test plan
New coverage:
packages/desktop/test/unit/specs/sidebar-trash-key.spec.ts— shortcut andtarget rules:
Deleteon every platform,Cmd+Backspaceon macOS only, bareBackspacenever; the WYSIWYG editor vs other editable surfaces; project rootexcluded.
packages/desktop/test/unit/specs/trash-item-confirm.spec.ts— trashes only onthe confirm response, and Cancel/
cancelIdare the defaults.packages/desktop/test/e2e/issue-3148-sidebar-delete-key.spec.ts— clicks asidebar file, presses
Deletewhile the WYSIWYG editor has focus, and assertsthe native dialog gates
shell.trashItem(both stubbed in the main process).Also ran
pnpm run typecheckandpnpm run lint.Notes for reviewers [optional]
stopPropagation()for the Delete key once the editor has focus, and opening afile from the sidebar autofocuses the editor, so the shortcut has to reach the
sidebar selection before muya handles it. Other editable surfaces (search,
rename, command palette) keep their own Delete.
app.evaluate), because a realshowMessageBoxwould block the headless run and a real
shell.trashItemwould delete repofiles.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.