Skip to content

Commit

Permalink
fix: async transition functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Oct 16, 2024
1 parent f695e82 commit ef569c9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion addons/browser/src/renderer/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import * as commas from 'commas:api/renderer'
export function openBrowserTab(url: string) {
return commas.workspace.openPaneTab('browser', {
command: url,
})!
})
}
2 changes: 1 addition & 1 deletion addons/editor/src/renderer/compositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const useEditorTheme = commas.helper.reuse(() => {
export function openCodeEditorTab(file: string) {
return commas.workspace.openPaneTab('editor', {
shell: file,
})!
})
}
9 changes: 4 additions & 5 deletions addons/explorer/src/renderer/compositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export function getDirectoryProcess(directory: string) {
}

export function openFileExplorerTab(directory?: string) {
return commas.workspace.openPaneTab('explorer', { cwd: directory })!
return commas.workspace.openPaneTab('explorer', { cwd: directory })
}

const terminal = $(commas.workspace.useCurrentTerminal())
const settings = commas.remote.useSettings()

export function splitOrCloseFileExplorerTab(directory: string) {
export async function splitOrCloseFileExplorerTab(directory: string) {
const current = terminal
const pane = commas.workspace.getPane('explorer')!
const dir = getDirectoryProcess(directory)
Expand All @@ -22,12 +22,11 @@ export function splitOrCloseFileExplorerTab(directory: string) {
group: current.group,
})
if (existingTab) {
commas.workspace.closeTerminalTab(existingTab)
return
return commas.workspace.closeTerminalTab(existingTab)
}
}
const titlePosition = settings['terminal.view.tabListPosition'] === 'top' ? 'bottom' : 'top'
const tab = openFileExplorerTab(directory)
const tab = await openFileExplorerTab(directory)
if (current && !current.pane) {
const siblings = current.group
? commas.workspace.getTerminalTabsByGroup(current.group)
Expand Down
3 changes: 2 additions & 1 deletion addons/launcher/src/renderer/LauncherList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ const launcherItems = $computed(() => {
})
function toggleCollapsing() {
document.startViewTransition(() => {
const transition = document.startViewTransition(() => {
isCollapsed = !isCollapsed
})
return transition.updateCallbackDone
}
function createLauncher(data: LauncherInfo, index: number) {
Expand Down
2 changes: 1 addition & 1 deletion addons/launcher/src/renderer/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function openLauncher(launcher: Launcher, options: OpenLauncherOpti
command: launcher.command,
character,
})
commas.workspace.activateOrAddTerminalTab(paneTab)
await commas.workspace.activateOrAddTerminalTab(paneTab)
return paneTab
} else {
return commas.workspace.createTerminalTab(profile, {
Expand Down
8 changes: 4 additions & 4 deletions src/api/modules/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getTerminalTabByPane(pane: TerminalTabPane, info: Partial<TerminalTab>
return tabs.find(tab => tab.pane?.name === pane.name && isMatch(tab, info))
}

export type PaneTabInfo = Pick<TerminalTab, 'command' | 'process' | 'cwd' | 'shell'>
export type PaneTabInfo = Pick<TerminalTab, 'command' | 'process' | 'cwd' | 'shell' | 'character'>

function createPaneTab(pane: TerminalTabPane, info?: Partial<PaneTabInfo>) {
return reactive({
Expand All @@ -67,9 +67,9 @@ function createPaneTab(pane: TerminalTabPane, info?: Partial<PaneTabInfo>) {
} as TerminalTab)
}

function openPaneTab(name: string, info?: Partial<PaneTabInfo>) {
async function openPaneTab(name: string, info?: Partial<PaneTabInfo>) {
const pane = getPane(name)
if (!pane) return
if (!pane) return undefined as never
if (!pane.volatile) {
const tab = getTerminalTabByPane(pane, info)
if (tab) {
Expand All @@ -78,7 +78,7 @@ function openPaneTab(name: string, info?: Partial<PaneTabInfo>) {
}
}
const paneTab = createPaneTab(pane, info)
activateOrAddTerminalTab(paneTab)
await activateOrAddTerminalTab(paneTab)
return paneTab
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/TabList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function handleDrop(args: DraggableElementEventPayload<DraggableElementDat
const toEdge = edge === 'top' || edge === 'left'
? 'start'
: (edge === 'bottom' || edge === 'right' ? 'end' : undefined)
moveTerminalTab(tab, args.self.data.index, toEdge)
await moveTerminalTab(tab, args.self.data.index, toEdge)
}
if (args.source.data.dispose) {
args.source.data.dispose()
Expand Down
16 changes: 10 additions & 6 deletions src/renderer/compositions/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,12 @@ export async function createTerminalTab(context: Partial<TerminalContext> = {},
if (command) {
executeTerminalTab(tab, command)
}
document.startViewTransition(() => {
const transition = document.startViewTransition(() => {
const targetIndex = activeIndex + 1
tabs.splice(targetIndex, 0, tab)
activeIndex = targetIndex
})
await transition.updateCallbackDone
return tab
}

Expand Down Expand Up @@ -733,7 +734,7 @@ export function executeTerminalTab(tab: TerminalTab, command: string, restart?:

export function closeTerminalTab(tab: TerminalTab) {
if (tab.pane) {
removeTerminalTab(tab)
return removeTerminalTab(tab)
} else {
return ipcRenderer.invoke('close-terminal', tab.pid)
}
Expand Down Expand Up @@ -831,7 +832,7 @@ function reflowTabGroup(groupTabs: TerminalTab[]) {
}

export function removeTerminalTab(tab: TerminalTab) {
document.startViewTransition(() => {
const transition = document.startViewTransition(() => {
const index = getTerminalTabIndex(tab)
tabs.splice(index, 1)
const groupTabs = tab.group ? getTerminalTabsByGroup(tab.group) : []
Expand All @@ -848,6 +849,7 @@ export function removeTerminalTab(tab: TerminalTab) {
reflowTabGroup(groupTabs)
}
})
return transition.updateCallbackDone
}

export function activateTerminalTab(tab: TerminalTab) {
Expand All @@ -857,21 +859,22 @@ export function activateTerminalTab(tab: TerminalTab) {
}
}

export function activateOrAddTerminalTab(tab: TerminalTab) {
export async function activateOrAddTerminalTab(tab: TerminalTab) {
const index = getTerminalTabIndex(tab)
if (index !== -1) {
activeIndex = index
} else {
document.startViewTransition(() => {
const transition = document.startViewTransition(() => {
const targetIndex = activeIndex + 1
tabs.splice(targetIndex, 0, tab)
activeIndex = targetIndex
})
return transition.updateCallbackDone
}
}

export function moveTerminalTab(tab: TerminalTab, index: number, edge?: 'start' | 'end') {
document.startViewTransition(() => {
const transition = document.startViewTransition(() => {
const fromIndex = tabs.indexOf(tab)
if (fromIndex === index) return
let targetIndex = index
Expand All @@ -892,6 +895,7 @@ export function moveTerminalTab(tab: TerminalTab, index: number, edge?: 'start'
activeIndex += 1
}
})
return transition.updateCallbackDone
}

export function separateTerminalTabGroup(tab: TerminalTab) {
Expand Down

0 comments on commit ef569c9

Please sign in to comment.