fix: #2143 open missing CLI files as named buffers by Jocs · Pull Request #5758 · marktext/marktext · GitHub
Skip to content

fix: #2143 open missing CLI files as named buffers - #5758

Merged
Jocs merged 3 commits into
developfrom
fix/2143-cli-new-file
Oct 16, 2026
Merged

Jocs merged 3 commits into
developfrom
fix/2143-cli-new-file

Conversation

@Jocs

@Jocs Jocs commented Oct 15, 2026

Copy link
Copy Markdown
Member

Closes #2143

Summary

Running marktext foo.md currently discards the path when the file does not exist. Open it as a named, empty buffer instead, on both initial startup and subsequent CLI invocations. Preserve the absolute target path so Save creates the file directly, including an empty file. Opening and closing an unmodified buffer does not create a file or prompt to save.

Track pending creation separately from unsaved edits through IPC, buffered state, and session restoration. Register watchers and recent documents after the first successful save, and confirm replacement if another process creates the target before that save. Canceling a save keeps the window open. Existing file/directory handling, supported extensions, window preferences, and --new-window remain supported; the parent directory must exist.

Activate the application on macOS when bringing an editor window forward, so CLI invocations restore and focus hidden or minimized windows.

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: filesystem behavior and document state, plus an Electron E2E covering initial launch, first save, second-instance cwd, duplicate opening, unmodified close, --new-window, external-file conflict cancellation, and macOS application activation after hiding/minimizing.
  • pnpm run test:unit — 99 files / 1103 tests passed.
  • pnpm -C packages/desktop exec playwright test test/e2e/cli-missing-file-2143.spec.ts — passed.
  • pnpm run typecheck — passed.
  • pnpm run lint — passed, 0 errors (existing warnings).
  • pnpm run build:unpack — passed.
  • Tested on macOS arm64; built a local .app and verified named CLI opening without an immediate disk write. Local packaging output and launcher are outside the checkout.

Notes for reviewers

To reproduce: run marktext foo.md in an existing directory with no foo.md; check that the buffer is named and the file is absent, then save and check the file is created. While the app remains running, run marktext bar.md; verify the named buffer opens and the window comes forward. Closing an unmodified bar.md buffer should leave no file behind.

No --wait support is included.


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

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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.

🟡 Changes recommended

Critical save-conflict issues and two moderate path/line-ending issues remain unresolved.

2 open findings
What changed in this PR

Adds support for opening missing Markdown CLI paths as named buffers, creating files only on save.

Changes:

  • Tracks pending creation through IPC, renderer state, buffering, and restoration.
  • Adds save conflict handling and macOS window activation.
  • Adds unit and Electron E2E coverage.

Review findings include two critical save/conflict issues and two moderate path/line-ending issues requiring resolution.

File Summary
packages/​desktop/​test/​unit/​specs/​cli-pending-document.spec.ts Tests pending document state and restoration.
packages/​desktop/​test/​unit/​specs/​cli-missing-file.spec.ts Tests missing-file filesystem behavior.
packages/​desktop/​test/​e2e/​cli-missing-file-2143.spec.ts Covers CLI missing-file workflows.
packages/​desktop/​src/​shared/​types/​files.ts Defines pending-creation state types.
packages/​desktop/​src/​renderer/​src/​store/​help.ts Serializes document pending state.
packages/​desktop/​src/​renderer/​src/​store/​editor.ts Tracks pending state and buffering.
packages/​desktop/​src/​main/​windows/​editor.ts Opens and restores pending buffers.
packages/​desktop/​src/​main/​windows/​base.ts Activates macOS applications when focusing windows.
packages/​desktop/​src/​main/​menu/​actions/​file.ts Handles saves and replacement confirmation.
packages/​desktop/​src/​main/​filesystem/​markdown.ts Loads missing files as pending buffers.
packages/​desktop/​src/​main/​editorBufferStore/​index.ts Preserves pending buffers.
packages/​desktop/​src/​main/​app/​index.ts Routes CLI paths and window activation.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/desktop/src/main/menu/actions/file.ts
Comment thread packages/desktop/src/main/windows/editor.ts Outdated
@Jocs
Jocs merged commit ccc1634 into develop Oct 16, 2026
12 checks passed
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.

Open a non-existed file from a command line issue

2 participants