🐛 fix(vscode): 改动 tab 默认统一视图并保留阅读位置
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
DEFAULT_PR_DIFF_MODE,
|
||||
isPrDiffMode,
|
||||
parsePrDiffMode,
|
||||
type PrDiffMode,
|
||||
} from './prDiffMode'
|
||||
|
||||
describe('DEFAULT_PR_DIFF_MODE', () => {
|
||||
it('默认是 unified', () => {
|
||||
expect(DEFAULT_PR_DIFF_MODE).toBe('unified')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isPrDiffMode', () => {
|
||||
it('仅接受 unified / split', () => {
|
||||
expect(isPrDiffMode('unified')).toBe(true)
|
||||
expect(isPrDiffMode('split')).toBe(true)
|
||||
expect(isPrDiffMode('Unified')).toBe(false)
|
||||
expect(isPrDiffMode('SPLIT')).toBe(false)
|
||||
expect(isPrDiffMode('')).toBe(false)
|
||||
expect(isPrDiffMode(null)).toBe(false)
|
||||
expect(isPrDiffMode(undefined)).toBe(false)
|
||||
expect(isPrDiffMode(3)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parsePrDiffMode', () => {
|
||||
it('split → split', () => {
|
||||
expect(parsePrDiffMode('split')).toBe('split')
|
||||
})
|
||||
|
||||
it('unified → unified', () => {
|
||||
expect(parsePrDiffMode('unified')).toBe('unified')
|
||||
})
|
||||
|
||||
it('缺省 / 非法一律 unified', () => {
|
||||
expect(parsePrDiffMode(undefined)).toBe('unified')
|
||||
expect(parsePrDiffMode(null)).toBe('unified')
|
||||
expect(parsePrDiffMode('')).toBe('unified')
|
||||
expect(parsePrDiffMode('Split')).toBe('unified')
|
||||
expect(parsePrDiffMode('UNIFIED')).toBe('unified')
|
||||
expect(parsePrDiffMode(1)).toBe('unified')
|
||||
expect(parsePrDiffMode({})).toBe('unified')
|
||||
})
|
||||
|
||||
it('返回类型可赋值给 PrDiffMode', () => {
|
||||
const mode: PrDiffMode = parsePrDiffMode('split')
|
||||
expect(mode).toBe('split')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 「改动」tab 的 diff 模式(统一 / 分栏)解析。
|
||||
* 纯逻辑:不碰 VS Code API,便于单测。
|
||||
*/
|
||||
|
||||
export const DEFAULT_PR_DIFF_MODE = 'unified' as const
|
||||
|
||||
export type PrDiffMode = 'unified' | 'split'
|
||||
|
||||
export function isPrDiffMode(x: unknown): x is PrDiffMode {
|
||||
return x === 'unified' || x === 'split'
|
||||
}
|
||||
|
||||
/**
|
||||
* workspaceState 读出值 → 合法模式。
|
||||
* 仅精确字符串 `'split'` 才是分栏;其它一律统一(默认路径)。
|
||||
*/
|
||||
export function parsePrDiffMode(stored: unknown): PrDiffMode {
|
||||
return stored === 'split' ? 'split' : DEFAULT_PR_DIFF_MODE
|
||||
}
|
||||
@@ -588,6 +588,14 @@ export class KanbanWebviewPanel {
|
||||
void prFiles.handleSetPrReviewConfirmed(this, msg)
|
||||
return
|
||||
}
|
||||
if (msg.type === 'pr-diff-mode/get') {
|
||||
prFiles.handleGetPrDiffMode(this)
|
||||
return
|
||||
}
|
||||
if (msg.type === 'pr-diff-mode/set') {
|
||||
void prFiles.handleSetPrDiffMode(this, msg.mode)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// internal: handler 模块访问
|
||||
|
||||
@@ -19,6 +19,7 @@ import { getPullRequest, getRawFile, listPullRequestFiles } from '../../gitea/ap
|
||||
import { readStateJsonComment } from '../../gitea/stateJson'
|
||||
import { readFileSummaries, readSummarySession, writeFileSummary, writeSummarySession } from '../../sessions/prFileSummaryStore'
|
||||
import { readConfirmedSigs, writeConfirmedSigs } from '../../sessions/prReviewStore'
|
||||
import { parsePrDiffMode, type PrDiffMode } from '../../cc/prDiffMode'
|
||||
import { makeNonce } from '../KanbanPanel'
|
||||
|
||||
/**
|
||||
@@ -351,3 +352,22 @@ export async function handleGeneratePrFileSummary(
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const PR_DIFF_MODE_KEY = 'prDiffMode'
|
||||
|
||||
/** 读 workspace 级 diff 模式(缺省 unified),回推 webview。 */
|
||||
export function handleGetPrDiffMode(panel: KanbanWebviewPanel): void {
|
||||
const stored = panel.context.workspaceState.get<unknown>(PR_DIFF_MODE_KEY)
|
||||
const mode = parsePrDiffMode(stored)
|
||||
panel.postMessage({ type: 'pr-diff-mode/show', mode })
|
||||
}
|
||||
|
||||
/** 写 workspace 级 diff 模式;非法值按 unified 落盘。 */
|
||||
export async function handleSetPrDiffMode(
|
||||
panel: KanbanWebviewPanel,
|
||||
mode: unknown,
|
||||
): Promise<void> {
|
||||
const next: PrDiffMode = parsePrDiffMode(mode)
|
||||
await panel.context.workspaceState.update(PR_DIFF_MODE_KEY, next)
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ export type ExtensionToWebview
|
||||
| { type: 'pr-files/show', issueNumber: number, files: PrFile[], confirmed: string[], summaries: Record<string, string>, error?: string }
|
||||
| { type: 'pr-file-diff/show', issueNumber: number, path: string, oldContent: string, newContent: string, oldLang?: string, newLang?: string, error?: string }
|
||||
| { type: 'pr-file-summary/show', issueNumber: number, path: string, summary?: string, error?: string }
|
||||
| { type: 'pr-diff-mode/show', mode: 'unified' | 'split' }
|
||||
// profile 值编辑器粘贴的图片:存盘/读盘的回执,requestId 关联并发请求。
|
||||
| { type: 'profile-asset/saved', requestId: string, assetPath?: string, error?: string }
|
||||
| { type: 'profile-asset/loaded', requestId: string, dataUrl?: string, error?: string }
|
||||
@@ -194,6 +195,8 @@ export type WebviewToExtension
|
||||
| { type: 'pr-file-diff/get', issueNumber: number, path: string, previousPath?: string }
|
||||
| { type: 'pr-file-summary/generate', issueNumber: number, path: string, previousPath?: string }
|
||||
| { type: 'pr-review/set', issueNumber: number, confirmed: Record<string, string> }
|
||||
| { type: 'pr-diff-mode/get' }
|
||||
| { type: 'pr-diff-mode/set', mode: 'unified' | 'split' }
|
||||
// profile 值编辑器:图片存盘(base64→磁盘)与读盘(磁盘→dataUrl)请求。
|
||||
| { type: 'profile-asset/save', requestId: string, base64: string, mediaType: string }
|
||||
| { type: 'profile-asset/load', requestId: string, assetPath: string }
|
||||
|
||||
Reference in New Issue
Block a user