Skip to content

Commit f5ccbf1

Browse files
committed
fix(explorer): split when calling from cli
1 parent 3116dbb commit f5ccbf1

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

addons/explorer/src/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default () => {
5656
async handler({ sender, argv, cwd }) {
5757
const directory = argv.length ? path.resolve(cwd, argv[0]) : cwd
5858
await fs.promises.access(directory, fs.constants.R_OK)
59-
commas.frame.send(sender, 'open-explorer', directory)
59+
commas.frame.send(sender, 'split-explorer', directory)
6060
},
6161
})
6262

addons/explorer/src/renderer/compositions.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function openFileExplorerTab(directory?: string) {
1212
const terminal = $(commas.workspace.useCurrentTerminal())
1313
const settings = commas.remote.useSettings()
1414

15-
export async function splitOrCloseFileExplorerTab(directory: string) {
15+
export async function splitFileExplorerTab(directory: string) {
1616
const current = terminal
1717
const pane = commas.workspace.getPane('explorer')!
1818
const dir = getDirectoryProcess(directory)
@@ -22,7 +22,10 @@ export async function splitOrCloseFileExplorerTab(directory: string) {
2222
group: current.group,
2323
})
2424
if (existingTab) {
25-
return commas.workspace.closeTerminalTab(existingTab)
25+
return {
26+
tab: existingTab,
27+
exists: true,
28+
}
2629
}
2730
}
2831
const titlePosition = settings['terminal.view.tabListPosition'] === 'top' ? 'bottom' : 'top'
@@ -40,4 +43,15 @@ export async function splitOrCloseFileExplorerTab(directory: string) {
4043
)
4144
}
4245
}
46+
return {
47+
tab,
48+
exists: false,
49+
}
50+
}
51+
52+
export async function splitOrCloseFileExplorerTab(directory: string) {
53+
const { tab, exists } = await splitFileExplorerTab(directory)
54+
if (exists) {
55+
return commas.workspace.closeTerminalTab(tab)
56+
}
4357
}

addons/explorer/src/renderer/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as os from 'node:os'
22
import * as commas from 'commas:api/renderer'
33
import FileExplorerPane from './FileExplorerPane.vue'
4-
import { getDirectoryProcess, openFileExplorerTab, splitOrCloseFileExplorerTab } from './compositions'
4+
import { getDirectoryProcess, openFileExplorerTab, splitFileExplorerTab, splitOrCloseFileExplorerTab } from './compositions'
55

66
declare module '@commas/electron-ipc' {
77
export interface RendererEvents {
88
'open-explorer': (directory?: string) => void,
9+
'split-explorer': (directory: string) => void,
910
}
1011
}
1112

@@ -36,6 +37,10 @@ export default () => {
3637
openFileExplorerTab(directory)
3738
})
3839

40+
commas.ipcRenderer.on('split-explorer', (event, directory) => {
41+
splitFileExplorerTab(directory)
42+
})
43+
3944
commas.context.handle('global-renderer:show-directory', (directory) => {
4045
splitOrCloseFileExplorerTab(directory)
4146
})

0 commit comments

Comments
 (0)