Files
superwork/vscode/src/panel/terminalColumn.ts
T

26 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 会话终端落在编辑区哪一栏。
* 数值对齐 VS Code ViewColumn:2 = Two(右侧分屏),-1 = Active(当前栏只加标签)。
*/
export function terminalEditorColumn(split: boolean): 2 | -1 {
return split ? 2 : -1
}
export interface EditorTabGroupLike {
readonly viewColumn: number
readonly isActive: boolean
readonly tabs: ReadonlyArray<{ readonly isTerminal: boolean }>
}
/** URI / 无看板开终端:复用已有终端所在组,避免无 panel 时强制劈出第 2 栏。 */
export function existingTerminalGroupColumn(groups: readonly EditorTabGroupLike[]): number {
const hasTerminal = (g: EditorTabGroupLike) => g.tabs.some(t => t.isTerminal)
const active = groups.find(g => g.isActive && hasTerminal(g))
if (active)
return active.viewColumn // ① 活动组已有终端 → 加进当前组,不劈栏
const first = groups.find(hasTerminal)
if (first)
return first.viewColumn // ② 终端在别的组 → 跟过去,不新开一栏
return -1 // ③ 一个终端组都没有 → Active(当前组只加标签),绝不默认 2
}