Skip to content

Commit 69ac946

Browse files
committed
fix(editor): default file path
1 parent 9b7e644 commit 69ac946

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

addons/camera/src/renderer/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as os from 'node:os'
21
import * as path from 'node:path'
32
import { ipcRenderer } from '@commas/electron-ipc'
43
import type { TerminalTab } from '@commas/types/terminal'

addons/editor/locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"New File#!editor.1": "新文件",
23
"Edit a text file#!cli.description.edit": "编辑文本文件",
34
"<file>#!cli.usage.edit": "<文件>"
45
}

addons/editor/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"main": "index.js",
88
"author": "commas",
99
"license": "ISC",
10+
"dependencies": {
11+
"unused-filename": "^3.0.1"
12+
},
1013
"devDependencies": {
1114
"monaco-editor": "^0.52.0"
1215
},

addons/editor/src/renderer/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as os from 'node:os'
21
import * as path from 'node:path'
32
import * as commas from 'commas:api/renderer'
3+
import unusedFilename from 'unused-filename'
44
import CodeEditorPane from './CodeEditorPane.vue'
55
import { openCodeEditorTab } from './compositions'
66

@@ -10,6 +10,14 @@ declare module '@commas/electron-ipc' {
1010
}
1111
}
1212

13+
function getNewFileName() {
14+
const name = commas.remote.translate('New File#!editor.1', {
15+
increment: '',
16+
}) + '.txt'
17+
const file = path.join(commas.app.getPath('downloads'), name)
18+
return unusedFilename.sync(file)
19+
}
20+
1321
export default () => {
1422

1523
commas.ui.addCSSFile('dist/renderer/style.css')
@@ -18,7 +26,7 @@ export default () => {
1826
title: '',
1927
component: CodeEditorPane,
2028
factory: info => {
21-
const shell = info?.shell || path.join(os.tmpdir(), '.commas')
29+
const shell = info?.shell || getNewFileName()
2230
return {
2331
shell,
2432
process: shell,

package-lock.json

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)