Skip to content

feat(desktop): move sidebar selection to trash with Delete key - #5609

Merged
Jocs merged 13 commits into
developfrom
feat/3148-sidebar-delete-key
Oct 3, 2026
Merged

Jocs merged 13 commits into
developfrom
feat/3148-sidebar-delete-key

Conversation

@Jocs

@Jocs Jocs commented Oct 2, 2026

Copy link
Copy Markdown
Member

Closes #3148

Summary

Pressing Delete with a file or folder selected in the sidebar now moves it to
the OS trash, after a native confirmation dialog.

  • Left-clicking a file or folder row selects it (previously only right-click set
    the selection).
  • Delete works on Windows/Linux; on macOS both Delete (forward delete) and
    Cmd+Backspace work. A bare Backspace never triggers it.
  • The confirmation is a native dialog.showMessageBox with the cancel button as
    the default; it also now guards the sidebar context menu's "Move To Trash".
  • Delete keeps its normal behavior in the editor, sidebar search, rename input
    and other fields. The project root cannot be trashed from the shortcut.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
  • Manually tested on: macOS

New coverage:

  • packages/desktop/test/unit/specs/sidebar-trash-key.spec.ts — shortcut and
    target rules: Delete on every platform, Cmd+Backspace on macOS only, bare
    Backspace never; the WYSIWYG editor vs other editable surfaces; project root
    excluded.
  • packages/desktop/test/unit/specs/trash-item-confirm.spec.ts — trashes only on
    the confirm response, and Cancel/cancelId are the defaults.
  • packages/desktop/test/e2e/issue-3148-sidebar-delete-key.spec.ts — clicks a
    sidebar file, presses Delete while the WYSIWYG editor has focus, and asserts
    the native dialog gates shell.trashItem (both stubbed in the main process).

Also ran pnpm run typecheck and pnpm run lint.

Notes for reviewers [optional]

  • The renderer keydown listener runs in the capture phase: muya calls
    stopPropagation() for the Delete key once the editor has focus, and opening a
    file 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.
  • e2e stubs the native dialog (app.evaluate), because a real showMessageBox
    would block the headless run and a real shell.trashItem would delete repo
    files.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

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.
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5609:

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

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

Jocs added 12 commits October 2, 2026 19:16
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.
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.
@Jocs
Jocs merged commit 0d8dba0 into develop Oct 3, 2026
14 of 17 checks passed
@Jocs
Jocs deleted the feat/3148-sidebar-delete-key branch October 23, 2026 08:32
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]>
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.

Deleting file using Delete key

1 participant