fix(desktop): let F2, Enter and Delete act on sidebar files on Windows by Zane-0x5a · Pull Request #5671 · marktext/marktext · GitHub
Skip to content

fix(desktop): let F2, Enter and Delete act on sidebar files on Windows - #5671

Closed
Zane-0x5a wants to merge 1 commit into
marktext:developfrom
Zane-0x5a:fix/sidebar-shortcuts-windows-paths
Closed

Zane-0x5a wants to merge 1 commit into
marktext:developfrom
Zane-0x5a:fix/sidebar-shortcuts-windows-paths

Conversation

@Zane-0x5a

Copy link
Copy Markdown
Contributor

Related: #1618, #3148 (follow-up to #5638 and #5609)

Summary

On Windows, the sidebar keyboard shortcuts do nothing for files in the tree: F2 and Enter don't open the rename input (#5638), and Delete doesn't ask to move the file to the trash (#5609). Folders work.

Both checks call isPathWithinRoot(selection, root), and on Windows a file and the root use different separators:

  • the root comes from createProjectRoot, which normalizes it with window.path (pathe): C:/Users/me/docs
  • folder nodes are built in the renderer the same way, so they match
  • file nodes come from the watcher, with Windows separators: C:\Users\me\docs\notes.md

So every selected file looks like it is outside the project.

isPathWithinRoot now compares both with / when the root is a Windows path: a drive letter, or a UNC prefix (pathe turns \\server\share into //server/share). POSIX roots are compared as before, since a backslash there is part of a file name.

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: sidebar-rename-key.spec.ts and sidebar-trash-key.spec.ts cover a Windows watcher path under a normalized root (drive letter and UNC), a sibling folder with a common prefix, and a POSIX name containing a backslash. Both new tests fail without the change.
  • Manually tested on: Windows 11. The e2e specs for these shortcuts fail on Windows today and pass with the change:
    • issue-1618-sidebar-rename-key.spec.ts: F2 on a file opens no rename input. With the change, all 3 pass.
    • issue-3207-sidebar-rename-commit.spec.ts: the three tests that rename a file with F2 fail. With the change, all 4 pass.
    • issue-3148-sidebar-delete-key.spec.ts: Delete on a file shows no confirmation. With the change, both pass.

Notes for reviewers [optional]

issue-3148-sidebar-delete-key.spec.ts took the file name with split('/').pop(), which returns the whole path on Windows; it now uses path.basename. Only Windows exercises any of this, and e2e CI runs on Ubuntu, which is presumably why it went unnoticed.


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

🤖 Generated with Claude Code

On Windows the sidebar keyboard shortcuts from marktext#5638 (rename with F2 or
Enter) and marktext#5609 (move to trash with Delete) did nothing for files. The
renderer normalizes the project root with pathe ('C:/docs') and builds
folder nodes the same way, but file nodes come from the watcher with
backslashes ('C:\docs\notes.md'), so isPathWithinRoot treated every
selected file as outside the project.

isPathWithinRoot now compares both with '/' when the root is a Windows
path (drive letter or UNC). POSIX paths are left alone, where a backslash
is part of a name.

The marktext#3148 e2e test also takes the file name with path.basename, so it
passes with Windows paths too.
@Jocs

Jocs commented Oct 10, 2026

Copy link
Copy Markdown
Member

@Jocs Jocs closed this Oct 10, 2026
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.

2 participants