Skip to content

Commit

Permalink
feat: support opening markdown smb files on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Jan 23, 2025
1 parent 554a569 commit d9fca0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/server/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ function getExcludeRegex () {
}

function withRepo<T> (repo = 'main', callback: (repoPath: string, ...targetPath: string[]) => Promise<T>, ...target: string[]): Promise<T> {
const repoPath = repo.startsWith(ROOT_REPO_NAME_PREFIX)
const isRootRepo = repo.startsWith(ROOT_REPO_NAME_PREFIX)

const repoPath = isRootRepo
? repo.substring(ROOT_REPO_NAME_PREFIX.length)
: repository.getPath(repo)

Expand All @@ -80,7 +82,9 @@ function withRepo<T> (repo = 'main', callback: (repoPath: string, ...targetPath:
}

return callback(repoPath, ...target.map(x => {
const targetPath = path.join(repoPath, x)
const targetPath = isRootRepo
? x.replace(/^\//, repoPath) // replace first / to repoPath for case of `\\127.0.0.1/test/a.md`
: path.join(repoPath, x)

if (!targetPath.startsWith(repoPath)) {
throw new Error('Path error.')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/services/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ export async function switchDocByPath (path: string): Promise<void> {

let root = '/'
if (isWindows) {
const regMatch = path.match(/^([a-zA-Z]:\\)/)
const regMatch = path.match(/^([a-zA-Z]:\\|\\\\)/)
if (regMatch) {
root = regMatch[1]
path = path.replace(root, '/')
Expand Down

0 comments on commit d9fca0b

Please sign in to comment.