dsh-vscode-mode 0.29.2 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -11
- package/lib/client.js +178 -51
- package/lib/client.js.map +1 -1
- package/lib/index.js +4860 -1576
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/dsh-vscodemode-html-plan/LICENSE +202 -0
- package/skills/dsh-vscodemode-html-plan/SKILL.md +147 -0
- package/skills/dsh-vscodemode-html-plan/examples/scheduled-send.html +298 -0
- package/skills/dsh-vscodemode-html-plan/references/blocks.md +227 -0
- package/skills/dsh-vscodemode-html-plan/references/subagent-brief.md +17 -0
- package/skills/dsh-vscodemode-html-plan/references/upstream-SKILL.md +174 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.css +564 -0
- package/skills/dsh-vscodemode-html-plan/runtime/htmlplan.js +1299 -0
- package/skills/dsh-vscodemode-html-plan/runtime/pack.mjs +300 -0
- package/src/ai/llmTask.ts +178 -0
- package/src/ai/llmTypes.ts +6 -0
- package/src/ai/svnCommitMsg.ts +107 -0
- package/src/ai/svnTriage.ts +34 -85
- package/src/client/aiCommit.ts +57 -0
- package/src/client/compatSummary.ts +15 -0
- package/src/client/editorFlush.ts +55 -0
- package/src/client/featurePrefs.ts +63 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +261 -0
- package/src/client/htmlPlan/planActions.ts +347 -0
- package/src/client/htmlPlan/planPage.ts +333 -0
- package/src/client/htmlPreview.ts +218 -0
- package/src/client/index.ts +43 -0
- package/src/client/monaco/loader.ts +71 -9
- package/src/client/monaco/templateLanguages.ts +300 -0
- package/src/client/officialSidebar.ts +16 -4
- package/src/client/openPathRouter.ts +7 -0
- package/src/client/planState.ts +8 -2
- package/src/client/refCopy.ts +70 -0
- package/src/client/refIntake.ts +215 -0
- package/src/client/sidebar/menuItems.ts +11 -0
- package/src/client/sidebar/panels/FileExplorer.ts +11 -0
- package/src/client/sidebar/panels/SearchPanel.ts +214 -4
- package/src/client/sidebar/panels/SvnPanel.ts +17 -0
- package/src/client/sidebar/types.ts +2 -0
- package/src/client/styles/editor.css +112 -0
- package/src/client/svnActions.ts +7 -0
- package/src/client/svnCommit.ts +109 -0
- package/src/client/svnNotice.ts +1 -1
- package/src/client/svnStatus.ts +5 -2
- package/src/client/ui/DiffLauncher.ts +3 -1
- package/src/client/ui/EditorView.ts +221 -14
- package/src/client/ui/McpSettings.ts +108 -1
- package/src/client/ui/SvnAiPlanDialog.ts +24 -4
- package/src/client/ui/SvnCommitDialog.ts +458 -0
- package/src/client/ui/commandCatalog.ts +11 -0
- package/src/client/ui/svnCommitModel.ts +204 -0
- package/src/client/univer/UniverCacheSettings.ts +75 -0
- package/src/client/univer/UniverHost.ts +177 -0
- package/src/client/univer/api.ts +30 -0
- package/src/client/univer/routing.ts +32 -0
- package/src/client/univer/store.ts +111 -0
- package/src/fileOpenSettings.ts +118 -6
- package/src/htmlPlanCommand.ts +176 -0
- package/src/index.ts +4 -0
- package/src/paths.ts +5 -0
- package/src/refPointer.ts +193 -0
- package/src/rpc.ts +51 -0
- package/src/search/replacePlan.ts +144 -0
- package/src/search/replaceRun.ts +289 -0
- package/src/shared/keybindings.ts +11 -0
- package/src/shared/refSyntax.ts +106 -0
- package/src/shared/rpc.ts +28 -4
- package/src/shared/snippets.ts +17 -0
- package/src/shared/svn.ts +191 -10
- package/src/shared/svnActions.ts +16 -0
- package/src/shared/univer.ts +90 -0
- package/src/svn.ts +205 -47
- package/src/svnCommit.ts +348 -0
- package/src/svnCore.ts +254 -0
- package/src/svnToolJson.ts +73 -0
- package/src/svnTools.ts +566 -0
- package/src/univerBridge.ts +83 -0
- package/src/univerCache.ts +205 -0
- package/src/univerRpc.ts +144 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* dsh-vscode-mode client — 引用接入:把「拖文件 / 粘贴文件 / 粘贴 @路径」变成对话引用 chip。
|
|
4
|
+
*
|
|
5
|
+
* 设计要点:
|
|
6
|
+
* 1. **同步判定、异步解析**:浏览器的 preventDefault 必须在事件回调里同步调用,而路径解析
|
|
7
|
+
* 要走 host(`edrv.resolveRef`)。因此回调里只用 payload 形态做同步判断(是否带自定义
|
|
8
|
+
* MIME、是否以 `@` 开头的引用文本、是否带了非图片文件),确认要接管后立即 preventDefault,
|
|
9
|
+
* 再去异步解析并插入;解析失败时回退成纯文本,绝不吞掉用户的粘贴内容。
|
|
10
|
+
* 2. **只在 composer 内生效**:以官方 `[data-composer-seat]` 为锚点,普通输入框/终端/其他
|
|
11
|
+
* 插件里的拖拽与粘贴完全不受影响。
|
|
12
|
+
* 3. **插入走既有通道**:统一用 addToConversation.appendReference(保 chip、忙态自动降级),
|
|
13
|
+
* 不自己拼草稿文本,避免销毁用户已插入的引用。
|
|
14
|
+
* 4. **多实例只让最后一个生效**:编辑器可能在侧栏/浮窗多处挂载,用 owner 栈保证一次粘贴
|
|
15
|
+
* 只插入一份引用。
|
|
16
|
+
*
|
|
17
|
+
* @author ddj 2026年11月15号
|
|
18
|
+
*/
|
|
19
|
+
import { parseRef } from '../shared/refSyntax.js'
|
|
20
|
+
import { featurePrefs } from './featurePrefs.js'
|
|
21
|
+
|
|
22
|
+
/** 官方 composer 座位选择器(DSH 会话输入区锚点)。 */
|
|
23
|
+
export const COMPOSER_SEAT = '[data-composer-seat]'
|
|
24
|
+
/** 资源管理器拖拽携带的内部 MIME(JSON:{ path, range? })。 */
|
|
25
|
+
export const DRAG_MIME = 'text/x-edrv-path'
|
|
26
|
+
/** 单次最多插入的引用数(防止整目录拖拽刷屏)。 */
|
|
27
|
+
export const MAX_INSERT_REFS = 5
|
|
28
|
+
|
|
29
|
+
/** 接入依赖(由 EditorView 提供,避免本模块直接依赖 ctx)。 */
|
|
30
|
+
export interface RefIntakeDeps {
|
|
31
|
+
/** 当前会话 id(无会话时返回 undefined)。 */
|
|
32
|
+
sessionId: () => string | undefined
|
|
33
|
+
/** 当前活动文件(多义时的同目录优先)。 */
|
|
34
|
+
activePath: () => string | null
|
|
35
|
+
/** 插入引用 chip。 */
|
|
36
|
+
appendReference: (sessionId: string | undefined, path: string, range?: unknown) => Promise<string>
|
|
37
|
+
/** 插入纯文本(解析失败时的回退,保住用户粘贴内容)。 */
|
|
38
|
+
appendText: (sessionId: string | undefined, text: string) => Promise<string>
|
|
39
|
+
/** 解析路径片段(host edrv.resolveRef)。 */
|
|
40
|
+
resolve: (ref: string, activePath?: string | null) => Promise<{ ok: boolean; path?: string; ambiguous?: string[]; error?: string }>
|
|
41
|
+
/** 轻提示(失败/多义时用,不用于成功)。 */
|
|
42
|
+
notify: (text: string) => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 生效中的接入实例栈(最后挂载者优先)。 */
|
|
46
|
+
const owners = []
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 事件目标是否位于 composer 座位内。
|
|
50
|
+
* @author ddj 2026年11月15号
|
|
51
|
+
* @param target 事件目标
|
|
52
|
+
* @returns 是否命中 composer
|
|
53
|
+
*/
|
|
54
|
+
export function insideComposer(target) {
|
|
55
|
+
const element = target instanceof Element ? target : target?.parentElement
|
|
56
|
+
if (!element) return false
|
|
57
|
+
try {
|
|
58
|
+
return element.closest(COMPOSER_SEAT) !== null
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 从拖拽载荷里取内部引用项(自定义 MIME 优先)。
|
|
66
|
+
* @author ddj 2026年11月15号
|
|
67
|
+
* @param dataTransfer 拖拽数据
|
|
68
|
+
* @returns 解析出的引用项(path 必填,range 可空)
|
|
69
|
+
*/
|
|
70
|
+
export function dragRefItems(dataTransfer) {
|
|
71
|
+
const items = []
|
|
72
|
+
try {
|
|
73
|
+
const raw = dataTransfer?.getData?.(DRAG_MIME) ?? ''
|
|
74
|
+
if (raw) {
|
|
75
|
+
const parsed = JSON.parse(raw)
|
|
76
|
+
const path = String(parsed?.path ?? '').trim()
|
|
77
|
+
if (path) items.push({ path, range: parsed?.range ?? undefined })
|
|
78
|
+
}
|
|
79
|
+
} catch (error) { /* 非法 JSON 当作没有 */ }
|
|
80
|
+
const files = dataTransfer?.files
|
|
81
|
+
if (files && files.length > 0) {
|
|
82
|
+
for (const file of Array.from(files)) {
|
|
83
|
+
const name = String(file?.name ?? '').trim()
|
|
84
|
+
if (name) items.push({ path: name, range: undefined })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return items.slice(0, MAX_INSERT_REFS)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 拖拽载荷是否值得接管(同步判定,供 dragover/drop 提前 preventDefault)。
|
|
92
|
+
* @author ddj 2026年11月15号
|
|
93
|
+
* @param dataTransfer 拖拽数据
|
|
94
|
+
* @returns 是否接管
|
|
95
|
+
*/
|
|
96
|
+
export function isRefDrop(dataTransfer) {
|
|
97
|
+
try {
|
|
98
|
+
const types = Array.from(dataTransfer?.types ?? [])
|
|
99
|
+
return types.includes(DRAG_MIME) || types.includes('Files')
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 粘贴内容是否应转成引用(同步判定)。
|
|
107
|
+
* @author ddj 2026年11月15号
|
|
108
|
+
* @param clipboard 剪贴板数据
|
|
109
|
+
* @returns 'ref'(@路径文本)| 'file'(非图片文件)| null(放行原生粘贴)
|
|
110
|
+
*/
|
|
111
|
+
export function pasteIntent(clipboard) {
|
|
112
|
+
if (!clipboard) return null
|
|
113
|
+
const text = String(clipboard.getData?.('text/plain') ?? '').trim()
|
|
114
|
+
if (text.startsWith('@')) return 'ref'
|
|
115
|
+
const files = clipboard.files
|
|
116
|
+
if (files && files.length > 0) {
|
|
117
|
+
const nonImage = Array.from(files).filter((file) => !String(file?.type ?? '').startsWith('image/'))
|
|
118
|
+
if (nonImage.length > 0) return 'file'
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 插入一组引用;返回实际插入数量(0 表示全部失败)。
|
|
125
|
+
* @author ddj 2026年11月15号
|
|
126
|
+
* @param deps 接入依赖
|
|
127
|
+
* @param items 引用项(path 可为绝/相对/裸文件名,range 可空)
|
|
128
|
+
* @param fallbackText 失败时回填的纯文本(paste 场景用;drop 场景传空串)
|
|
129
|
+
* @returns 插入数量
|
|
130
|
+
* @sideEffects 写会话草稿
|
|
131
|
+
*/
|
|
132
|
+
async function insertItems(deps, items, fallbackText) {
|
|
133
|
+
const sessionId = deps.sessionId()
|
|
134
|
+
const activePath = deps.activePath()
|
|
135
|
+
let inserted = 0
|
|
136
|
+
let ambiguous = false
|
|
137
|
+
for (const item of items) {
|
|
138
|
+
const resolved = await deps.resolve(item.path, activePath)
|
|
139
|
+
if (!resolved || resolved.ok !== true || !resolved.path) continue
|
|
140
|
+
if (Array.isArray(resolved.ambiguous) && resolved.ambiguous.length > 0) {
|
|
141
|
+
ambiguous = true
|
|
142
|
+
deps.notify('同名文件较多,未能确定引用:' + item.path)
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
const outcome = await deps.appendReference(sessionId, resolved.path, item.range)
|
|
146
|
+
if (outcome === 'ok' || outcome === 'busy') inserted += 1
|
|
147
|
+
}
|
|
148
|
+
if (inserted === 0 && fallbackText) await deps.appendText(sessionId, fallbackText)
|
|
149
|
+
if (inserted === 0 && items.length > 0 && !fallbackText && !ambiguous) deps.notify('未能在工作区内找到对应文件')
|
|
150
|
+
return inserted
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 挂载引用接入(返回解绑函数)。
|
|
155
|
+
* @author ddj 2026年11月15号
|
|
156
|
+
* @param deps 接入依赖
|
|
157
|
+
* @returns 解绑函数(移除全部监听并退出 owner 栈)
|
|
158
|
+
*/
|
|
159
|
+
export function attachRefIntake(deps) {
|
|
160
|
+
const owner = { deps }
|
|
161
|
+
owners.push(owner)
|
|
162
|
+
const active = () => owners[owners.length - 1]
|
|
163
|
+
|
|
164
|
+
/** @private @author ddj 2026年11月15号 @param event 拖拽事件 @returns void */
|
|
165
|
+
const onDragOver = (event) => {
|
|
166
|
+
if (!featurePrefs().refIntake) return
|
|
167
|
+
if (!insideComposer(event.target)) return
|
|
168
|
+
if (!isRefDrop(event.dataTransfer)) return
|
|
169
|
+
event.preventDefault()
|
|
170
|
+
try { event.dataTransfer.dropEffect = 'copy' } catch (error) { /* 只读实现忽略 */ }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** @private @author ddj 2026年11月15号 @param event 放置事件 @returns void */
|
|
174
|
+
const onDrop = (event) => {
|
|
175
|
+
if (!featurePrefs().refIntake) return
|
|
176
|
+
if (!insideComposer(event.target)) return
|
|
177
|
+
if (!isRefDrop(event.dataTransfer)) return
|
|
178
|
+
const items = dragRefItems(event.dataTransfer)
|
|
179
|
+
// 同步拦截:否则浏览器会把拖入的文件当导航打开
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
event.stopPropagation()
|
|
182
|
+
if (!items.length) return
|
|
183
|
+
void insertItems(active().deps, items, '')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @private @author ddj 2026年11月15号 @param event 粘贴事件 @returns void */
|
|
187
|
+
const onPaste = (event) => {
|
|
188
|
+
if (!featurePrefs().refIntake) return
|
|
189
|
+
if (!insideComposer(event.target)) return
|
|
190
|
+
const intent = pasteIntent(event.clipboardData)
|
|
191
|
+
if (intent === null) return
|
|
192
|
+
const text = String(event.clipboardData?.getData?.('text/plain') ?? '')
|
|
193
|
+
const parsed = intent === 'ref' ? parseRef(text) : null
|
|
194
|
+
const files = event.clipboardData?.files
|
|
195
|
+
const items = parsed
|
|
196
|
+
? [{ path: parsed.path, range: parsed.range }]
|
|
197
|
+
: Array.from(files ?? []).map((file) => ({ path: String(file?.name ?? ''), range: undefined })).filter((item) => item.path)
|
|
198
|
+
if (!items.length) return
|
|
199
|
+
// 同步拦截后异步插入;解析失败回退纯文本,内容不丢
|
|
200
|
+
event.preventDefault()
|
|
201
|
+
event.stopPropagation()
|
|
202
|
+
void insertItems(active().deps, items.slice(0, MAX_INSERT_REFS), intent === 'ref' ? text : '')
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
document.addEventListener('dragover', onDragOver, true)
|
|
206
|
+
document.addEventListener('drop', onDrop, true)
|
|
207
|
+
document.addEventListener('paste', onPaste, true)
|
|
208
|
+
return () => {
|
|
209
|
+
document.removeEventListener('dragover', onDragOver, true)
|
|
210
|
+
document.removeEventListener('drop', onDrop, true)
|
|
211
|
+
document.removeEventListener('paste', onPaste, true)
|
|
212
|
+
const index = owners.indexOf(owner)
|
|
213
|
+
if (index >= 0) owners.splice(index, 1)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* 作者 ddj 2026-08-27 / 2026-09-03 / 2026-09-16 / 2026年09月22号
|
|
11
11
|
*/
|
|
12
12
|
import { isSvnDiffable } from '../../shared/svn.js'
|
|
13
|
+
import { canImportOffice } from '../../shared/univer.js'
|
|
14
|
+
import { univerCapability } from '../univer/store.js'
|
|
13
15
|
import type { SvnChangeEntry } from '../../shared/svn.js'
|
|
14
16
|
import { svnActionOn, svnActionsFor } from '../../shared/svnActions.js'
|
|
15
17
|
import type { SvnActionContext, SvnTargetType } from '../../shared/svnActions.js'
|
|
@@ -271,6 +273,14 @@ async function pasteInto(target: TreeMenuTarget, ctx: SidebarCtx): Promise<void>
|
|
|
271
273
|
*/
|
|
272
274
|
function openGroupItems(): TreeMenuItem[] {
|
|
273
275
|
return [
|
|
276
|
+
{
|
|
277
|
+
id: 'univer-import',
|
|
278
|
+
label: '使用 Univer 编辑副本',
|
|
279
|
+
order: ORDER_OPEN - 1,
|
|
280
|
+
group: GROUP_OPEN,
|
|
281
|
+
visible: (target, ctx) => isFileTarget(target) && canImportOffice(target.path) && univerCapability(ctx.sessionId ?? '')?.available === true,
|
|
282
|
+
run: (target, ctx) => { window.dispatchEvent(new CustomEvent('edrv:open-editor', { detail: { path: target.path, univer: true, sessionId: ctx.sessionId } })) },
|
|
283
|
+
},
|
|
274
284
|
{
|
|
275
285
|
id: 'open-with',
|
|
276
286
|
label: '打开方式…',
|
|
@@ -533,6 +543,7 @@ function treeRunCtx(target: TreeMenuTarget, ctx: SidebarCtx): SvnActionRunCtx {
|
|
|
533
543
|
openSvnDiff: (p) => ctx.openSvnDiff?.(p),
|
|
534
544
|
openSvnUpdate: (p) => ctx.openSvnUpdate?.(p),
|
|
535
545
|
openSvnLog: ctx.openSvnLog,
|
|
546
|
+
openCommitDialog: (seed) => ctx.openSvnCommit?.(seed),
|
|
536
547
|
refreshChanges: ctx.refreshSvnChanges,
|
|
537
548
|
// 确认对话框可注入(测试/宿主可替换;缺省走 window.confirm)
|
|
538
549
|
confirm: ctx.confirm,
|
|
@@ -20,6 +20,7 @@ import { explorerLoad, explorerSave } from '../../state/explorerCache.js'
|
|
|
20
20
|
import { entriesCacheGet, entriesCacheIsFresh, entriesCachePut } from '../../state/explorerEntriesCache.js'
|
|
21
21
|
import { workspaceScopeOf } from '../../state/scopeStore.js'
|
|
22
22
|
import { ancestorDirsOf } from '../../tabActions.js'
|
|
23
|
+
import { DRAG_MIME } from '../../refIntake.js'
|
|
23
24
|
import { refreshSvnChanges, refreshSvnStatus } from '../../svnStatus.js'
|
|
24
25
|
import { Button } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
25
26
|
import { emitRefresh } from '../../events.js'
|
|
@@ -90,11 +91,21 @@ function rowView(props) {
|
|
|
90
91
|
const rect = event.currentTarget.getBoundingClientRect()
|
|
91
92
|
onContext(path, type, { preventDefault: () => event.preventDefault(), stopPropagation: () => event.stopPropagation(), clientX: rect.left, clientY: rect.bottom })
|
|
92
93
|
}
|
|
94
|
+
/** @private @author ddj 2026年11月15号 @param event Drag start. @description 拖拽携带内部路径 MIME,交给对话输入框落成引用 */
|
|
95
|
+
function drag(event) {
|
|
96
|
+
if (isDir) return
|
|
97
|
+
try {
|
|
98
|
+
event.dataTransfer.setData(DRAG_MIME, JSON.stringify({ path }))
|
|
99
|
+
event.dataTransfer.setData('text/plain', path)
|
|
100
|
+
event.dataTransfer.effectAllowed = 'copy'
|
|
101
|
+
} catch (error) { /* 拖拽能力不可用时按普通拖拽处理 */ }
|
|
102
|
+
}
|
|
93
103
|
return React.createElement('div', {
|
|
94
104
|
className: 'edrv-tree-row' + (active ? ' edrv-tree-active' : '') + (context ? ' edrv-tree-context' : '')
|
|
95
105
|
+ (reveal ? ' edrv-tree-reveal' : '') + (mark?.stale ? ' edrv-tree-stale' : ''),
|
|
96
106
|
title: path + (mark?.stale ? ';SVN 状态陈旧,等待确认' : ''), 'data-edrv-path': path,
|
|
97
107
|
style: { paddingLeft: 6 + depth * 14 }, tabIndex: 0, onClick: select, onContextMenu: menu, onKeyDown: menuKey,
|
|
108
|
+
draggable: !isDir, onDragStart: drag,
|
|
98
109
|
},
|
|
99
110
|
React.createElement('span', { className: 'edrv-tree-chev' }, isDir ? (isOpen ? '▾' : '▸') : ''),
|
|
100
111
|
React.createElement('span', { className: 'edrv-tree-iconbox' }, rowIconEl({ name }, isDir, isOpen), svnOverlayEl(viewOverlayOf(mark), remote)),
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* 点击经 ctx.openFileAt 打开文件并跳转行列。
|
|
6
6
|
* 选项:大小写/全词/正则;折叠区(⚙ 齿轮展开):包含的文件(📖 toggle = 仅当前打开文件)
|
|
7
7
|
* 与排除的文件(⚙ toggle = 启用排除),模式为逗号分隔 rg glob;无搜索按钮,防抖 + 回车触发。
|
|
8
|
-
*
|
|
8
|
+
* 替换(v0.30.0):搜索框右侧 chevron 展开替换行,先 dryRun 预览命中数再确认写盘;
|
|
9
|
+
* 执行前经 edrv:flush-all 让所有编辑器落盘,执行后派发 edrv:refresh 让面板与页签看到新内容。
|
|
10
|
+
* 作者 ddj 2026-08-26 / 2026-11-15
|
|
9
11
|
*/
|
|
10
12
|
import React from 'react'
|
|
11
13
|
import { rpc } from '../../rpc.js'
|
|
@@ -13,6 +15,10 @@ import type { SidebarCtx } from '../types.js'
|
|
|
13
15
|
import { CACHE_KEY } from '../../paths.js'
|
|
14
16
|
import { workspaceScopeOf } from '../../state/scopeStore.js'
|
|
15
17
|
import { takeSearchSeed, takeSearchScope } from '../../searchSeed.js'
|
|
18
|
+
import { ModalShell } from '../../ui/ModalShell.js'
|
|
19
|
+
import { flushEditors } from '../../editorFlush.js'
|
|
20
|
+
import { emitRefresh } from '../../events.js'
|
|
21
|
+
import { featurePrefs, watchFeaturePrefs } from '../../featurePrefs.js'
|
|
16
22
|
|
|
17
23
|
const DEBOUNCE_MS = 250
|
|
18
24
|
/** 文件变更后的重搜去抖:合并一次写盘的 refresh+file-changed 双事件与批量保存。 */
|
|
@@ -95,6 +101,25 @@ function splitHit(text, start, end) {
|
|
|
95
101
|
return { before: String(text).slice(0, s), hit: String(text).slice(s, e), after: String(text).slice(e) }
|
|
96
102
|
}
|
|
97
103
|
|
|
104
|
+
/**
|
|
105
|
+
* 替换结果的用户可读摘要(纯函数,可单测)。
|
|
106
|
+
* @author ddj 2026年11月15号
|
|
107
|
+
* @param result edrv.replaceContent 响应
|
|
108
|
+
* @returns 一句话摘要
|
|
109
|
+
*/
|
|
110
|
+
export function replaceSummary(result) {
|
|
111
|
+
if (!result) return ''
|
|
112
|
+
const total = Number(result.totalReplaced ?? 0)
|
|
113
|
+
const files = Number(result.totalFiles ?? 0)
|
|
114
|
+
const parts = [(result.dryRun === true ? '预览:' : '已替换 ') + total + ' 处 · ' + files + ' 个文件']
|
|
115
|
+
if (result.truncated === true) parts.push('超出单次上限已截断')
|
|
116
|
+
if (Number(result.skipped ?? 0) > 0) parts.push('跳过 ' + result.skipped + ' 个文件')
|
|
117
|
+
const failed = Array.isArray(result.failed) ? result.failed : []
|
|
118
|
+
if (failed.length > 0) parts.push('失败 ' + failed.length + ' 个(' + String(failed[0]?.reason ?? '') + ')')
|
|
119
|
+
if (result.warning) parts.push(String(result.warning))
|
|
120
|
+
return parts.join(' · ')
|
|
121
|
+
}
|
|
122
|
+
|
|
98
123
|
/**
|
|
99
124
|
* 搜索面板主体。
|
|
100
125
|
* @param props.ctx 面板共享上下文(sessionId/openFileAt/activePath)
|
|
@@ -121,6 +146,17 @@ export function SearchPanel(props) {
|
|
|
121
146
|
const [matches, setMatches] = React.useState(null)
|
|
122
147
|
const [truncated, setTruncated] = React.useState(false)
|
|
123
148
|
const [collapsed, setCollapsed] = React.useState({})
|
|
149
|
+
// 替换行状态:replaceOpen 由 chevron 控制;replaceText 按作用域记忆
|
|
150
|
+
const [replaceOpen, setReplaceOpen] = React.useState(false)
|
|
151
|
+
const [replaceText, setReplaceText] = React.useState('')
|
|
152
|
+
const [replaceBusy, setReplaceBusy] = React.useState(false)
|
|
153
|
+
const [replaceNotice, setReplaceNotice] = React.useState('')
|
|
154
|
+
const [replaceError, setReplaceError] = React.useState('')
|
|
155
|
+
/** 待确认的替换动作:{ scope:'all'|'file', path?, preview } */
|
|
156
|
+
const [replaceConfirm, setReplaceConfirm] = React.useState(null)
|
|
157
|
+
const [replaceEnabled, setReplaceEnabled] = React.useState(() => featurePrefs().searchReplace)
|
|
158
|
+
const replaceTextRef = React.useRef('')
|
|
159
|
+
replaceTextRef.current = replaceText
|
|
124
160
|
const seqRef = React.useRef(0)
|
|
125
161
|
const timerRef = React.useRef(null)
|
|
126
162
|
const inputRef = React.useRef(null)
|
|
@@ -153,6 +189,8 @@ export function SearchPanel(props) {
|
|
|
153
189
|
if (typeof saved.onlyActive === 'boolean') setOnlyActive(saved.onlyActive)
|
|
154
190
|
if (typeof saved.excludeOn === 'boolean') setExcludeOn(saved.excludeOn)
|
|
155
191
|
if (typeof saved.sectionOpen === 'boolean') setSectionOpen(saved.sectionOpen)
|
|
192
|
+
if (typeof saved.replaceText === 'string') setReplaceText(saved.replaceText)
|
|
193
|
+
if (typeof saved.replaceOpen === 'boolean') setReplaceOpen(saved.replaceOpen)
|
|
156
194
|
// 显式把恢复后的选项同步进 requestRef:render 期的同步要等下一次渲染才生效,
|
|
157
195
|
// 而紧随其后的「选区种子」effect 会在本次 commit 内立即搜索,读到的会是陈旧选项。
|
|
158
196
|
requestRef.current = {
|
|
@@ -174,9 +212,16 @@ export function SearchPanel(props) {
|
|
|
174
212
|
try {
|
|
175
213
|
localStorage.setItem(CACHE_KEY.search + String(scope), JSON.stringify({
|
|
176
214
|
query, matchCase, wholeWord, regex, includeText, excludeText, onlyActive, excludeOn, sectionOpen,
|
|
215
|
+
replaceText, replaceOpen,
|
|
177
216
|
}))
|
|
178
217
|
} catch (e) { /* 忽略 */ }
|
|
179
|
-
}, [scope, query, matchCase, wholeWord, regex, includeText, excludeText, onlyActive, excludeOn, sectionOpen])
|
|
218
|
+
}, [scope, query, matchCase, wholeWord, regex, includeText, excludeText, onlyActive, excludeOn, sectionOpen, replaceText, replaceOpen])
|
|
219
|
+
|
|
220
|
+
// 替换能力开关(设置 → 通用):关闭时收起替换行,已展开的确认弹窗一并撤销
|
|
221
|
+
React.useEffect(() => watchFeaturePrefs((prefs) => {
|
|
222
|
+
setReplaceEnabled(prefs.searchReplace)
|
|
223
|
+
if (!prefs.searchReplace) { setReplaceOpen(false); setReplaceConfirm(null) }
|
|
224
|
+
}), [])
|
|
180
225
|
|
|
181
226
|
/**
|
|
182
227
|
* 执行内容搜索(请求参数从 ref 读最新值)。
|
|
@@ -277,6 +322,105 @@ export function SearchPanel(props) {
|
|
|
277
322
|
})
|
|
278
323
|
}
|
|
279
324
|
|
|
325
|
+
/**
|
|
326
|
+
* 替换请求的公共字段(与内容搜索严格同口径:选项 + 包含/排除 + 查询词)。
|
|
327
|
+
* @author ddj 2026年11月15号
|
|
328
|
+
* @returns 不含 replacement/paths/dryRun 的请求字段
|
|
329
|
+
*/
|
|
330
|
+
const replaceBaseOf = () => {
|
|
331
|
+
const req = requestRef.current
|
|
332
|
+
return {
|
|
333
|
+
sessionId,
|
|
334
|
+
query: String(queryRef.current ?? '').trim(),
|
|
335
|
+
matchCase: req.matchCase === true,
|
|
336
|
+
wholeWord: req.wholeWord === true,
|
|
337
|
+
regex: req.regex === true,
|
|
338
|
+
include: req.include ?? [],
|
|
339
|
+
exclude: req.exclude ?? [],
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 调替换 RPC(失败转异常,成功返回响应)。
|
|
345
|
+
* @author ddj 2026年11月15号
|
|
346
|
+
* @param options.paths 只处理这些文件(单文件替换);缺省 = 全部候选
|
|
347
|
+
* @param options.dryRun 只统计不写盘
|
|
348
|
+
* @returns RPC 响应
|
|
349
|
+
*/
|
|
350
|
+
const callReplace = async ({ paths, dryRun }) => {
|
|
351
|
+
const base = replaceBaseOf()
|
|
352
|
+
if (base.query.length < 2) throw new Error('请先输入至少 2 个字符的查找内容')
|
|
353
|
+
const body = Object.assign({}, base, { replacement: replaceTextRef.current })
|
|
354
|
+
if (dryRun === true) body.dryRun = true
|
|
355
|
+
if (Array.isArray(paths) && paths.length > 0) body.paths = paths
|
|
356
|
+
const res = await rpc('edrv.replaceContent', body)
|
|
357
|
+
if (!res || res.ok !== true) throw new Error(res?.error ? String(res.error) : '替换失败')
|
|
358
|
+
return res
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 先预览命中数,再打开确认弹窗(破坏性写盘不在预览阶段发生)。
|
|
363
|
+
* @author ddj 2026年11月15号
|
|
364
|
+
* @param targetScope 'all' 全部候选 | 'file' 单个文件
|
|
365
|
+
* @param path targetScope='file' 时的相对路径
|
|
366
|
+
* @returns 无(状态经 setState 反映)
|
|
367
|
+
* @sideEffects 只读(dryRun)
|
|
368
|
+
*/
|
|
369
|
+
const previewReplace = async (targetScope, path) => {
|
|
370
|
+
if (replaceBusy || !replaceEnabled) return
|
|
371
|
+
setReplaceBusy(true)
|
|
372
|
+
setReplaceError('')
|
|
373
|
+
setReplaceNotice('')
|
|
374
|
+
try {
|
|
375
|
+
const preview = await callReplace({ paths: targetScope === 'file' ? [path] : undefined, dryRun: true })
|
|
376
|
+
if (Number(preview.totalReplaced ?? 0) === 0) {
|
|
377
|
+
setReplaceNotice('没有可替换的命中')
|
|
378
|
+
return
|
|
379
|
+
}
|
|
380
|
+
setReplaceConfirm({ scope: targetScope, path, preview })
|
|
381
|
+
} catch (error) {
|
|
382
|
+
setReplaceError(error instanceof Error ? error.message : String(error))
|
|
383
|
+
} finally {
|
|
384
|
+
setReplaceBusy(false)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* 确认后执行替换:先让所有编辑器落盘(否则旧缓冲会被写回覆盖用户改动),再写盘并广播刷新。
|
|
390
|
+
* @author ddj 2026年11月15号
|
|
391
|
+
* @returns 无(状态经 setState 反映)
|
|
392
|
+
* @sideEffects 写盘 + edrv:refresh 事件
|
|
393
|
+
*/
|
|
394
|
+
const applyReplace = async () => {
|
|
395
|
+
const target = replaceConfirm
|
|
396
|
+
if (!target) return
|
|
397
|
+
setReplaceConfirm(null)
|
|
398
|
+
setReplaceBusy(true)
|
|
399
|
+
setReplaceError('')
|
|
400
|
+
setReplaceNotice('')
|
|
401
|
+
try {
|
|
402
|
+
const flushed = await flushEditors()
|
|
403
|
+
if (flushed.timedOut) {
|
|
404
|
+
setReplaceError('部分页签未能在 3 秒内落盘,已中止替换;请先手动保存后重试')
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
if (Array.isArray(flushed.failures) && flushed.failures.length > 0) {
|
|
408
|
+
setReplaceError('有页签保存失败(' + flushed.failures.join('、') + '),已中止替换;请先手动保存后重试')
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
const result = await callReplace({ paths: target.scope === 'file' ? [target.path] : undefined })
|
|
412
|
+
setReplaceNotice(replaceSummary(result))
|
|
413
|
+
if (Array.isArray(result.files) && result.files.length > 0) {
|
|
414
|
+
emitRefresh({ scope, paths: result.files.map((file) => file.path), kind: 'text' })
|
|
415
|
+
}
|
|
416
|
+
rerun({})
|
|
417
|
+
} catch (error) {
|
|
418
|
+
setReplaceError(error instanceof Error ? error.message : String(error))
|
|
419
|
+
} finally {
|
|
420
|
+
setReplaceBusy(false)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
280
424
|
// 仅当前文件模式下切换/关闭活动文件,立即更新搜索范围并作废旧请求。
|
|
281
425
|
const previousPathRef = React.useRef(activePath)
|
|
282
426
|
React.useEffect(() => {
|
|
@@ -429,6 +573,54 @@ export function SearchPanel(props) {
|
|
|
429
573
|
? React.createElement('div', { className: 'edrv-search-warn', title: warning }, warning)
|
|
430
574
|
: null
|
|
431
575
|
|
|
576
|
+
const replaceErrorBanner = replaceError
|
|
577
|
+
? React.createElement('div', { className: 'edrv-search-error' }, replaceError)
|
|
578
|
+
: null
|
|
579
|
+
|
|
580
|
+
const replaceNoticeBanner = replaceNotice
|
|
581
|
+
? React.createElement('div', { className: 'edrv-search-notice' }, replaceNotice)
|
|
582
|
+
: null
|
|
583
|
+
|
|
584
|
+
// 替换行:仅开关打开时渲染(VS Code 形态,chevron 在搜索框右侧)
|
|
585
|
+
const replaceRows = replaceEnabled && replaceOpen
|
|
586
|
+
? React.createElement('div', { className: 'edrv-search-replace-row' },
|
|
587
|
+
React.createElement('input', {
|
|
588
|
+
className: 'edrv-search-replace', autoComplete: 'off', spellCheck: false,
|
|
589
|
+
placeholder: '替换为',
|
|
590
|
+
value: replaceText,
|
|
591
|
+
onChange: (e) => setReplaceText(e.target.value),
|
|
592
|
+
onKeyDown: (e) => {
|
|
593
|
+
if (e.key !== 'Enter') return
|
|
594
|
+
e.preventDefault()
|
|
595
|
+
void previewReplace('all')
|
|
596
|
+
},
|
|
597
|
+
}),
|
|
598
|
+
React.createElement('button', {
|
|
599
|
+
className: 'edrv-search-replace-btn danger',
|
|
600
|
+
disabled: replaceBusy || !String(query).trim() || totalFiles === 0,
|
|
601
|
+
title: totalFiles === 0 ? '先搜索到命中再替换' : '预览后确认,把当前范围内的全部命中替换为上方文本',
|
|
602
|
+
onClick: () => void previewReplace('all'),
|
|
603
|
+
}, replaceBusy ? '处理中…' : '全部替换'))
|
|
604
|
+
: null
|
|
605
|
+
|
|
606
|
+
const confirmDialog = replaceConfirm
|
|
607
|
+
? React.createElement(ModalShell, { onClose: () => setReplaceConfirm(null) },
|
|
608
|
+
React.createElement('h3', null, replaceConfirm.scope === 'file' ? '确认替换此文件' : '确认全部替换'),
|
|
609
|
+
React.createElement('ul', { className: 'edrv-search-confirm-list' },
|
|
610
|
+
React.createElement('li', null, '命中:' + Number(replaceConfirm.preview.totalReplaced ?? 0) + ' 处 · ' + Number(replaceConfirm.preview.totalFiles ?? 0) + ' 个文件'),
|
|
611
|
+
replaceConfirm.scope === 'file'
|
|
612
|
+
? React.createElement('li', null, '范围:' + String(replaceConfirm.path ?? ''))
|
|
613
|
+
: React.createElement('li', null, '范围:当前搜索条件与包含/排除过滤'),
|
|
614
|
+
Number(replaceConfirm.preview.skipped ?? 0) > 0
|
|
615
|
+
? React.createElement('li', null, '将跳过 ' + replaceConfirm.preview.skipped + ' 个文件(过大/二进制/非普通文件)')
|
|
616
|
+
: null),
|
|
617
|
+
React.createElement('p', { className: 'edrv-search-confirm-note' },
|
|
618
|
+
'替换会直接改写磁盘,编辑器撤销无法撤回;执行前会先把已打开页签的未保存内容落盘。'),
|
|
619
|
+
React.createElement('div', { className: 'edrv-search-confirm-actions' },
|
|
620
|
+
React.createElement('button', { className: 'edrv-search-replace-btn', onClick: () => setReplaceConfirm(null), autoFocus: true }, '取消'),
|
|
621
|
+
React.createElement('button', { className: 'edrv-search-replace-btn danger', onClick: () => void applyReplace() }, '确认替换')))
|
|
622
|
+
: null
|
|
623
|
+
|
|
432
624
|
const body = (() => {
|
|
433
625
|
if (status === 'searching') return React.createElement('div', { className: 'edrv-search-empty' }, '搜索中…')
|
|
434
626
|
if (status === 'error') return React.createElement('div', { className: 'edrv-search-error' }, error)
|
|
@@ -442,6 +634,12 @@ export function SearchPanel(props) {
|
|
|
442
634
|
React.createElement('span', { className: 'edrv-search-chev' }, open ? '▾' : '▸'),
|
|
443
635
|
React.createElement('span', { className: 'edrv-search-fname' }, String(group.path).split(/[\\/]/).pop() || group.path),
|
|
444
636
|
React.createElement('span', { className: 'edrv-search-fdir' }, String(group.path).split(/[\\/]/).slice(0, -1).join('/')),
|
|
637
|
+
replaceEnabled
|
|
638
|
+
? React.createElement('button', {
|
|
639
|
+
className: 'edrv-search-file-replace', title: '替换此文件中的全部命中',
|
|
640
|
+
onClick: (event) => { event.stopPropagation(); void previewReplace('file', group.path) },
|
|
641
|
+
}, '✎')
|
|
642
|
+
: null,
|
|
445
643
|
React.createElement('span', { className: 'edrv-search-fcount' }, group.count)),
|
|
446
644
|
open ? group.matches.map((m, i) => {
|
|
447
645
|
const parts = splitHit(m.text, m.startColumn, m.endColumn)
|
|
@@ -466,10 +664,22 @@ export function SearchPanel(props) {
|
|
|
466
664
|
if (e.key === 'Enter') { if (timerRef.current) clearTimeout(timerRef.current); runSearch(queryRef.current) }
|
|
467
665
|
if (e.key === 'Escape') inputRef.current?.blur?.()
|
|
468
666
|
},
|
|
469
|
-
})
|
|
667
|
+
}),
|
|
668
|
+
replaceEnabled
|
|
669
|
+
? React.createElement('button', {
|
|
670
|
+
className: 'edrv-search-toggle' + (replaceOpen ? ' on' : ''),
|
|
671
|
+
title: replaceOpen ? '收起替换' : '显示替换',
|
|
672
|
+
'aria-pressed': replaceOpen,
|
|
673
|
+
onClick: () => setReplaceOpen((value) => !value),
|
|
674
|
+
}, '⇄')
|
|
675
|
+
: null),
|
|
676
|
+
replaceRows,
|
|
470
677
|
optsBar,
|
|
471
678
|
filterRows,
|
|
472
679
|
summary,
|
|
473
680
|
warnBanner,
|
|
474
|
-
|
|
681
|
+
replaceErrorBanner,
|
|
682
|
+
replaceNoticeBanner,
|
|
683
|
+
body,
|
|
684
|
+
confirmDialog)
|
|
475
685
|
}
|
|
@@ -445,6 +445,12 @@ function svnToolbarEl(props) {
|
|
|
445
445
|
className: 'edrv-svn-act', title: '导出当前列表为 HTML 报表(仅本地查看,不外发)',
|
|
446
446
|
onClick: handlers.onExportHtml,
|
|
447
447
|
}, '导出 HTML'),
|
|
448
|
+
React.createElement('button', {
|
|
449
|
+
className: 'edrv-svn-act edrv-svnplan-primary',
|
|
450
|
+
disabled: handlers.busy,
|
|
451
|
+
title: '打开原生提交对话框(勾选文件 → 写信息 → 提交;未版本控制默认不勾)',
|
|
452
|
+
onClick: () => handlers.commit?.(),
|
|
453
|
+
}, '提交…'),
|
|
448
454
|
((paths.unversioned.length || paths.revert.length)
|
|
449
455
|
? React.createElement('span', { className: 'edrv-svn-sep' })
|
|
450
456
|
: null),
|
|
@@ -997,6 +1003,8 @@ export function SvnPanel(props) {
|
|
|
997
1003
|
onExportHtml: () => onExport('html'),
|
|
998
1004
|
add: onAdd,
|
|
999
1005
|
revert: onRevert,
|
|
1006
|
+
// 提交入口:只打开对话框(提交范围与信息由人在对话框里确认)
|
|
1007
|
+
commit: () => ctxRef.current?.openSvnCommit?.({}),
|
|
1000
1008
|
}),
|
|
1001
1009
|
})
|
|
1002
1010
|
/** @private @author ddj 2026年10月15号 Open the shared update window independently of selection and local changes. */
|
|
@@ -1051,6 +1059,15 @@ export function SvnPanel(props) {
|
|
|
1051
1059
|
onResume: aiResume,
|
|
1052
1060
|
onCancelRest: aiCancelRest,
|
|
1053
1061
|
onClose: closeAiPlan,
|
|
1062
|
+
// 逐组提交只预填提交对话框(绝不自动提交)
|
|
1063
|
+
onCommitGroup: (group) => {
|
|
1064
|
+
closeAiPlan()
|
|
1065
|
+
const body = group.body ?? ''
|
|
1066
|
+
ctxRef.current?.openSvnCommit?.({
|
|
1067
|
+
paths: group.paths,
|
|
1068
|
+
message: body ? group.subject + '\n\n' + body : group.subject,
|
|
1069
|
+
})
|
|
1070
|
+
},
|
|
1054
1071
|
})
|
|
1055
1072
|
: null
|
|
1056
1073
|
|
|
@@ -52,6 +52,8 @@ export interface SidebarCtx {
|
|
|
52
52
|
openSvnUpdate?: (path: string) => void
|
|
53
53
|
/** 打开 SVN 日志弹窗(P3;菜单/命令栏「查看日志」)。 */
|
|
54
54
|
openSvnLog?: (path?: string) => void
|
|
55
|
+
/** 打开原生提交对话框(seed = 预选路径/预填信息)。 */
|
|
56
|
+
openSvnCommit?: (seed?: { paths?: string[]; message?: string }) => void
|
|
55
57
|
/** 确认对话框(破坏性动作守卫;缺省走 window.confirm,测试可注入)。 */
|
|
56
58
|
confirm?: (message: string) => boolean
|
|
57
59
|
/** 面板动作反馈(如右键菜单操作结果 → 编辑区路径栏状态)。 */
|