@keyou007/agent-bot 0.1.27-alpha.4 → 0.1.27-alpha.5
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/CHANGELOG.md +14 -0
- package/README.md +37 -18
- package/README.zh.md +37 -18
- package/assets/workspace-sessions.js +959 -229
- package/assets/workspace.css +241 -57
- package/assets/workspace.js +1463 -227
- package/dist/feishu/FeishuTurnPresenter.js +26 -9
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +69 -7
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LocalFileViewerServer.js +10 -7
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/PreviewSyntaxHighlight.js +1 -1
- package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +30 -7
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WorkspaceImages.js +28 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -1
- package/dist/local-files/WorkspacePage.js +5 -2
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +343 -96
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +34 -10
- package/dist/local-files/WorkspaceTimeline.js.map +1 -1
- package/dist/presentation/OutboundRouter.js +3 -1
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +3 -1
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +130 -45
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/scheduling/ScheduledTaskStore.js +6 -4
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +2 -1
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +77 -13
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +24 -13
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/utils/promptAttachments.js +4 -2
- package/dist/utils/promptAttachments.js.map +1 -1
- package/dist/utils/promptQuotes.js +47 -0
- package/dist/utils/promptQuotes.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/feishu/FeishuTurnPresenter.ts +27 -8
- package/src/local-files/GitDiffPreview.ts +72 -8
- package/src/local-files/LocalFileViewerServer.ts +10 -7
- package/src/local-files/PreviewSyntaxHighlight.ts +1 -1
- package/src/local-files/TurnPreviewPage.ts +35 -7
- package/src/local-files/WorkspaceImages.ts +25 -0
- package/src/local-files/WorkspacePage.ts +5 -2
- package/src/local-files/WorkspaceSessions.ts +318 -101
- package/src/local-files/WorkspaceTimeline.ts +41 -15
- package/src/presentation/OutboundRouter.ts +3 -0
- package/src/presentation/TurnStateReducer.ts +3 -1
- package/src/presentation/turnViewTypes.ts +1 -1
- package/src/proxy/ProxySessionController.ts +135 -44
- package/src/scheduling/ScheduledTaskStore.ts +6 -4
- package/src/scheduling/types.ts +4 -1
- package/src/state/StateStore.ts +83 -17
- package/src/state/TurnPreviewJournal.ts +27 -14
- package/src/utils/promptAttachments.ts +5 -2
- package/src/utils/promptQuotes.ts +48 -0
package/assets/workspace.js
CHANGED
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
};
|
|
27
27
|
const put = (key,value) => { try { window.localStorage?.setItem(key,JSON.stringify(value)); } catch {} };
|
|
28
28
|
const themeKey = 'agentbot-workspace-theme';
|
|
29
|
+
const previewFontKey = 'agentbot-workspace-preview-font-size';
|
|
30
|
+
const defaultPreviewFontSize = 12, minPreviewFontSize = 8, maxPreviewFontSize = 28;
|
|
31
|
+
const taskSidebarKey = 'agentbot-workspace-medium-task-sidebar';
|
|
32
|
+
const taskSidebarWidthKey = 'agentbot-workspace-medium-task-sidebar-width';
|
|
29
33
|
const treeCacheKey = 'agentbot-workspace-directory-cache-v1', treeCacheAge = 30 * 60_000;
|
|
30
34
|
const conserveData = () => {
|
|
31
35
|
const network = window.navigator?.connection;
|
|
@@ -70,8 +74,9 @@
|
|
|
70
74
|
if (value === undefined) return 0;
|
|
71
75
|
if (!Number.isFinite(value) || value < 0) throw new Error('页面状态中的位置无效。'); return value;
|
|
72
76
|
};
|
|
77
|
+
const absoluteFilePath = value => /^[\\/]|^[a-z]:/iu.test(value);
|
|
73
78
|
const relativePath = (value, empty = false) => {
|
|
74
|
-
if (typeof value !== 'string' || (!empty && !value) || value.includes('\0') ||
|
|
79
|
+
if (typeof value !== 'string' || (!empty && !value) || value.includes('\0') || absoluteFilePath(value) || value.split(/[\\/]/u).includes('..')) throw new Error('页面状态中的路径无效。'); return value;
|
|
75
80
|
};
|
|
76
81
|
const tabKinds = embedded ? ['file','diff'] : ['file','diff','new','web','terminal','directory'];
|
|
77
82
|
const localDirectoryPrefix = 'local-';
|
|
@@ -79,6 +84,17 @@
|
|
|
79
84
|
const directoryEntry = (kind, value) => kind === 'directory' && value != null ? relativePath(value) : undefined;
|
|
80
85
|
const previewSource = (kind,value) => appBase && ['file','diff'].includes(kind) && /^[a-f0-9]{32}$/u.test(value || '') ? value : undefined;
|
|
81
86
|
const previewKey = (kind,path,source) => (source ? source+':' : '')+kind+':'+path;
|
|
87
|
+
const diffModes = ['all','staged','unstaged','recorded'];
|
|
88
|
+
const diffScrollKey = tab => tab.mode === 'recorded' ? tab.patch : tab.mode;
|
|
89
|
+
const patchReference = (kind,mode,value) => {
|
|
90
|
+
if (value == null && mode !== 'recorded') return;
|
|
91
|
+
if (!appBase || embedded || kind !== 'diff' || typeof value !== 'string' || value.length > 4096) throw new Error('补丁标识无效。');
|
|
92
|
+
const ref = JSON.parse(value);
|
|
93
|
+
const id = part => typeof part === 'string' && part.length > 0 && part.length <= 200 && !/[\x00-\x1f\x7f]/u.test(part);
|
|
94
|
+
if (!Array.isArray(ref) || ref.length !== 3 || !id(ref[0]) || !id(ref[1])
|
|
95
|
+
|| typeof ref[2] !== 'string' || !/^[a-f0-9]{32}$/u.test(ref[2])) throw new Error('补丁标识无效。');
|
|
96
|
+
return JSON.stringify(ref);
|
|
97
|
+
};
|
|
82
98
|
const localAddress = value => /^(?:file:|[a-z]:[\\/]|\\\\|\/(?!\/))/iu.test(value);
|
|
83
99
|
const webAddress = value => {
|
|
84
100
|
const url = new URL(value);
|
|
@@ -115,7 +131,11 @@
|
|
|
115
131
|
const literal = suffix && !/^file:/iu.test(value) && (!windowsRoot || !/[<>:"|?*]/u.test(path+suffix)) ? path+suffix : undefined;
|
|
116
132
|
return {path,hash,literal,query:line ? path : literal || path};
|
|
117
133
|
};
|
|
118
|
-
const tabPath = (value, kind) => {
|
|
134
|
+
const tabPath = (value, kind, patch) => {
|
|
135
|
+
if (patch && typeof value === 'string' && absoluteFilePath(value)) {
|
|
136
|
+
if (value.length > 4096 || value.includes('\0')) throw new Error('补丁文件路径无效。');
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
119
139
|
if (kind === 'directory') { if (!/^(?:local-)?[a-f0-9]{32}$/u.test(value)) throw new Error('目录标识无效。'); return value; }
|
|
120
140
|
if (kind === 'web') return webAddress(value);
|
|
121
141
|
if (kind === 'new' || kind === 'terminal') { if (typeof value !== 'string' || !/^[a-f0-9]{16}$/u.test(value)) throw new Error('标签标识无效。'); return value; }
|
|
@@ -139,10 +159,12 @@
|
|
|
139
159
|
};
|
|
140
160
|
const readUrlState = (href = window.location.href, resolveId) => {
|
|
141
161
|
const url = new URL(href), params = url.searchParams;
|
|
142
|
-
const entry = params.get('entry'), kind = choice(params.get('kind'),tabKinds,'file'), mode = choice(params.get('mode'),
|
|
143
|
-
const
|
|
162
|
+
const entry = params.get('entry'), kind = choice(params.get('kind'),tabKinds,'file'), mode = choice(params.get('mode'),diffModes,'all');
|
|
163
|
+
const patch = patchReference(kind,mode,params.get('patch'));
|
|
164
|
+
const route = {pane:choice(params.get('pane'),['tasks','chat','files'],'files'),listMode:choice(params.get('list'),['files','changes'],'files'),view:choice(params.get('view'),['list','content'],entry?'content':'list'),tab:entry?{id:params.has('tab')?tabId(params.get('tab')):undefined,path:tabPath(entry,kind,patch),kind,mode,patch,original:params.has('original')?relativePath(params.get('original')):undefined}:null};
|
|
144
165
|
if (route.tab) route.tab.directoryEntry = directoryEntry(kind,params.get('directoryFile'));
|
|
145
166
|
if (route.tab) route.tab.source = previewSource(kind,params.get('sourceDir'));
|
|
167
|
+
if (route.tab?.kind === 'file' && params.get('source') === '1') route.tab.sourceView = true;
|
|
146
168
|
let extra = {v:1}; const encoded = url.hash.startsWith('#workspace=');
|
|
147
169
|
if (encoded) {
|
|
148
170
|
extra = JSON.parse(decodeURIComponent(url.hash.slice(11)));
|
|
@@ -154,10 +176,13 @@
|
|
|
154
176
|
for (const value of extra.tabs) {
|
|
155
177
|
if (!value || typeof value !== 'object') throw new Error('链接中的文件标签无效。');
|
|
156
178
|
const kind = choice(value.kind,tabKinds,'file');
|
|
157
|
-
const
|
|
179
|
+
const mode = choice(value.mode,diffModes,'all'), patch = patchReference(kind,mode,value.patch);
|
|
180
|
+
const path = tabPath(value.path,kind,patch);
|
|
158
181
|
const source = previewSource(kind,value.source);
|
|
159
|
-
const tab = {id:value.id===undefined?resolveId?.(kind,path,source) || instanceId():tabId(value.id),path,kind,source,mode
|
|
182
|
+
const tab = {id:value.id===undefined?resolveId?.(kind,path,source) || instanceId():tabId(value.id),path,kind,source,mode,patch,original:value.original===undefined?undefined:relativePath(value.original),scrollTop:offset(value.scrollTop),scrollLeft:offset(value.scrollLeft),hash:undefined,requestedHash:undefined};
|
|
160
183
|
tab.directoryEntry = directoryEntry(kind,value.directoryEntry);
|
|
184
|
+
if (value.pinned === true) tab.pinned = true;
|
|
185
|
+
if (kind === 'file' && value.sourceView === true) tab.sourceView = true;
|
|
161
186
|
for (const key of ['hash','requestedHash']) if (value[key] !== undefined) { if (typeof value[key] !== 'string' || !value[key].startsWith('#')) throw new Error('链接中的文件锚点无效。'); tab[key] = value[key]; }
|
|
162
187
|
tabs.push(tab);
|
|
163
188
|
}
|
|
@@ -165,7 +190,7 @@
|
|
|
165
190
|
if (route.tab) {
|
|
166
191
|
let active = tabs.find(tab => route.tab.id?tab.id===route.tab.id:tab.path === route.tab.path && tab.kind === route.tab.kind && tab.source === route.tab.source);
|
|
167
192
|
if (!active) { active = {...route.tab,id:route.tab.id || resolveId?.(kind,route.tab.path,route.tab.source) || instanceId(),scrollTop:0,scrollLeft:0}; tabs.push(active); }
|
|
168
|
-
Object.assign(active,route.tab,{id:active.id}); route.tab.id = active.id;
|
|
193
|
+
Object.assign(active,route.tab,{id:active.id,sourceView:route.tab.sourceView}); route.tab.id = active.id;
|
|
169
194
|
if (!encoded && url.hash) active.hash = active.requestedHash = url.hash;
|
|
170
195
|
route.tab.hash = active.hash;
|
|
171
196
|
}
|
|
@@ -181,11 +206,29 @@
|
|
|
181
206
|
}
|
|
182
207
|
const layout = {};
|
|
183
208
|
for (const key of ['sidebar','chat','explorer']) if (extra.layout?.[key] !== undefined) { const value = offset(extra.layout[key]); if (value > 4000) throw new Error('面板宽度无效。'); layout[key] = value; }
|
|
184
|
-
for (const key of ['sidebarCollapsed','filesCollapsed','explorerCollapsed']) if (extra.layout?.[key] !== undefined) { if (typeof extra.layout[key] !== 'boolean') throw new Error('面板折叠状态无效。'); layout[key] = extra.layout[key]; }
|
|
185
|
-
const recentTabs = extra.recentTabs ?? [], keys = new Map(tabs.flatMap(tab => [[tab.id,tab.id],[previewKey(tab.kind,tab.path,tab.source),tab.id]
|
|
209
|
+
for (const key of ['sidebarCollapsed','chatCollapsed','filesCollapsed','explorerCollapsed']) if (extra.layout?.[key] !== undefined) { if (typeof extra.layout[key] !== 'boolean') throw new Error('面板折叠状态无效。'); layout[key] = extra.layout[key]; }
|
|
210
|
+
const recentTabs = extra.recentTabs ?? [], keys = new Map(tabs.flatMap(tab => [[tab.id,tab.id],[previewKey(tab.kind,tab.path,tab.source),tab.id],
|
|
211
|
+
...(tab.patch ? [['recorded:'+tab.patch,tab.id]] : [])]));
|
|
186
212
|
if (new Set(tabs.map(tab => tab.id)).size !== tabs.length) throw new Error('链接中的标签标识重复。');
|
|
187
213
|
if (!Array.isArray(recentTabs) || recentTabs.some(key => typeof key !== 'string' || !keys.has(key))) throw new Error('链接中的标签浏览顺序无效。');
|
|
188
|
-
|
|
214
|
+
const diffTabs = new Map();
|
|
215
|
+
const diffKey = tab => previewKey(tab.kind,tab.path,tab.source);
|
|
216
|
+
for (const tab of tabs) {
|
|
217
|
+
if (tab.kind !== 'diff') continue;
|
|
218
|
+
const key = diffKey(tab), previous = diffTabs.get(key);
|
|
219
|
+
if (!previous || tab.id === route.tab?.id) {
|
|
220
|
+
tab.patch ??= previous?.patch;
|
|
221
|
+
tab.pinned ||= previous?.pinned;
|
|
222
|
+
diffTabs.set(key,tab);
|
|
223
|
+
} else {
|
|
224
|
+
previous.patch ??= tab.patch;
|
|
225
|
+
previous.pinned ||= tab.pinned;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (route.tab?.kind === 'diff') route.tab.patch = diffTabs.get(diffKey(route.tab))?.patch;
|
|
229
|
+
const ids = new Map(tabs.map(tab => [tab.id,tab.kind==='diff'?diffTabs.get(diffKey(tab)).id:tab.id]));
|
|
230
|
+
return {route,tabs:tabs.filter(tab => ids.get(tab.id)===tab.id),trees,treeDirectory:previewSource('file',extra.treeDirectory),scroll,layout,
|
|
231
|
+
recentTabs:[...new Set(recentTabs.map(key => ids.get(keys.get(key))))]};
|
|
189
232
|
};
|
|
190
233
|
const element = (tag, text, className) => {
|
|
191
234
|
const node = document.createElement(tag);
|
|
@@ -197,19 +240,30 @@
|
|
|
197
240
|
tasks: '<path d="m3 6 2 2 4-4M12 6h9M3 13h3M12 13h9M3 20h3M12 20h9"/>',
|
|
198
241
|
chat: '<path d="M21 11a8 8 0 0 1-8 8H8l-5 3V11a8 8 0 0 1 8-8h2a8 8 0 0 1 8 8Z"/>',
|
|
199
242
|
annotation: '<path d="M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-9l-5 4v-4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"/><path d="M9 10h6m-3-3v6"/>',
|
|
243
|
+
quote: '<path fill="currentColor" stroke="none" d="M10 6c-3.6.6-6 3.7-6 7.1V17a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-4H7.25C7.54 11.24 8.54 10.15 10 9.6V6Zm10 0c-3.6.6-6 3.7-6 7.1V17a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-4h-2.75c.29-1.76 1.29-2.85 2.75-3.4V6Z"/>',
|
|
200
244
|
folder: '<path d="M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"/>',
|
|
201
245
|
tree: '<rect x="3" y="2" width="6" height="5" rx="1"/><path d="M6 7v13h6M6 12h6"/><rect x="12" y="9" width="9" height="6" rx="1"/><rect x="12" y="17" width="9" height="6" rx="1"/>',
|
|
246
|
+
zoomIn: '<circle cx="10" cy="10" r="6"/><path d="m14.5 14.5 5 5M7 10h6m-3-3v6"/>',
|
|
247
|
+
zoomOut: '<circle cx="10" cy="10" r="6"/><path d="m14.5 14.5 5 5M7 10h6"/>',
|
|
202
248
|
file: '<path d="M14 2H5a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9Z M14 2v7h7M8 13h8M8 17h8"/>',
|
|
249
|
+
code: '<path d="m8 6-6 6 6 6m8-12 6 6-6 6m-3-14-2 16"/>',
|
|
250
|
+
preview: '<path d="M2 12s3.6-6 10-6 10 6 10 6-3.6 6-10 6-10-6-10-6Z"/><circle cx="12" cy="12" r="2.5"/>',
|
|
203
251
|
openFile: '<path d="M9 11v9a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1V9l-6-6h-2M16 3v6h6"/><path d="M3 10V6a2 2 0 0 1 2-2h7m-3-3 3 3-3 3"/>',
|
|
204
252
|
diff: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M7 8h6M10 5v6M11 16h6"/>',
|
|
253
|
+
hourglass: '<path d="M6 3h12M6 21h12M7 3v3c0 2 1 3 3 4l2 2 2-2c2-1 3-2 3-4V3M7 21v-3c0-2 1-3 3-4l2-2 2 2c2 1 3 2 3 4v3"/>',
|
|
205
254
|
refresh: '<path d="M20 7a8 8 0 1 0 1 9M20 2v5h-5"/>',
|
|
206
255
|
back: '<path d="m14 5-7 7 7 7"/>',
|
|
207
256
|
forward: '<path d="m10 5 7 7-7 7"/>',
|
|
208
257
|
up: '<path d="M12 20V4m-6 6 6-6 6 6"/>',
|
|
209
258
|
down: '<path d="M12 4v16m-6-6 6 6 6-6"/>',
|
|
210
259
|
close: '<path d="m6 6 12 12M6 18 18 6"/>',
|
|
260
|
+
pin: '<path d="M9 3h6m-1 0v5l3 4v2H7v-2l3-4V3m2 11v7"/>',
|
|
261
|
+
unpin: '<path d="m3 3 18 18M9 3h6m-1 0v5l3 4m-8-2-2 2v2h7m-2 0v7"/>',
|
|
262
|
+
moreTabs: '<path d="m7 10 5 5 5-5"/>',
|
|
211
263
|
check: '<path d="m5 12 4 4L19 6"/>',
|
|
212
264
|
download: '<path d="M12 3v12m-5-5 5 5 5-5M4 16v5h16v-5"/>',
|
|
265
|
+
copy: '<path d="M9 9h11v12H9zM15 9V4H4v12h5"/>',
|
|
266
|
+
share: '<path d="M12 15V3m-4 4 4-4 4 4M8 10H5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1h-3"/>',
|
|
213
267
|
send: '<path d="m22 2-7 20-4-9-9-4Z M22 2 11 13"/>',
|
|
214
268
|
lock: '<rect x="5" y="10" width="14" height="11" rx="2"/><path d="M8 10V6a4 4 0 0 1 8 0v4M12 14v3"/>',
|
|
215
269
|
branch: '<circle cx="6" cy="4" r="2"/><circle cx="6" cy="20" r="2"/><circle cx="18" cy="6" r="2"/><path d="M6 6v12M18 8a10 10 0 0 1-12 9"/>',
|
|
@@ -217,6 +271,10 @@
|
|
|
217
271
|
new: '<rect x="3" y="3" width="18" height="18" rx="2.5"/><path d="M3 8h18M7 5.5h.01M10 5.5h.01"/>',
|
|
218
272
|
sidebar: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/>',
|
|
219
273
|
explorer: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/>',
|
|
274
|
+
expandFiles: '<path d="M3 12h18M7 8l-4 4 4 4m10-8 4 4-4 4"/>',
|
|
275
|
+
restoreFiles: '<path d="M3 12h6m6 0h6M6 8l4 4-4 4m12-8-4 4 4 4"/>',
|
|
276
|
+
fullscreen: '<path d="M9 3H3v6m12-6h6v6M3 15v6h6m12-6v6h-6"/>',
|
|
277
|
+
exitFullscreen: '<path d="M3 9h6V3m12 6h-6V3M9 21v-6H3m12 6v-6h6"/>',
|
|
220
278
|
web: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a17 17 0 0 1 0 18 17 17 0 0 1 0-18Z"/>',
|
|
221
279
|
terminal: '<rect x="2" y="3" width="20" height="18" rx="2"/><path d="m6 8 4 4-4 4M13 16h5"/>',
|
|
222
280
|
pencil: '<path d="m14 6 4 4M4 20l4.5-1 11-11a2.8 2.8 0 0 0-4-4l-11 11Z"/>',
|
|
@@ -271,6 +329,12 @@
|
|
|
271
329
|
node.dataset.tooltip = label; node.setAttribute('aria-label',label); return node;
|
|
272
330
|
};
|
|
273
331
|
const selectionElement = node => node.nodeType === 1 ? node : node.parentElement;
|
|
332
|
+
const addressPathSelection = breadcrumbs => {
|
|
333
|
+
const selection = window.getSelection?.();
|
|
334
|
+
if (!selection?.rangeCount || selection.isCollapsed) return;
|
|
335
|
+
const range = selection.getRangeAt(0);
|
|
336
|
+
if (breadcrumbs.contains(range.commonAncestorContainer)) return range;
|
|
337
|
+
};
|
|
274
338
|
const sameRange = (a,b) => a.startContainer === b.startContainer && a.endContainer === b.endContainer
|
|
275
339
|
&& a.startOffset === b.startOffset && a.endOffset === b.endOffset;
|
|
276
340
|
const annotationAnchor = (range,root,kind) => {
|
|
@@ -297,27 +361,78 @@
|
|
|
297
361
|
}
|
|
298
362
|
};
|
|
299
363
|
const lineSpan = (first,last) => first === last ? String(first) : `${first}–${last}`;
|
|
364
|
+
const codeText = '.line-text,.diff-text';
|
|
365
|
+
const codeGutter = '.line-number,.diff-number';
|
|
366
|
+
const selectedNodeRange = (source,range) => {
|
|
367
|
+
const portion = range.cloneRange(); portion.selectNodeContents(source);
|
|
368
|
+
if (source.contains(range.startContainer)) portion.setStart(range.startContainer,range.startOffset);
|
|
369
|
+
if (source.contains(range.endContainer)) portion.setEnd(range.endContainer,range.endOffset);
|
|
370
|
+
return portion;
|
|
371
|
+
};
|
|
372
|
+
const annotationCodeRows = (preview,range) => {
|
|
373
|
+
const selected = [];
|
|
374
|
+
for (const source of preview.querySelectorAll(codeText)) {
|
|
375
|
+
if (!range.intersectsNode(source)) continue;
|
|
376
|
+
const portion = selectedNodeRange(source,range);
|
|
377
|
+
selected.push({source,range:portion,text:portion.toString()});
|
|
378
|
+
}
|
|
379
|
+
const first = selected.findIndex(row => row.text);
|
|
380
|
+
if (first < 0) return [];
|
|
381
|
+
if (range.startContainer === selected[0].source && range.endContainer === selected.at(-1).source) return selected;
|
|
382
|
+
return selected.slice(first,selected.findLastIndex(row => row.text)+1);
|
|
383
|
+
};
|
|
384
|
+
const coversCodeRows = rows => rows.every(row => row.text === row.source.textContent);
|
|
385
|
+
const annotationFocusRect = ({range,backward,codeRows},minLeft,maxRight) => {
|
|
386
|
+
const edge = (backward ? codeRows?.[0] : codeRows?.at(-1))?.range ?? range;
|
|
387
|
+
const caret = edge.cloneRange();
|
|
388
|
+
caret.collapse(backward);
|
|
389
|
+
const focus = caret.getBoundingClientRect();
|
|
390
|
+
const fragments = [...edge.getClientRects()].filter(rect => rect.width && rect.height);
|
|
391
|
+
const fragment = backward ? fragments[0] : fragments.at(-1);
|
|
392
|
+
const onLine = (rect,anchor) => rect.top < anchor.bottom && rect.bottom > anchor.top;
|
|
393
|
+
const anchor = focus.height && fragment && onLine(fragment,focus) ? focus : fragment;
|
|
394
|
+
if (!anchor) return;
|
|
395
|
+
const visible = fragments.filter(rect => rect.left < maxRight && rect.right > minLeft && onLine(rect,anchor));
|
|
396
|
+
if (visible.length) return {right:Math.max(...visible.map(rect => rect.right)),top:anchor.top,bottom:anchor.bottom};
|
|
397
|
+
};
|
|
300
398
|
const annotationPath = (directory,entry) => {
|
|
399
|
+
if (/^[\\/]|^[a-z]:[\\/]/iu.test(entry)) return entry;
|
|
301
400
|
const path = directory.replace(/[\\/]$/u,'')+'/'+entry;
|
|
302
401
|
return isWindowsRoot(directory) ? path.replaceAll('/','\\') : path;
|
|
303
402
|
};
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
403
|
+
const fileReference = (directory,path,original) => {
|
|
404
|
+
if (!path || !directory && !absoluteFilePath(path)) return;
|
|
405
|
+
return {path:annotationPath(directory,path),originalPath:original && (directory || absoluteFilePath(original)) ? annotationPath(directory,original) : undefined};
|
|
406
|
+
};
|
|
407
|
+
const previewFileLocation = (target,{path,originalPath}) => {
|
|
408
|
+
const gutter = target.closest(codeGutter), gutterLine = gutter?.textContent.trim();
|
|
409
|
+
const row = /^([LD])([1-9]\d*)$/u.exec(target.closest('pre.code .line[id]')?.id ?? '');
|
|
410
|
+
const clickedNumber = /^[1-9]\d*$/u.test(gutterLine ?? '');
|
|
411
|
+
const original = clickedNumber ? gutter.matches('.diff-number:first-child') : row?.[1] === 'D';
|
|
412
|
+
const line = clickedNumber ? gutterLine : row?.[2] ?? target.closest('.markdown-body [data-source-start]')?.dataset.sourceStart;
|
|
413
|
+
return {path:original && originalPath || path,line:/^[1-9]\d*$/u.test(line ?? '') ? line : undefined};
|
|
414
|
+
};
|
|
415
|
+
const directoryReference = (directory,entry) => {
|
|
416
|
+
const reference = fileReference(directory,entry);
|
|
417
|
+
if (reference) return {...reference,directory:true};
|
|
418
|
+
};
|
|
419
|
+
const coversMarkdownBlocks = (range,start,end) => {
|
|
420
|
+
const edge = range.cloneRange();
|
|
421
|
+
edge.selectNodeContents(start); edge.setEnd(range.startContainer,range.startOffset);
|
|
422
|
+
if (edge.toString()) return false;
|
|
423
|
+
edge.selectNodeContents(end); edge.setStart(range.endContainer,range.endOffset);
|
|
424
|
+
return !edge.toString();
|
|
425
|
+
};
|
|
426
|
+
const annotationQuote = ({range,codeRows,selectedText,directory,tab}) => {
|
|
427
|
+
let quote, line, originalLine, wholeLines;
|
|
428
|
+
if (codeRows) {
|
|
429
|
+
const rows = codeRows.map(({source}) => source.parentElement);
|
|
430
|
+
quote = codeRows.map(row => row.text).join('\n');
|
|
431
|
+
wholeLines = coversCodeRows(codeRows);
|
|
432
|
+
const current = rows.map(row => /^L(\d+)$/u.exec(row.id)?.[1]).filter(Boolean);
|
|
318
433
|
if (current.length) line = lineSpan(current[0],current.at(-1));
|
|
319
|
-
if (rows.some(
|
|
320
|
-
const original = rows.map(
|
|
434
|
+
if (rows.some(row => row.classList.contains('diff-deletion'))) {
|
|
435
|
+
const original = rows.map(row => row.querySelector('.diff-number')?.textContent).filter(Boolean);
|
|
321
436
|
originalLine = lineSpan(original[0],original.at(-1));
|
|
322
437
|
}
|
|
323
438
|
} else {
|
|
@@ -326,25 +441,46 @@
|
|
|
326
441
|
if (!start || !end) return;
|
|
327
442
|
line = lineSpan(start.dataset.sourceStart,end.dataset.sourceEnd);
|
|
328
443
|
quote = selectedText;
|
|
444
|
+
wholeLines = coversMarkdownBlocks(range,start,end);
|
|
329
445
|
}
|
|
330
446
|
if (!quote.trim() || !line && !originalLine) return;
|
|
331
447
|
return {path:annotationPath(directory,tab.path),line,originalLine,quote,
|
|
448
|
+
...(wholeLines ? {wholeLines:true} : {}),
|
|
332
449
|
...(originalLine && tab.original ? {originalPath:annotationPath(directory,tab.original)} : {})};
|
|
333
450
|
};
|
|
334
451
|
class WorkspaceAnnotations {
|
|
335
452
|
constructor(app) {
|
|
336
453
|
this.app = app;
|
|
337
454
|
this.draftAnnotations = [];
|
|
455
|
+
this.visibleAnnotations = [];
|
|
456
|
+
this.offerSize = new ResizeObserver(this.refresh);
|
|
457
|
+
const selectionActions = this.selectionActions = element('div',undefined,'workspace-selection-actions');
|
|
458
|
+
selectionActions.hidden = true; selectionActions.setAttribute('role','group'); selectionActions.setAttribute('aria-label','选区操作');
|
|
338
459
|
const button = this.button = iconControl('button','annotation','添加批注','workspace-annotation');
|
|
339
|
-
button.type = 'button';
|
|
460
|
+
button.type = 'button';
|
|
340
461
|
button.onpointerdown = event => event.preventDefault();
|
|
341
462
|
button.onclick = () => this.open();
|
|
463
|
+
const quote = iconControl('button','quote','引用该选区','workspace-add-reference');
|
|
464
|
+
quote.type = 'button'; quote.onpointerdown = event => event.preventDefault();
|
|
465
|
+
quote.onclick = () => this.addReference(this.selectionReference(this.offer),this.offer?.task);
|
|
466
|
+
selectionActions.append(button,quote);
|
|
467
|
+
const menu = this.referenceMenu = element('div',undefined,'workspace-reference-menu');
|
|
468
|
+
menu.hidden = true; menu.setAttribute('role','menu'); menu.setAttribute('aria-label','操作菜单');
|
|
469
|
+
menu.onkeydown = this.referenceMenuKeys;
|
|
470
|
+
menu.onfocusout = event => { if (!menu.contains(event.relatedTarget)) this.closeReferenceMenu(); };
|
|
471
|
+
const referenceStatus = this.referenceStatus = element('div',undefined,'workspace-reference-status');
|
|
472
|
+
referenceStatus.hidden = true; referenceStatus.setAttribute('role','status');
|
|
473
|
+
const note = this.note = element('button',undefined,'workspace-annotation-note');
|
|
474
|
+
note.type = 'button'; note.hidden = true; note.setAttribute('aria-description','点击编辑批注');
|
|
475
|
+
note.onclick = () => this.openNote();
|
|
342
476
|
const form = this.form = element('form',undefined,'workspace-annotation-editor');
|
|
343
477
|
form.hidden = true; form.setAttribute('aria-label','添加批注');
|
|
344
478
|
const input = this.input = element('textarea'); input.rows = 1; input.maxLength = 8000;
|
|
345
479
|
input.placeholder = '写批注…'; input.setAttribute('aria-label','批注内容');
|
|
346
480
|
const actions = this.actions = element('div',undefined,'workspace-annotation-actions');
|
|
347
|
-
const cancel = iconControl('button','close','取消批注'); cancel.type = 'button';
|
|
481
|
+
const cancel = this.cancelButton = iconControl('button','close','取消批注'); cancel.type = 'button';
|
|
482
|
+
cancel.onpointerdown = event => event.preventDefault();
|
|
483
|
+
cancel.onclick = () => this.remove();
|
|
348
484
|
const submit = this.submit = iconControl('button','check','添加到聊天'); submit.type = 'submit';
|
|
349
485
|
const status = this.status = element('small'); status.setAttribute('role','status');
|
|
350
486
|
const measure = this.measure = element('span',undefined,'workspace-annotation-measure'); measure.setAttribute('aria-hidden','true');
|
|
@@ -365,7 +501,7 @@
|
|
|
365
501
|
form.addEventListener('focusout',event => {
|
|
366
502
|
if (!form.contains(event.relatedTarget)) this.saveOnBlur();
|
|
367
503
|
});
|
|
368
|
-
app.append(
|
|
504
|
+
app.append(selectionActions,note,form,menu,referenceStatus);
|
|
369
505
|
this.listeners = new AbortController(); const {signal} = this.listeners;
|
|
370
506
|
document.addEventListener('selectionchange',this.selectionChanged,{signal});
|
|
371
507
|
document.addEventListener('pointerdown',this.beginSelection,{capture:true,signal});
|
|
@@ -374,7 +510,20 @@
|
|
|
374
510
|
window.addEventListener('blur',this.endSelection,{signal});
|
|
375
511
|
document.addEventListener('keydown',this.extendSelection,{signal});
|
|
376
512
|
document.addEventListener('keyup',this.finishKeyboardSelection,{signal});
|
|
513
|
+
app.addEventListener('pointermove',this.inspectOffer,{signal});
|
|
514
|
+
app.addEventListener('pointerleave',event => {
|
|
515
|
+
if (event.pointerType !== 'mouse') return;
|
|
516
|
+
this.offerPointer = undefined; this.setOfferHover(false); this.hideNote();
|
|
517
|
+
},{signal});
|
|
518
|
+
app.addEventListener('click',this.tapNote,{capture:true,signal});
|
|
519
|
+
app.addEventListener('contextmenu',this.referenceContext,{signal});
|
|
520
|
+
app.addEventListener('scroll',event => {
|
|
521
|
+
if (this.referenceTrigger && event.target.contains?.(this.referenceTrigger)) this.closeReferenceMenu();
|
|
522
|
+
},{capture:true,signal});
|
|
523
|
+
app.addEventListener('scroll',event => { if (event.target !== this.note) this.hideNote(); },{capture:true,signal});
|
|
377
524
|
app.addEventListener('scroll',this.refresh,{capture:true,signal});
|
|
525
|
+
window.addEventListener('resize',this.hideNote,{signal});
|
|
526
|
+
window.addEventListener('resize',() => this.closeReferenceMenu(),{signal});
|
|
378
527
|
window.addEventListener('resize',this.refresh,{signal});
|
|
379
528
|
window.visualViewport?.addEventListener('resize',this.refresh,{signal});
|
|
380
529
|
window.visualViewport?.addEventListener('scroll',this.refresh,{signal});
|
|
@@ -388,23 +537,30 @@
|
|
|
388
537
|
}
|
|
389
538
|
}
|
|
390
539
|
hideOffer() {
|
|
391
|
-
clearTimeout(this.offerTimer); this.
|
|
540
|
+
clearTimeout(this.offerTimer); this.offerSize.disconnect(); this.offer = undefined;
|
|
541
|
+
this.offerHovered = false; this.selectionActions.hidden = true;
|
|
392
542
|
}
|
|
393
543
|
beginSelection = event => {
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
|
|
544
|
+
if (this.referenceMenu.contains(event.target) || this.app.tooltips?.tip.contains(event.target)) return;
|
|
545
|
+
this.closeReferenceMenu();
|
|
546
|
+
if (event.button !== 0 || this.selectionActions.contains(event.target) || this.note.contains(event.target) || this.form.contains(event.target)) return;
|
|
547
|
+
clearTimeout(this.settleTimer); this.touchSettling = event.pointerType === 'touch'; this.offerPointer = undefined;
|
|
548
|
+
this.pointer = event.pointerId; this.dismissedRange = undefined; this.hideOffer(); this.hideNote();
|
|
397
549
|
};
|
|
398
550
|
endSelection = event => {
|
|
399
551
|
if (event.type !== 'blur' && this.pointer !== event.pointerId) return;
|
|
400
552
|
this.pointer = undefined;
|
|
401
553
|
if (event.type === 'blur') {
|
|
402
|
-
clearTimeout(this.settleTimer); this.keyboard = this.touchSettling = false;
|
|
554
|
+
clearTimeout(this.settleTimer); this.keyboard = this.touchSettling = false;
|
|
555
|
+
this.offerPointer = undefined;
|
|
556
|
+
this.hideOffer(); this.hideNote(); this.closeReferenceMenu(); this.saveOnBlur();
|
|
403
557
|
return;
|
|
404
558
|
}
|
|
559
|
+
if (event.pointerType === 'mouse') this.offerPointer = event;
|
|
405
560
|
this.selectionChanged();
|
|
406
561
|
};
|
|
407
562
|
extendSelection = event => {
|
|
563
|
+
if (event.key === 'Escape') this.hideNote();
|
|
408
564
|
if (!event.shiftKey || !['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Home','End','PageUp','PageDown'].includes(event.key)
|
|
409
565
|
|| event.target.closest?.('textarea,input,[contenteditable=true]')) return;
|
|
410
566
|
this.keyboard = true; this.dismissedRange = undefined; this.hideOffer();
|
|
@@ -414,7 +570,7 @@
|
|
|
414
570
|
this.keyboard = false; this.selectionChanged();
|
|
415
571
|
};
|
|
416
572
|
selectionChanged = () => {
|
|
417
|
-
if (this.entry || this.pointer !== undefined || this.keyboard) return;
|
|
573
|
+
if (this.entry || this.pointer !== undefined || this.keyboard || this.app.tooltips?.isSelecting()) return;
|
|
418
574
|
if (!this.touchSettling && !window.matchMedia?.('(pointer:coarse)').matches) { this.offerSelection(); return; }
|
|
419
575
|
this.hideOffer(); clearTimeout(this.settleTimer);
|
|
420
576
|
this.settleTimer = setTimeout(() => { this.touchSettling = false; this.offerSelection(); },210);
|
|
@@ -422,50 +578,268 @@
|
|
|
422
578
|
offerSelection() {
|
|
423
579
|
if (this.entry) return;
|
|
424
580
|
const selected = this.selection();
|
|
425
|
-
if (selected && (this.offer && sameRange(selected.range,this.offer.range)
|
|
581
|
+
if (selected && (this.offer && selected.backward === this.offer.backward && sameRange(selected.range,this.offer.range)
|
|
426
582
|
|| this.dismissedRange && sameRange(selected.range,this.dismissedRange))) return;
|
|
427
583
|
this.hideOffer();
|
|
428
584
|
this.dismissedRange = undefined;
|
|
429
585
|
if (!selected) return;
|
|
586
|
+
this.showOffer(selected);
|
|
587
|
+
if (this.offerPointer && this.pointerInSelection(this.offerPointer,selected.range,selected.content)) this.setOfferHover(true);
|
|
588
|
+
else this.dismissOfferAfter(3000);
|
|
589
|
+
}
|
|
590
|
+
showOffer(selected) {
|
|
430
591
|
this.offer = {...selected,range:selected.range.cloneRange(),selectedText:window.getSelection().toString()};
|
|
592
|
+
this.offerSize.observe(selected.content);
|
|
431
593
|
this.refresh();
|
|
432
|
-
this.offerTimer = setTimeout(() => { this.dismissedRange = this.offer?.range; this.hideOffer(); },3000);
|
|
433
594
|
}
|
|
595
|
+
dismissOfferAfter(delay) {
|
|
596
|
+
clearTimeout(this.offerTimer);
|
|
597
|
+
this.offerTimer = setTimeout(() => { this.dismissedRange = this.offer?.range; this.hideOffer(); },delay);
|
|
598
|
+
}
|
|
599
|
+
setOfferHover(hovered) {
|
|
600
|
+
if (!this.offer || this.offerHovered === hovered) return;
|
|
601
|
+
this.offerHovered = hovered;
|
|
602
|
+
if (hovered) clearTimeout(this.offerTimer);
|
|
603
|
+
else this.dismissOfferAfter(5000);
|
|
604
|
+
}
|
|
605
|
+
pointerInSelection({target,clientX:x,clientY:y},range,content) {
|
|
606
|
+
if (!target || content && !content.contains(target)) return false;
|
|
607
|
+
const source = target.closest?.('pre.code') ? target.closest(codeText) : target;
|
|
608
|
+
if (!source || !range.intersectsNode(source)) return false;
|
|
609
|
+
return [...selectedNodeRange(source,range).getClientRects()].some(rect => rect.width && rect.height
|
|
610
|
+
&& x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom);
|
|
611
|
+
}
|
|
612
|
+
pointerInOffer(point) {
|
|
613
|
+
const tooltips = this.app.tooltips;
|
|
614
|
+
if (tooltips?.visible && this.selectionActions.contains(tooltips.visible)
|
|
615
|
+
&& (tooltips.isSelecting() || tooltips.tip.contains(point.target))) return true;
|
|
616
|
+
return point.target && (this.selectionActions.contains(point.target) || this.pointerInSelection(point,this.offer.range,this.offer.content));
|
|
617
|
+
}
|
|
618
|
+
inspectOffer = event => {
|
|
619
|
+
if (event.pointerType !== 'mouse' || event.buttons) return;
|
|
620
|
+
this.offerPointer = event;
|
|
621
|
+
if (!this.entry && this.pointer === undefined && !this.keyboard && !this.touchSettling && this.referenceMenu.hidden) {
|
|
622
|
+
if (this.offer) {
|
|
623
|
+
this.setOfferHover(Boolean(this.pointerInOffer(event)));
|
|
624
|
+
} else {
|
|
625
|
+
const selection = window.getSelection?.();
|
|
626
|
+
if (selection?.rangeCount && !selection.isCollapsed && this.pointerInSelection(event,selection.getRangeAt(0))) {
|
|
627
|
+
const selected = this.selection();
|
|
628
|
+
if (selected) { this.showOffer(selected); this.setOfferHover(true); }
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (this.offerHovered) this.hideNote(); else this.inspectNote(event);
|
|
633
|
+
};
|
|
634
|
+
noteAt(event) {
|
|
635
|
+
if (this.entry || this.pointer !== undefined || !this.visibleAnnotations.length) return;
|
|
636
|
+
const {clientX:x,clientY:y,target} = event, source = target.closest?.(codeText);
|
|
637
|
+
for (const mark of this.visibleAnnotations) {
|
|
638
|
+
if (!mark.content.contains(target)) continue;
|
|
639
|
+
const range = mark.codeRows ? mark.codeRows.find(row => row.source === source)?.range : mark.range;
|
|
640
|
+
if (!range?.intersectsNode(target)) continue;
|
|
641
|
+
for (const rect of range.getClientRects()) {
|
|
642
|
+
if (rect.width && x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom+2) {
|
|
643
|
+
return {mark,anchor:{left:x-10,top:rect.top,bottom:rect.bottom}};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
showNote({mark,anchor}) {
|
|
649
|
+
this.noteMark = mark;
|
|
650
|
+
this.note.textContent = mark.note;
|
|
651
|
+
this.position(this.note,mark,false,anchor);
|
|
652
|
+
}
|
|
653
|
+
hideNote = () => {
|
|
654
|
+
clearTimeout(this.noteTimer); this.noteTimer = undefined;
|
|
655
|
+
this.noteMark = undefined; this.note.hidden = true;
|
|
656
|
+
};
|
|
657
|
+
inspectNote = event => {
|
|
658
|
+
if (event.pointerType !== 'mouse' || event.buttons) return;
|
|
659
|
+
if (this.note.contains(event.target)) {
|
|
660
|
+
clearTimeout(this.noteTimer); this.noteTimer = undefined; return;
|
|
661
|
+
}
|
|
662
|
+
const hit = this.noteAt(event);
|
|
663
|
+
if (hit) {
|
|
664
|
+
clearTimeout(this.noteTimer); this.noteTimer = undefined;
|
|
665
|
+
if (this.note.hidden || this.noteMark?.id !== hit.mark.id) this.showNote(hit);
|
|
666
|
+
} else if (this.noteMark && !this.noteTimer) this.noteTimer = setTimeout(this.hideNote,220);
|
|
667
|
+
};
|
|
668
|
+
tapNote = event => {
|
|
669
|
+
if (event.pointerType !== 'touch' || this.note.contains(event.target) || window.getSelection()?.isCollapsed === false) return;
|
|
670
|
+
const hit = this.noteAt(event);
|
|
671
|
+
if (!hit) return;
|
|
672
|
+
event.preventDefault(); event.stopPropagation();
|
|
673
|
+
this.showNote(hit);
|
|
674
|
+
};
|
|
675
|
+
selectionReference(selected) {
|
|
676
|
+
if (!selected) return;
|
|
677
|
+
const quote = selected.selectedText ?? window.getSelection()?.toString();
|
|
678
|
+
if (!quote?.trim()) return;
|
|
679
|
+
if (selected.label) return {label:selected.label,turn:selected.turn,quote};
|
|
680
|
+
return annotationQuote({...selected,selectedText:quote}) ?? {...fileReference(selected.directory,selected.tab.path),quote};
|
|
681
|
+
}
|
|
682
|
+
addReference(reference,task) {
|
|
683
|
+
if (!reference || !task) { this.showReferenceStatus('无法添加这个引用。'); return; }
|
|
684
|
+
this.hideOffer();
|
|
685
|
+
if (embedded) {
|
|
686
|
+
const request = this.referenceRequest = instanceId();
|
|
687
|
+
window.parent.postMessage({type:'agentbot-workspace-reference',request,reference,task},window.location.origin);
|
|
688
|
+
} else this.showReferenceStatus(this.app.sessions.addReference(reference,task));
|
|
689
|
+
}
|
|
690
|
+
showReferenceStatus(error,success = '已添加引用到草稿') {
|
|
691
|
+
clearTimeout(this.referenceTimer);
|
|
692
|
+
this.referenceStatus.textContent = error || success;
|
|
693
|
+
this.referenceStatus.hidden = false;
|
|
694
|
+
this.referenceTimer = setTimeout(() => { this.referenceStatus.hidden = true; },2500);
|
|
695
|
+
}
|
|
696
|
+
async copyFileLocation(path,line) {
|
|
697
|
+
try {
|
|
698
|
+
await window.agentBotMarkdown.copy(line ? `${path}:${line}` : path);
|
|
699
|
+
this.showReferenceStatus(undefined,line ? '已复制文件路径和行号' : '已复制文件路径');
|
|
700
|
+
} catch { this.showReferenceStatus('复制失败。'); }
|
|
701
|
+
}
|
|
702
|
+
referenceContext = event => {
|
|
703
|
+
const task = embedded ? this.hostTask : this.app.sessions?.annotationTask();
|
|
704
|
+
const files = this.app.filesPanel, target = event.target;
|
|
705
|
+
if (!files?.contains(target) || this.entry) return;
|
|
706
|
+
const fileRow = target.closest('.file-navigation [data-file-path]'), tabRow = target.closest('.file-tab');
|
|
707
|
+
const contextTab = files.tabs.get(tabRow?.dataset.key);
|
|
708
|
+
const directoryRow = target.closest('.file-navigation details:is([data-directory],[data-filter-directory]) > summary');
|
|
709
|
+
const directoryControl = target.closest('[data-reference-directory]');
|
|
710
|
+
const inPreview = !files.hidden && files.renderedKey === files.activeKey && files.content.contains(target);
|
|
711
|
+
if (!task && !inPreview && !contextTab) return;
|
|
712
|
+
let reference, trigger, location;
|
|
713
|
+
if (fileRow && !fileRow.disabled) {
|
|
714
|
+
reference = fileReference(files.previewRoot(files.explorerDirectory),fileRow.dataset.filePath,fileRow.dataset.originalPath);
|
|
715
|
+
trigger = fileRow;
|
|
716
|
+
} else if (directoryRow) {
|
|
717
|
+
const {directory,filterDirectory} = directoryRow.parentElement.dataset;
|
|
718
|
+
reference = directoryReference(files.treeRoot,directory ?? filterDirectory);
|
|
719
|
+
trigger = directoryRow;
|
|
720
|
+
} else if (directoryControl) {
|
|
721
|
+
reference = directoryReference(undefined,directoryControl.dataset.referenceDirectory);
|
|
722
|
+
trigger = directoryControl;
|
|
723
|
+
} else if (tabRow || inPreview) {
|
|
724
|
+
const tab = files.tabs.get(tabRow?.dataset.key ?? files.activeKey);
|
|
725
|
+
if (tab?.kind === 'web') reference = {url:tab.path,label:tab.pageTitle};
|
|
726
|
+
else if (tab?.kind === 'directory') reference = directoryReference(undefined,files.directory(tab.path)?.path);
|
|
727
|
+
else if (['file','diff'].includes(tab?.kind)) {
|
|
728
|
+
reference = fileReference(files.previewRoot(tab.source),tab.path,tab.original);
|
|
729
|
+
if (inPreview && reference) {
|
|
730
|
+
location = previewFileLocation(target,reference);
|
|
731
|
+
const selection = this.selection();
|
|
732
|
+
if (selection?.tab === tab) reference = this.selectionReference(selection) ?? reference;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
trigger = tabRow?.querySelector('[role=tab]') ?? files.content;
|
|
736
|
+
}
|
|
737
|
+
const items = [];
|
|
738
|
+
if (task && reference) {
|
|
739
|
+
const label = reference.url ? '引用该网页' : reference.quote ? '引用该选区' : reference.directory ? '引用该路径' : '引用该文件';
|
|
740
|
+
items.push(['quote',label,() => this.addReference(reference,task)]);
|
|
741
|
+
}
|
|
742
|
+
if (contextTab) {
|
|
743
|
+
const pinned = files.pinnedTabs.has(contextTab.key);
|
|
744
|
+
const label = files.chinese ? (pinned ? '取消固定' : '固定') : (pinned ? 'Unpin' : 'Pin');
|
|
745
|
+
items.push([pinned?'unpin':'pin',label,() => files.setTabPinned(contextTab.key,!pinned,trigger)]);
|
|
746
|
+
}
|
|
747
|
+
if (location) {
|
|
748
|
+
items.push(['copy','复制文件路径',() => void this.copyFileLocation(location.path)]);
|
|
749
|
+
if (location.line) items.push(['copy','复制文件路径和行号',() => void this.copyFileLocation(location.path,location.line)]);
|
|
750
|
+
}
|
|
751
|
+
if (items.length) this.showReferenceMenu(event,trigger,items);
|
|
752
|
+
};
|
|
753
|
+
showReferenceMenu(event,trigger,actions) {
|
|
754
|
+
event.preventDefault();
|
|
755
|
+
this.closeReferenceMenu(); this.hideOffer(); this.hideNote();
|
|
756
|
+
const menu = this.referenceMenu;
|
|
757
|
+
const items = actions.map(([name,label,action]) => {
|
|
758
|
+
const button = element('button'); button.type = 'button'; button.setAttribute('role','menuitem');
|
|
759
|
+
button.append(typeof name === 'string' ? icon(name) : name,element('span',label));
|
|
760
|
+
button.onclick = () => { this.closeReferenceMenu(true); action(); };
|
|
761
|
+
return button;
|
|
762
|
+
});
|
|
763
|
+
menu.replaceChildren(...items);
|
|
764
|
+
this.referenceTrigger = trigger;
|
|
765
|
+
menu.hidden = false;
|
|
766
|
+
const origin = trigger.getBoundingClientRect(), {width,height} = menu.getBoundingClientRect();
|
|
767
|
+
const viewport = window.visualViewport, left = viewport?.offsetLeft ?? 0, top = viewport?.offsetTop ?? 0;
|
|
768
|
+
const right = left+(viewport?.width || document.documentElement.clientWidth), bottom = top+(viewport?.height || document.documentElement.clientHeight);
|
|
769
|
+
const point = event.clientX || event.clientY ? {x:event.clientX,y:event.clientY} : {x:origin.left,y:origin.bottom};
|
|
770
|
+
menu.style.left = `${Math.max(left+4,Math.min(point.x,right-width-4))}px`;
|
|
771
|
+
menu.style.top = `${Math.max(top+4,Math.min(point.y,bottom-height-4))}px`;
|
|
772
|
+
items[0].focus({preventScroll:true});
|
|
773
|
+
}
|
|
774
|
+
closeReferenceMenu(restoreFocus = false) {
|
|
775
|
+
if (this.referenceMenu.hidden) return;
|
|
776
|
+
const trigger = this.referenceTrigger;
|
|
777
|
+
this.referenceTrigger = undefined; this.referenceMenu.hidden = true;
|
|
778
|
+
if (restoreFocus && trigger?.isConnected) trigger.focus({preventScroll:true});
|
|
779
|
+
if (trigger && this.app.taskSidebar?.contains(trigger)) this.app.deferTaskPreviewClose();
|
|
780
|
+
}
|
|
781
|
+
referenceMenuKeys = event => {
|
|
782
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); this.closeReferenceMenu(true); return; }
|
|
783
|
+
if (!['ArrowUp','ArrowDown','Home','End'].includes(event.key)) return;
|
|
784
|
+
event.preventDefault();
|
|
785
|
+
const items = [...this.referenceMenu.children], current = items.indexOf(event.target);
|
|
786
|
+
const index = event.key === 'Home' ? 0 : event.key === 'End' ? items.length-1
|
|
787
|
+
: (current + (event.key === 'ArrowDown' ? 1 : items.length-1)) % items.length;
|
|
788
|
+
items[index].focus({preventScroll:true});
|
|
789
|
+
};
|
|
434
790
|
selection() {
|
|
435
791
|
const sessions = this.app.sessions, task = embedded ? this.hostTask : sessions?.annotationTask(), selection = window.getSelection?.();
|
|
436
792
|
if (!selection?.rangeCount || selection.isCollapsed || !task) return;
|
|
437
793
|
const range = selection.getRangeAt(0);
|
|
794
|
+
const backward = selection.focusNode === range.startContainer && selection.focusOffset === range.startOffset;
|
|
438
795
|
const start = selectionElement(range.startContainer), end = selectionElement(range.endContainer);
|
|
439
796
|
const chat = sessions?.body;
|
|
440
797
|
if (chat?.contains(range.commonAncestorContainer) && start?.closest('.session-turn-content,.session-outbox') && end?.closest('.session-turn-content,.session-outbox')) {
|
|
441
798
|
const label = start.closest('.session-message')?.getAttribute('aria-label') || (start.closest('[data-tool]') ? '工具输出' : '对话记录');
|
|
442
799
|
const scope = selectionElement(range.commonAncestorContainer)?.closest('.session-turn-content,.session-outbox');
|
|
443
800
|
const turns = [...new Set([start,end].map(node => node.closest('[data-turn]')?.dataset.turn).filter(Boolean))];
|
|
444
|
-
return {range,content:chat,preview:scope || chat,anchorKind:scope?.classList.contains('session-turn-content') ? 'turn' : scope ? 'outbox' : 'chat',
|
|
801
|
+
return {range,backward,content:chat,preview:scope || chat,anchorKind:scope?.classList.contains('session-turn-content') ? 'turn' : scope ? 'outbox' : 'chat',
|
|
445
802
|
task,label:'聊天 · '+label,turn:turns.join(' → ') || undefined};
|
|
446
803
|
}
|
|
447
804
|
const files = this.app.filesPanel, tab = files?.tabs.get(files.activeKey);
|
|
448
|
-
if (files
|
|
805
|
+
if (!files || files.hidden || files.renderedKey !== tab?.key || !['file','diff'].includes(tab?.kind)) return;
|
|
449
806
|
const content = files.content, directory = files.previewRoot(tab.source);
|
|
450
|
-
if (!directory || !content.contains(range.commonAncestorContainer)) return;
|
|
807
|
+
if ((!directory && !absoluteFilePath(tab.path)) || !content.contains(range.commonAncestorContainer)) return;
|
|
451
808
|
const preview = start?.closest('pre.code,.markdown-body');
|
|
452
809
|
if (!preview || end?.closest('pre.code,.markdown-body') !== preview) return;
|
|
453
|
-
|
|
810
|
+
const codeRows = preview.matches('.code') ? annotationCodeRows(preview,range) : undefined;
|
|
811
|
+
if (codeRows?.length === 0) return;
|
|
812
|
+
return {range,backward,codeRows,content,preview,anchorKind:tab.kind,tab,directory,task};
|
|
454
813
|
}
|
|
455
814
|
open() {
|
|
456
815
|
const selected = this.offer;
|
|
457
|
-
if (!selected || this.entry || this.
|
|
458
|
-
const {label,turn,selectedText,task,content,range,tab,preview,anchorKind} = selected;
|
|
816
|
+
if (!selected || this.entry || this.selectionActions.hidden) return;
|
|
817
|
+
const {label,turn,selectedText,task,content,range,codeRows,tab,preview,anchorKind} = selected;
|
|
459
818
|
const annotation = label ? {label,turn,quote:selectedText} : annotationQuote(selected);
|
|
460
819
|
if (!annotation?.quote.trim()) return;
|
|
461
820
|
const anchor = annotationAnchor(range,preview,anchorKind);
|
|
462
|
-
this.
|
|
463
|
-
|
|
821
|
+
this.openEditor({annotation:{...annotation,anchor},task,content,range,codeRows,tab});
|
|
822
|
+
}
|
|
823
|
+
openNote() {
|
|
824
|
+
const selected = this.visibleAnnotations.find(mark => mark.id === this.noteMark?.id);
|
|
825
|
+
const task = embedded ? this.hostTask : this.app.sessions?.annotationTask();
|
|
826
|
+
if (!selected || this.entry || this.note.hidden || !task || task !== this.draftTask) return;
|
|
827
|
+
this.openEditor({...selected,task});
|
|
828
|
+
}
|
|
829
|
+
openEditor(entry) {
|
|
830
|
+
this.entry = entry;
|
|
831
|
+
this.input.value = entry.note ?? '';
|
|
832
|
+
this.form.setAttribute('aria-label',entry.id ? '编辑批注' : '添加批注');
|
|
833
|
+
const action = entry.id ? '保存批注' : '添加到聊天';
|
|
834
|
+
this.submit.setAttribute('aria-label',action); this.submit.dataset.tooltip = action;
|
|
835
|
+
this.highlight('workspace-annotation-selection',entry.codeRows?.map(row => row.range) ?? [entry.range]);
|
|
836
|
+
this.hideNote();
|
|
464
837
|
this.hideOffer(); this.form.hidden = false;
|
|
465
838
|
this.grow(); this.input.focus({preventScroll:true});
|
|
466
839
|
}
|
|
467
840
|
grow() {
|
|
468
841
|
this.measure.textContent = this.input.value;
|
|
842
|
+
this.cancelButton.disabled = Boolean(this.pending);
|
|
469
843
|
this.submit.disabled = !this.input.value.trim() || Boolean(this.pending);
|
|
470
844
|
this.refresh();
|
|
471
845
|
}
|
|
@@ -476,23 +850,38 @@
|
|
|
476
850
|
commit() {
|
|
477
851
|
const note = this.input.value.trim(), entry = this.entry;
|
|
478
852
|
if (!entry || !note || this.pending) return;
|
|
479
|
-
const annotation = {...entry.annotation,note};
|
|
480
|
-
if (annotation
|
|
853
|
+
const annotation = entry.id ? undefined : {...entry.annotation,note};
|
|
854
|
+
if (annotation?.quote.length > 100_000) { this.finish('选中的文字过长,请缩小选区后再添加批注。'); return; }
|
|
481
855
|
if (embedded) {
|
|
482
|
-
|
|
483
|
-
this.submit.disabled = true;
|
|
484
|
-
this.replyTimer = setTimeout(() => this.finish('未能添加批注,请重试。'),3000);
|
|
485
|
-
window.parent.postMessage({type:'agentbot-workspace-annotate',request,annotation,task:entry.task},window.location.origin);
|
|
856
|
+
this.requestChange(entry.task,entry.id ? {id:entry.id,note} : {annotation},'未能保存批注,请重试。');
|
|
486
857
|
} else {
|
|
487
|
-
const
|
|
858
|
+
const sessions = this.app.sessions;
|
|
859
|
+
const error = entry.id ? sessions.editAnnotation(entry.id,note,entry.task) : sessions.addAnnotation(annotation,entry.task);
|
|
488
860
|
this.finish(error);
|
|
489
861
|
}
|
|
490
862
|
}
|
|
863
|
+
remove() {
|
|
864
|
+
const entry = this.entry;
|
|
865
|
+
if (!entry || this.pending) return;
|
|
866
|
+
if (!entry.id) { this.cancel(); return; }
|
|
867
|
+
if (embedded) this.requestChange(entry.task,{id:entry.id,remove:true},'未能移除批注,请重试。');
|
|
868
|
+
else this.finish(this.app.sessions.removeAnnotation(entry.id,entry.task));
|
|
869
|
+
}
|
|
870
|
+
requestChange(task,change,timeoutError) {
|
|
871
|
+
const request = this.pending = instanceId();
|
|
872
|
+
this.grow();
|
|
873
|
+
this.replyTimer = setTimeout(() => this.finish(timeoutError),3000);
|
|
874
|
+
window.parent.postMessage({type:'agentbot-workspace-annotate',request,task,...change},window.location.origin);
|
|
875
|
+
}
|
|
491
876
|
result = event => {
|
|
492
877
|
if (event.source !== window.parent || event.origin !== window.location.origin) return;
|
|
878
|
+
if (event.data?.type === 'agentbot-workspace-reference-result' && event.data.request === this.referenceRequest) {
|
|
879
|
+
this.referenceRequest = undefined;
|
|
880
|
+
this.showReferenceStatus(event.data.error);
|
|
881
|
+
}
|
|
493
882
|
if (event.data?.type === 'agentbot-workspace-annotation-result' && this.pending && event.data.request === this.pending) this.finish(event.data.error);
|
|
494
883
|
if (event.data?.type === 'agentbot-workspace-annotation-drafts') {
|
|
495
|
-
this.hostTask = event.data.task;
|
|
884
|
+
this.hostTask = this.draftTask = event.data.task;
|
|
496
885
|
this.draftAnnotations = event.data.annotations;
|
|
497
886
|
this.paintDrafts();
|
|
498
887
|
}
|
|
@@ -510,31 +899,33 @@
|
|
|
510
899
|
if (this.entry) this.dismissedRange = this.entry.range;
|
|
511
900
|
clearTimeout(this.replyTimer); this.pending = this.entry = undefined;
|
|
512
901
|
this.form.hidden = true; this.input.value = this.status.textContent = '';
|
|
513
|
-
this.hideOffer(); this.highlight('workspace-annotation-selection',[]);
|
|
902
|
+
this.hideOffer(); this.hideNote(); this.closeReferenceMenu(); this.highlight('workspace-annotation-selection',[]);
|
|
514
903
|
}
|
|
515
904
|
highlight(name,ranges) {
|
|
516
905
|
if (!window.CSS?.highlights || typeof Highlight !== 'function') return;
|
|
517
906
|
if (ranges.length) CSS.highlights.set(name,new Highlight(...ranges)); else CSS.highlights.delete(name);
|
|
518
907
|
}
|
|
519
908
|
updateDrafts(task,attachments) {
|
|
909
|
+
if (task !== this.draftTask) this.hideNote();
|
|
520
910
|
this.draftTask = task;
|
|
521
|
-
this.draftAnnotations = attachments.flatMap(({annotation}) => annotation?.anchor ? [annotation] : []);
|
|
911
|
+
this.draftAnnotations = attachments.flatMap(({id,annotation}) => annotation?.anchor ? [{...annotation,id}] : []);
|
|
522
912
|
this.paintDrafts();
|
|
523
913
|
for (const tab of this.app.filesPanel?.tabs.values() || []) this.syncFrame(tab);
|
|
524
914
|
}
|
|
525
915
|
syncFrame(tab) {
|
|
526
916
|
if (tab.kind !== 'directory' || !tab.frameReady) return;
|
|
527
|
-
const annotations = this.draftAnnotations.filter(item => item.path).map(({path,anchor}) => ({path,anchor}));
|
|
917
|
+
const annotations = this.draftAnnotations.filter(item => item.path).map(({id,path,anchor,note}) => ({id,path,anchor,note}));
|
|
528
918
|
tab.frame.contentWindow?.postMessage({type:'agentbot-workspace-annotation-drafts',task:this.draftTask,
|
|
529
919
|
annotations},window.location.origin);
|
|
530
920
|
}
|
|
531
921
|
paintDrafts() {
|
|
532
922
|
if (!window.CSS?.highlights) return;
|
|
533
923
|
const files = this.app.filesPanel, tab = files?.tabs.get(files.activeKey), sessions = this.app.sessions;
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
const ranges = [];
|
|
537
|
-
for (const
|
|
924
|
+
const file = files?.renderedKey === tab?.key && ['file','diff'].includes(tab?.kind)
|
|
925
|
+
? fileReference(files.previewRoot(tab.source),tab.path)?.path : undefined;
|
|
926
|
+
const ranges = [], visible = [];
|
|
927
|
+
for (const item of [...this.draftAnnotations].reverse()) {
|
|
928
|
+
const {path,turn,anchor} = item;
|
|
538
929
|
let root;
|
|
539
930
|
if (path) {
|
|
540
931
|
if (file !== path || tab.kind !== anchor.kind) continue;
|
|
@@ -542,8 +933,14 @@
|
|
|
542
933
|
} else if (anchor.kind === 'turn') root = sessions?.turnNodes.get(turn)?.content;
|
|
543
934
|
else root = anchor.kind === 'outbox' ? sessions?.outbox : sessions?.body;
|
|
544
935
|
const range = restoreAnnotationRange(root,anchor);
|
|
545
|
-
if (range)
|
|
936
|
+
if (!range) continue;
|
|
937
|
+
const codeRows = path && root.matches('.code') ? annotationCodeRows(root,range) : undefined;
|
|
938
|
+
if (codeRows?.length === 0) continue;
|
|
939
|
+
visible.push({...item,range,codeRows,content:path ? files.content : sessions.body,tab:path ? tab : undefined});
|
|
940
|
+
for (const part of codeRows?.map(row => row.range) ?? [range]) ranges.push(part);
|
|
546
941
|
}
|
|
942
|
+
this.visibleAnnotations = visible;
|
|
943
|
+
if (this.noteMark && !visible.some(mark => mark.id === this.noteMark.id && mark.note === this.noteMark.note && mark.tab === this.noteMark.tab)) this.hideNote();
|
|
547
944
|
this.highlight('workspace-annotation-draft',ranges);
|
|
548
945
|
}
|
|
549
946
|
hasDraft() {
|
|
@@ -559,26 +956,49 @@
|
|
|
559
956
|
this.form.hidden = !entry.content.isConnected || !entry.content.clientHeight
|
|
560
957
|
|| Boolean(entry.tab && this.app.filesPanel.tabs.get(this.app.filesPanel.activeKey) !== entry.tab);
|
|
561
958
|
if (!this.form.hidden) this.position(this.form,entry,true);
|
|
562
|
-
} else if (this.offer)
|
|
959
|
+
} else if (this.offer) {
|
|
960
|
+
this.position(this.selectionActions,this.offer,false);
|
|
961
|
+
if (this.offerHovered && this.offerPointer && document.elementFromPoint) {
|
|
962
|
+
const {clientX,clientY} = this.offerPointer;
|
|
963
|
+
this.setOfferHover(Boolean(this.pointerInOffer({clientX,clientY,target:document.elementFromPoint(clientX,clientY)})));
|
|
964
|
+
}
|
|
965
|
+
}
|
|
563
966
|
};
|
|
564
|
-
position(node,
|
|
565
|
-
const
|
|
566
|
-
if (!editing && (!rect.width || !rect.height || rect.bottom <= bounds.top || rect.top >= bounds.bottom
|
|
567
|
-
|| rect.right <= bounds.left || rect.left >= bounds.right)) { node.hidden = true; return; }
|
|
967
|
+
position(node,selection,editing,anchor) {
|
|
968
|
+
const {content,range,codeRows} = selection, bounds = content.getBoundingClientRect();
|
|
568
969
|
const viewport = window.visualViewport, gap = 5;
|
|
569
970
|
const leftEdge = viewport?.offsetLeft || 0, topEdge = viewport?.offsetTop || 0;
|
|
570
971
|
const rightEdge = leftEdge+(viewport?.width || document.documentElement.clientWidth);
|
|
571
972
|
const bottomEdge = topEdge+(viewport?.height || document.documentElement.clientHeight);
|
|
973
|
+
const first = codeRows?.[0], last = codeRows?.at(-1);
|
|
974
|
+
const contentLeft = bounds.left+content.clientLeft, contentTop = bounds.top+content.clientTop;
|
|
975
|
+
const codeLeft = editing && first ? first.source.getBoundingClientRect().left : contentLeft;
|
|
976
|
+
const minLeft = Math.max(contentLeft,leftEdge,codeLeft), maxRight = Math.min(contentLeft+content.clientWidth,rightEdge);
|
|
977
|
+
const minTop = Math.max(contentTop,topEdge), maxBottom = Math.min(contentTop+content.clientHeight,bottomEdge);
|
|
978
|
+
if (maxRight <= minLeft || maxBottom <= minTop) { node.hidden = true; return; }
|
|
979
|
+
const lineStart = !editing && last && coversCodeRows(codeRows);
|
|
980
|
+
let rect;
|
|
981
|
+
if (!editing) {
|
|
982
|
+
rect = anchor ?? (lineStart ? last.source.getBoundingClientRect() : annotationFocusRect(selection,minLeft,maxRight));
|
|
983
|
+
if (!rect || rect.bottom <= minTop || rect.top >= maxBottom || !anchor && lineStart && (rect.right <= minLeft || rect.left >= maxRight)) {
|
|
984
|
+
node.hidden = true; return;
|
|
985
|
+
}
|
|
986
|
+
} else if (first) {
|
|
987
|
+
const start = first.range.getBoundingClientRect(), end = last.range.getBoundingClientRect();
|
|
988
|
+
rect = {left:first === last ? start.left : codeLeft,top:start.top,bottom:end.bottom};
|
|
989
|
+
} else rect = range.getBoundingClientRect();
|
|
572
990
|
node.hidden = false;
|
|
573
|
-
|
|
574
|
-
const minTop = Math.max(bounds.top,topEdge), maxBottom = Math.min(bounds.bottom,bottomEdge);
|
|
991
|
+
if (anchor) node.style.maxWidth = `${Math.max(1,Math.min(360,maxRight-minLeft-2*gap))}px`;
|
|
575
992
|
if (editing) {
|
|
576
993
|
const width = Math.min(maxRight-minLeft,Math.max(220,this.measure.scrollWidth+this.actions.offsetWidth+22));
|
|
577
994
|
node.style.width = `${width}px`;
|
|
578
995
|
this.input.style.height = '0px'; this.input.style.height = `${this.input.scrollHeight}px`;
|
|
579
996
|
}
|
|
580
997
|
const {width,height} = node.getBoundingClientRect();
|
|
581
|
-
|
|
998
|
+
if (!editing && (width > maxRight-minLeft || height > maxBottom-minTop)) { node.hidden = true; return; }
|
|
999
|
+
const alignRight = !editing && !anchor && !lineStart;
|
|
1000
|
+
const inset = editing || alignRight ? 0 : Math.min(gap,(maxRight-minLeft-width)/2);
|
|
1001
|
+
const left = Math.max(minLeft+inset,Math.min(alignRight ? rect.right-width : rect.left,maxRight-width-inset));
|
|
582
1002
|
const after = rect.bottom+gap, before = rect.top-height-gap;
|
|
583
1003
|
const top = after+height <= maxBottom || before < minTop ? after : before;
|
|
584
1004
|
node.style.left = `${left}px`;
|
|
@@ -587,13 +1007,14 @@
|
|
|
587
1007
|
disconnect() {
|
|
588
1008
|
this.listeners.abort(); this.observer?.disconnect(); clearTimeout(this.settleTimer); this.cancel();
|
|
589
1009
|
this.highlight('workspace-annotation-draft',[]);
|
|
590
|
-
|
|
1010
|
+
clearTimeout(this.referenceTimer);
|
|
1011
|
+
this.selectionActions.remove(); this.note.remove(); this.form.remove(); this.referenceMenu.remove(); this.referenceStatus.remove();
|
|
591
1012
|
}
|
|
592
1013
|
}
|
|
593
1014
|
const toolIcons = {
|
|
594
1015
|
command:'terminal',execute:'terminal',repl:'terminal',read:'file',edit:'pencil',write:'pencil',file_change:'diff',
|
|
595
1016
|
delete:'trash',move:'forward',search:'search',web_search:'search',fetch:'web',mcp:'plug',
|
|
596
|
-
image_view:'file-image',image_generation:'file-image',think:'chat',switch_mode:'branch',
|
|
1017
|
+
image_view:'file-image',image_generation:'file-image',think:'chat',switch_mode:'branch',hourglass:'hourglass',
|
|
597
1018
|
};
|
|
598
1019
|
const fileIcon = path => {
|
|
599
1020
|
const name = path.replaceAll('\\','/').split('/').pop().toLowerCase(), extension = name.split('.').pop();
|
|
@@ -626,6 +1047,7 @@
|
|
|
626
1047
|
count.dataset.tooltip = label; count.setAttribute('aria-hidden','true'); metadata.append(stats,count); summary.append(metadata); summary.setAttribute('aria-label',item.name+(item.ignored?',Git 已忽略':'')+','+label+','+stats.dataset.tooltip);
|
|
627
1048
|
};
|
|
628
1049
|
const tabStripSelector = '.file-tabs,.explorer-directory-tabs';
|
|
1050
|
+
const pinnedTabWidth = 32;
|
|
629
1051
|
class WorkspaceScrollbars {
|
|
630
1052
|
constructor(host) {
|
|
631
1053
|
this.host = host; this.hovered = new Set(); this.recent = new Map(); this.entries = new Map(); this.targets = new WeakMap();
|
|
@@ -706,7 +1128,7 @@
|
|
|
706
1128
|
this.frame = window.requestAnimationFrame(() => { this.frame = undefined; this.render(); });
|
|
707
1129
|
};
|
|
708
1130
|
axes(node) {
|
|
709
|
-
if (!this.host.contains(node) || !(node.clientWidth > 0 && node.clientHeight > 0)) return;
|
|
1131
|
+
if (!this.host.contains(node) || !(node.clientWidth > 0 && node.clientHeight > 0) || node.matches('.address-options')) return;
|
|
710
1132
|
const x = node.scrollWidth > node.clientWidth+1, y = node.scrollHeight > node.clientHeight+1; if (!x && !y) return;
|
|
711
1133
|
const style = window.getComputedStyle(node), horizontal = x && ['auto','scroll'].includes(style.overflowX), vertical = y && ['auto','scroll'].includes(style.overflowY);
|
|
712
1134
|
if (horizontal || vertical) return {horizontal,vertical};
|
|
@@ -769,9 +1191,8 @@
|
|
|
769
1191
|
}
|
|
770
1192
|
}
|
|
771
1193
|
const tooltipControls = '[data-tooltip], [data-tooltip-shortcut], [data-tooltip-overflow]';
|
|
772
|
-
function tooltipShortcut(
|
|
773
|
-
|
|
774
|
-
const shortcuts = (node.getAttribute('aria-keyshortcuts') || '').split(/\s+/u).filter(Boolean);
|
|
1194
|
+
function tooltipShortcut(value) {
|
|
1195
|
+
const shortcuts = (value || '').split(/\s+/u).filter(Boolean);
|
|
775
1196
|
const preferred = applePlatform ? 'Meta' : 'Control', alternate = applePlatform ? 'Control' : 'Meta';
|
|
776
1197
|
const keys = {Escape:'Esc',ArrowLeft:'←',ArrowRight:'→',ArrowUp:'↑',ArrowDown:'↓',
|
|
777
1198
|
...(applePlatform ? {Control:'⌃',Meta:'⌘',Alt:'⌥',Shift:'⇧'} : {Control:'Ctrl'})};
|
|
@@ -779,6 +1200,8 @@
|
|
|
779
1200
|
|| !shortcuts.includes(parts.map(key => key === alternate ? preferred : key).join('+')))
|
|
780
1201
|
.map(parts => parts.map(key => keys[key] || key).join(applePlatform ? '' : '+')).join(' / ');
|
|
781
1202
|
}
|
|
1203
|
+
const buttonShortcuts = ':is(button,a,[role=button]):is([aria-keyshortcuts],[data-tooltip-shortcut],[data-tooltip-detail-shortcut])';
|
|
1204
|
+
const shortcutModifier = applePlatform ? 'Meta' : 'Control';
|
|
782
1205
|
class WorkspaceTooltips {
|
|
783
1206
|
constructor(host) {
|
|
784
1207
|
this.host = host;
|
|
@@ -787,21 +1210,35 @@
|
|
|
787
1210
|
this.topLayer = typeof tip.showPopover === 'function';
|
|
788
1211
|
if (this.topLayer) tip.setAttribute('popover','manual');
|
|
789
1212
|
this.label = element('span'); this.detail = element('small',undefined,'workspace-tooltip-detail');
|
|
790
|
-
this.shortcut = element('kbd');
|
|
1213
|
+
this.shortcut = element('kbd'); this.detailShortcut = element('kbd',undefined,'workspace-tooltip-detail-shortcut');
|
|
1214
|
+
this.note = element('small',undefined,'workspace-tooltip-note');
|
|
1215
|
+
tip.append(this.label,this.shortcut,this.detail,this.detailShortcut,this.note); host.append(tip);
|
|
1216
|
+
const hints = this.hints = element('div',undefined,'workspace-shortcut-hints');
|
|
1217
|
+
hints.hidden = true; hints.setAttribute('aria-hidden','true');
|
|
1218
|
+
if (this.topLayer) hints.setAttribute('popover','manual');
|
|
1219
|
+
host.append(hints);
|
|
791
1220
|
this.events = new AbortController();
|
|
792
1221
|
const {signal} = this.events;
|
|
793
1222
|
for (const type of ['pointerover','pointerout']) host.addEventListener(type,this.pointer,{capture:true,signal});
|
|
794
1223
|
host.addEventListener('focusin',this.focus,{signal}); host.addEventListener('focusout',this.blur,{signal});
|
|
795
|
-
host.addEventListener('pointerdown',this.
|
|
1224
|
+
host.addEventListener('pointerdown',this.pointerDown,{capture:true,signal});
|
|
1225
|
+
window.addEventListener('pointermove',this.pointerMove,{signal});
|
|
1226
|
+
for (const type of ['pointerup','pointercancel']) window.addEventListener(type,this.pointerUp,{signal});
|
|
1227
|
+
document.addEventListener('selectionchange',this.selectionChanged,{signal});
|
|
796
1228
|
host.addEventListener('scroll',this.scroll,{capture:true,signal});
|
|
797
|
-
host.addEventListener('click',this.
|
|
798
|
-
window.addEventListener('resize',this.dismiss
|
|
799
|
-
window.addEventListener('
|
|
1229
|
+
host.addEventListener('click',this.click,{signal});
|
|
1230
|
+
window.addEventListener('resize',() => { this.dismiss(); this.queueHints(); },{signal});
|
|
1231
|
+
window.addEventListener('blur',() => { this.dismiss(); this.hideHints(); },{signal});
|
|
1232
|
+
document.addEventListener('visibilitychange',() => { if (document.hidden) this.hideHints(); },{signal});
|
|
1233
|
+
window.addEventListener('keydown',this.key,{capture:true,signal});
|
|
1234
|
+
window.addEventListener('keyup',event => { if (event.key === shortcutModifier) this.hideHints(); },{capture:true,signal});
|
|
800
1235
|
this.size = new ResizeObserver(this.render);
|
|
801
1236
|
this.changes = new window.MutationObserver(records => {
|
|
802
|
-
if (
|
|
1237
|
+
if (!records.some(record => !tip.contains(record.target) && !hints.contains(record.target))) return;
|
|
1238
|
+
if (this.visible) this.render();
|
|
1239
|
+
this.queueHints();
|
|
803
1240
|
});
|
|
804
|
-
this.changes.observe(host,{subtree:true,childList:true,attributes:true,attributeFilter:['aria-label','aria-keyshortcuts','data-tooltip','data-tooltip-shortcut','data-tooltip-overflow','hidden']});
|
|
1241
|
+
this.changes.observe(host,{subtree:true,childList:true,attributes:true,attributeFilter:['aria-label','aria-keyshortcuts','data-tooltip','data-tooltip-detail','data-tooltip-shortcut','data-tooltip-detail-shortcut','data-tooltip-overflow','data-pane','data-view','open','hidden']});
|
|
805
1242
|
}
|
|
806
1243
|
control(node) {
|
|
807
1244
|
if (!node) return;
|
|
@@ -809,14 +1246,71 @@
|
|
|
809
1246
|
const control = node.closest?.(tooltipControls), nativeTitle = node.closest?.('[title]');
|
|
810
1247
|
if (control && this.host.contains(control) && !(nativeTitle && control.contains(nativeTitle))) return control;
|
|
811
1248
|
}
|
|
1249
|
+
hasSelection() {
|
|
1250
|
+
const selection = window.getSelection?.();
|
|
1251
|
+
return Boolean(this.visible && selection?.anchorNode && !selection.isCollapsed && this.tip.contains(selection.anchorNode));
|
|
1252
|
+
}
|
|
1253
|
+
isSelecting() { return Boolean(this.selectionGesture) || this.hasSelection(); }
|
|
1254
|
+
pauseAutoHide() { clearTimeout(this.timer); clearTimeout(this.autoHide); }
|
|
1255
|
+
pointerDown = event => {
|
|
1256
|
+
if (!this.tip.contains(event.target)) { this.dismiss(); return; }
|
|
1257
|
+
this.pauseAutoHide();
|
|
1258
|
+
if (event.button === 0) this.selectionGesture = event;
|
|
1259
|
+
};
|
|
1260
|
+
pointerMove = event => {
|
|
1261
|
+
if (this.selectionGesture && this.selectionGesture.pointerId === event.pointerId) this.selectionGesture = event;
|
|
1262
|
+
};
|
|
1263
|
+
pointerUp = event => {
|
|
1264
|
+
if (!this.selectionGesture || this.selectionGesture.pointerId !== event.pointerId) return;
|
|
1265
|
+
this.keepSelectionInTip();
|
|
1266
|
+
this.selectionGesture = undefined;
|
|
1267
|
+
this.resumeAfterSelection();
|
|
1268
|
+
};
|
|
1269
|
+
keepSelectionInTip() {
|
|
1270
|
+
const point = this.selectionGesture;
|
|
1271
|
+
if (!point) return;
|
|
1272
|
+
const selection = window.getSelection?.();
|
|
1273
|
+
if (!selection?.anchorNode || selection.isCollapsed
|
|
1274
|
+
|| !this.tip.contains(selection.anchorNode) || this.tip.contains(selection.focusNode)) return;
|
|
1275
|
+
const {left,right,top,bottom} = this.tip.getBoundingClientRect();
|
|
1276
|
+
const x = Math.max(left+2,Math.min(right-2,point.clientX));
|
|
1277
|
+
const y = Math.max(top+2,Math.min(bottom-2,point.clientY));
|
|
1278
|
+
const caret = document.caretPositionFromPoint?.(x,y);
|
|
1279
|
+
const range = caret ? undefined : document.caretRangeFromPoint?.(x,y);
|
|
1280
|
+
const node = caret?.offsetNode ?? range?.startContainer;
|
|
1281
|
+
if (node && this.tip.contains(node)) selection.extend(node,caret?.offset ?? range.startOffset);
|
|
1282
|
+
else {
|
|
1283
|
+
const after = point.clientY >= bottom || point.clientY > top && point.clientX >= right;
|
|
1284
|
+
selection.extend(this.tip,after ? this.tip.childNodes.length : 0);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
selectionChanged = () => {
|
|
1288
|
+
this.keepSelectionInTip();
|
|
1289
|
+
const selected = this.hasSelection();
|
|
1290
|
+
if (selected) this.pauseAutoHide();
|
|
1291
|
+
else if (this.textSelected) this.resumeAfterSelection();
|
|
1292
|
+
this.textSelected = selected;
|
|
1293
|
+
};
|
|
1294
|
+
resumeAfterSelection() {
|
|
1295
|
+
if (!this.visible || this.pointed === this.tip || this.isSelecting()) return;
|
|
1296
|
+
clearTimeout(this.timer);
|
|
1297
|
+
if (this.pointed === this.visible || this.focused === this.visible) this.startAutoHide();
|
|
1298
|
+
else this.timer = setTimeout(this.dismiss,140);
|
|
1299
|
+
}
|
|
812
1300
|
pointer = event => {
|
|
813
1301
|
if (event.pointerType === 'touch') return;
|
|
814
1302
|
const node = this.control(event.type === 'pointerout' ? event.relatedTarget : event.target);
|
|
815
1303
|
if (node === this.pointed) return;
|
|
1304
|
+
const wasOverTip = this.pointed === this.tip;
|
|
816
1305
|
this.pointed = node;
|
|
817
|
-
if (node === this.tip ||
|
|
1306
|
+
if (node === this.tip || this.isSelecting()) {
|
|
1307
|
+
this.pauseAutoHide(); return;
|
|
1308
|
+
}
|
|
818
1309
|
const target = node || this.focused;
|
|
819
|
-
if (target
|
|
1310
|
+
if (target && target === this.visible) {
|
|
1311
|
+
clearTimeout(this.timer);
|
|
1312
|
+
if (wasOverTip) this.startAutoHide();
|
|
1313
|
+
} else if (target) this.schedule(target,node ? 400 : 0);
|
|
820
1314
|
else { clearTimeout(this.timer); this.timer = setTimeout(this.dismiss,140); }
|
|
821
1315
|
};
|
|
822
1316
|
focus = event => {
|
|
@@ -828,32 +1322,60 @@
|
|
|
828
1322
|
blur = event => {
|
|
829
1323
|
if (this.focused !== event.target) return;
|
|
830
1324
|
this.focused = undefined;
|
|
831
|
-
if (this.pointed
|
|
832
|
-
|
|
1325
|
+
if (this.pointed === this.tip || this.isSelecting()) return;
|
|
1326
|
+
if (this.pointed) this.schedule(this.pointed,400);
|
|
1327
|
+
else this.dismiss();
|
|
1328
|
+
};
|
|
1329
|
+
click = event => {
|
|
1330
|
+
const node = this.control(event.target);
|
|
1331
|
+
if (node === this.tip || this.hasSelection()) return;
|
|
1332
|
+
if (node?.matches('[data-annotation-tooltip],[data-tooltip-on-click]')) {
|
|
1333
|
+
this.focused = node; this.schedule(node,0);
|
|
1334
|
+
} else this.dismiss();
|
|
1335
|
+
};
|
|
1336
|
+
key = event => {
|
|
1337
|
+
if (event.key === 'Escape') this.dismiss();
|
|
1338
|
+
if (event.key !== shortcutModifier || event.altKey || event.shiftKey || (applePlatform ? event.ctrlKey : event.metaKey)) {
|
|
1339
|
+
this.hideHints(); return;
|
|
1340
|
+
}
|
|
1341
|
+
if (event.repeat || this.holdTimer !== undefined || !this.hints.hidden) return;
|
|
1342
|
+
this.holdTimer = setTimeout(() => {
|
|
1343
|
+
this.holdTimer = undefined;
|
|
1344
|
+
if (this.isSelecting()) return;
|
|
1345
|
+
this.showHints();
|
|
1346
|
+
if (embedded) window.parent.postMessage({type:'agentbot-workspace-shortcut-hints',visible:true},window.location.origin);
|
|
1347
|
+
},500);
|
|
833
1348
|
};
|
|
834
|
-
key = event => { if (event.key === 'Escape') this.dismiss(); };
|
|
835
1349
|
scroll = event => {
|
|
836
1350
|
const target = this.visible || this.focused;
|
|
837
1351
|
if (target && event.target.contains(target)) this.dismiss();
|
|
1352
|
+
this.queueHints();
|
|
838
1353
|
};
|
|
839
1354
|
schedule(node,delay) {
|
|
1355
|
+
if (!this.hints.hidden) return;
|
|
840
1356
|
this.hide(); this.timer = setTimeout(() => {
|
|
841
1357
|
this.visible = node; this.render();
|
|
842
1358
|
if (this.visible) {
|
|
843
1359
|
this.size.observe(node);
|
|
844
|
-
this.
|
|
1360
|
+
this.startAutoHide();
|
|
845
1361
|
}
|
|
846
1362
|
},delay);
|
|
847
1363
|
}
|
|
1364
|
+
startAutoHide() {
|
|
1365
|
+
clearTimeout(this.autoHide);
|
|
1366
|
+
this.autoHide = setTimeout(this.dismiss,5000);
|
|
1367
|
+
}
|
|
848
1368
|
render = () => {
|
|
849
1369
|
const node = this.visible;
|
|
850
1370
|
if (!node) return;
|
|
851
1371
|
if (!this.host.contains(node) || !node.matches(tooltipControls) || !node.getClientRects().length) { this.dismiss(); return; }
|
|
852
1372
|
const label = (node.dataset.tooltip || node.getAttribute('aria-label') || node.textContent).trim();
|
|
853
1373
|
if (!label) { this.dismiss(); return; }
|
|
854
|
-
const shortcut = tooltipShortcut
|
|
1374
|
+
const shortcut = node.dataset.tooltipShortcut || tooltipShortcut(node.getAttribute('aria-keyshortcuts'));
|
|
1375
|
+
const detail = node.tooltipDetail?.() || node.dataset.tooltipDetail || '', detailShortcut = detail ? tooltipShortcut(node.dataset.tooltipDetailShortcut) : '';
|
|
1376
|
+
const note = node.tooltipNote?.() || '';
|
|
855
1377
|
const overflow = node.dataset.tooltipOverflow;
|
|
856
|
-
if (!shortcut && !detail && overflow !== undefined) {
|
|
1378
|
+
if (!shortcut && !detail && !note && overflow !== undefined) {
|
|
857
1379
|
const targets = overflow ? [...node.querySelectorAll(overflow)] : [node];
|
|
858
1380
|
if (!targets.some(target => target.scrollWidth > target.clientWidth || target.scrollHeight > target.clientHeight)) {
|
|
859
1381
|
this.dismiss(); return;
|
|
@@ -861,17 +1383,22 @@
|
|
|
861
1383
|
}
|
|
862
1384
|
if (this.label.textContent !== label) this.label.textContent = label;
|
|
863
1385
|
if (this.detail.textContent !== detail) this.detail.textContent = detail;
|
|
1386
|
+
if (this.note.textContent !== note) this.note.textContent = note;
|
|
864
1387
|
this.tip.toggleAttribute('data-annotation',node.hasAttribute('data-annotation-tooltip'));
|
|
865
1388
|
this.detail.toggleAttribute('hidden',!detail);
|
|
1389
|
+
this.note.toggleAttribute('hidden',!note);
|
|
866
1390
|
if (this.shortcut.textContent !== shortcut) this.shortcut.textContent = shortcut;
|
|
867
1391
|
this.shortcut.toggleAttribute('hidden',!shortcut);
|
|
1392
|
+
if (this.detailShortcut.textContent !== detailShortcut) this.detailShortcut.textContent = detailShortcut;
|
|
1393
|
+
this.detailShortcut.toggleAttribute('hidden',!detailShortcut);
|
|
1394
|
+
this.tip.toggleAttribute('data-detail-shortcut',Boolean(detailShortcut));
|
|
868
1395
|
if (this.tip.hidden) {
|
|
869
1396
|
const dialog = this.topLayer && node.closest('dialog[open]');
|
|
870
1397
|
if (dialog) dialog.append(this.tip);
|
|
871
1398
|
this.tip.hidden = false;
|
|
872
1399
|
if (this.topLayer) this.tip.showPopover();
|
|
873
1400
|
}
|
|
874
|
-
if (shortcut || detail || node.dataset.tooltip && label !== node.getAttribute('aria-label') && label !== node.textContent.trim()) {
|
|
1401
|
+
if (shortcut || detail || note || node.dataset.tooltip && label !== node.getAttribute('aria-label') && label !== node.textContent.trim()) {
|
|
875
1402
|
const ids = (node.getAttribute('aria-describedby') || '').split(/\s+/u).filter(Boolean);
|
|
876
1403
|
if (!ids.includes(this.tip.id)) node.setAttribute('aria-describedby',[...ids,this.tip.id].join(' '));
|
|
877
1404
|
}
|
|
@@ -879,12 +1406,14 @@
|
|
|
879
1406
|
const left = Math.max(8,Math.min(window.innerWidth-bubble.width-8,anchor.left+(anchor.width-bubble.width)/2));
|
|
880
1407
|
const above = anchor.top-bubble.height-7;
|
|
881
1408
|
const top = Math.max(8,Math.min(window.innerHeight-bubble.height-8,above >= 8 ? above : anchor.bottom+7));
|
|
1409
|
+
this.tip.toggleAttribute('data-above',top+bubble.height <= anchor.top);
|
|
882
1410
|
if (this.tip.style.left !== left+'px') this.tip.style.left = left+'px';
|
|
883
1411
|
if (this.tip.style.top !== top+'px') this.tip.style.top = top+'px';
|
|
884
1412
|
};
|
|
885
1413
|
dismiss = () => { this.focused = undefined; this.hide(); };
|
|
886
1414
|
hide() {
|
|
887
|
-
|
|
1415
|
+
this.pauseAutoHide();
|
|
1416
|
+
this.selectionGesture = undefined; this.textSelected = false;
|
|
888
1417
|
const node = this.visible;
|
|
889
1418
|
if (!node) return;
|
|
890
1419
|
if (this.topLayer && this.tip.matches(':popover-open')) this.tip.hidePopover();
|
|
@@ -894,7 +1423,62 @@
|
|
|
894
1423
|
if (ids.length) node.setAttribute('aria-describedby',ids.join(' '));
|
|
895
1424
|
else node.removeAttribute('aria-describedby');
|
|
896
1425
|
}
|
|
897
|
-
|
|
1426
|
+
showHints(source) {
|
|
1427
|
+
this.dismiss();
|
|
1428
|
+
this.hintSource = source;
|
|
1429
|
+
this.hints.hidden = false;
|
|
1430
|
+
if (this.topLayer && !this.hints.matches(':popover-open')) this.hints.showPopover();
|
|
1431
|
+
this.renderHints();
|
|
1432
|
+
}
|
|
1433
|
+
hideHints() {
|
|
1434
|
+
clearTimeout(this.holdTimer); this.holdTimer = undefined;
|
|
1435
|
+
if (this.hints.hidden) return;
|
|
1436
|
+
if (this.hintFrame !== undefined) window.cancelAnimationFrame(this.hintFrame);
|
|
1437
|
+
this.hintFrame = undefined; this.hintSource = undefined;
|
|
1438
|
+
if (this.topLayer && this.hints.matches(':popover-open')) this.hints.hidePopover();
|
|
1439
|
+
this.hints.hidden = true; this.hints.replaceChildren();
|
|
1440
|
+
if (embedded) window.parent.postMessage({type:'agentbot-workspace-shortcut-hints',visible:false},window.location.origin);
|
|
1441
|
+
}
|
|
1442
|
+
queueHints() {
|
|
1443
|
+
if (this.hints.hidden || this.hintFrame !== undefined) return;
|
|
1444
|
+
this.hintFrame = window.requestAnimationFrame(() => {
|
|
1445
|
+
this.hintFrame = undefined; this.renderHints();
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
renderHints() {
|
|
1449
|
+
const files = this.host.filesPanel, tab = files?.tabs.get(files.activeKey);
|
|
1450
|
+
if (this.hintSource && (tab?.frame?.contentWindow !== this.hintSource || files.dataset.view !== 'content')) {
|
|
1451
|
+
this.hideHints(); return;
|
|
1452
|
+
}
|
|
1453
|
+
const dialogs = window.CSS?.supports('selector(:modal)') ? [...this.host.querySelectorAll('dialog:modal')] : [];
|
|
1454
|
+
const dialog = dialogs.findLast(node => node.contains(document.activeElement)) ?? dialogs.at(-1);
|
|
1455
|
+
const width = window.innerWidth, height = window.innerHeight, placed = [];
|
|
1456
|
+
const shortcuts = [];
|
|
1457
|
+
for (const node of (dialog || this.host).querySelectorAll(buttonShortcuts)) {
|
|
1458
|
+
if (!node.matches(tooltipControls)) continue;
|
|
1459
|
+
const keys = [node.dataset.tooltipShortcut || tooltipShortcut(node.getAttribute('aria-keyshortcuts')),
|
|
1460
|
+
tooltipShortcut(node.dataset.tooltipDetailShortcut)].filter(Boolean);
|
|
1461
|
+
if (!keys.length || !node.getClientRects().length) continue;
|
|
1462
|
+
const rect = node.getBoundingClientRect(), x = rect.left+rect.width/2, y = rect.top+rect.height/2;
|
|
1463
|
+
if (x < 0 || y < 0 || x >= width || y >= height) continue;
|
|
1464
|
+
if (document.elementFromPoint && !node.contains(document.elementFromPoint(x,y))) continue;
|
|
1465
|
+
const hint = element('span',undefined,'workspace-shortcut-hint');
|
|
1466
|
+
hint.append(...keys.map(key => element('kbd',key)));
|
|
1467
|
+
shortcuts.push({hint,rect,x});
|
|
1468
|
+
}
|
|
1469
|
+
this.hints.replaceChildren(...shortcuts.map(({hint})=>hint));
|
|
1470
|
+
const measured = shortcuts.map(({hint,rect,x})=>({hint,rect,x,width:hint.offsetWidth,height:hint.offsetHeight}));
|
|
1471
|
+
for (const {hint,rect,x,width:hintWidth,height:hintHeight} of measured) {
|
|
1472
|
+
const left = Math.max(4,Math.min(width-hintWidth-4,x-hintWidth/2));
|
|
1473
|
+
const above = rect.top-hintHeight-4, below = rect.bottom+4;
|
|
1474
|
+
const fits = y => y >= 4 && y+hintHeight <= height-4 && !placed.some(box =>
|
|
1475
|
+
left < box.right && left+hintWidth > box.left && y < box.bottom && y+hintHeight > box.top);
|
|
1476
|
+
const top = fits(above) ? above : fits(below) ? below : Math.max(4,Math.min(height-hintHeight-4,below));
|
|
1477
|
+
hint.style.left = `${left}px`; hint.style.top = `${top}px`;
|
|
1478
|
+
placed.push({left,top,right:left+hintWidth,bottom:top+hintHeight});
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
disconnect() { this.dismiss(); this.hideHints(); this.changes.disconnect(); this.events.abort(); this.tip.remove(); this.hints.remove(); }
|
|
898
1482
|
}
|
|
899
1483
|
class WorkspaceTaskList extends HTMLElement {
|
|
900
1484
|
connectedCallback() {
|
|
@@ -993,7 +1577,7 @@
|
|
|
993
1577
|
const showList = mode => this.showFiles(panel => { panel.selectList(mode); panel.showList(); },true);
|
|
994
1578
|
add('files','查看项目文件','Show File Explorer',() => showList('files'));
|
|
995
1579
|
add('git-changes','查看未提交改动','View Git Changes',() => showList('changes'),true);
|
|
996
|
-
add('refresh-files','刷新文件','Refresh Files',() => files.
|
|
1580
|
+
add('refresh-files','刷新文件','Refresh Files',() => files.refreshFiles());
|
|
997
1581
|
}
|
|
998
1582
|
if (!files.locateButton.disabled) add('reveal-file','定位当前文件','Reveal Active File in Explorer',
|
|
999
1583
|
() => this.showFiles(panel => { void panel.revealCurrentFile(); },true));
|
|
@@ -1185,9 +1769,8 @@
|
|
|
1185
1769
|
this.app.navigate(() => {
|
|
1186
1770
|
this.app.selectPane('files');
|
|
1187
1771
|
const layout = this.app.layout;
|
|
1188
|
-
if (
|
|
1189
|
-
layout.
|
|
1190
|
-
if (showExplorer) layout.explorerCollapsed = false;
|
|
1772
|
+
if (showExplorer && layout.explorerCollapsed) {
|
|
1773
|
+
layout.explorerCollapsed = false;
|
|
1191
1774
|
this.app.applyLayout();
|
|
1192
1775
|
}
|
|
1193
1776
|
action(this.app.filesPanel);
|
|
@@ -1198,14 +1781,22 @@
|
|
|
1198
1781
|
connectedCallback() {
|
|
1199
1782
|
this.dataset.noProject = String(!this.fileApi && !appBase);
|
|
1200
1783
|
this.dataset.noPrimary = String(!this.fileApi);
|
|
1201
|
-
this.controllers = new Set(); this.tabs = new Map(); this.views = new Map(); this.localDirectories = new Map(); this.activeKey = undefined; this.recentTabs = [];
|
|
1784
|
+
this.controllers = new Set(); this.tabs = new Map(); this.pinnedTabs = new Set(); this.views = new Map(); this.localDirectories = new Map(); this.activeKey = undefined; this.recentTabs = [];
|
|
1785
|
+
this.chinese = /^zh(?:[-_]|$)/iu.test(navigator.language || document.documentElement.lang);
|
|
1202
1786
|
this.renderedKey = undefined;
|
|
1203
1787
|
this.dataset.view = 'list'; this.listScrollTop = 0;
|
|
1204
1788
|
this.generation = 0; this.navigationGeneration = 0; this.navigationSequence = 0; this.listMode = 'files';
|
|
1205
|
-
this.innerHTML = '<div class="file-tabs" role="tablist" aria-label="已打开文件"></div><div class="content-toolbar" hidden></div><div class="file-layout"><section class="file-main"><div class="content-body" role="region" aria-label="文件内容" tabindex="0"><div class="content-empty">从右侧文件树选择文件,或在改动列表中查看 Git 变更。</div></div></section><aside class="file-explorer" aria-label="文件浏览"><div class="file-toolbar"><div class="file-list-switch" role="group" aria-label="文件浏览方式"><button data-list="files" aria-pressed="true">文件</button><button data-list="changes" aria-pressed="false">未提交</button></div
|
|
1789
|
+
this.innerHTML = '<div class="file-tabs" role="tablist" aria-label="已打开文件"></div><div class="content-toolbar" hidden></div><div class="file-layout"><section class="file-main"><div class="content-body" role="region" aria-label="文件内容" tabindex="0"><div class="content-empty">从右侧文件树选择文件,或在改动列表中查看 Git 变更。</div></div></section><aside class="file-explorer" aria-label="文件浏览"><div class="file-toolbar"><div class="file-list-switch" role="group" aria-label="文件浏览方式"><button data-list="files" aria-pressed="true">文件</button><button data-list="changes" aria-pressed="false">未提交</button></div></div><nav class="file-navigation" aria-label="项目文件"></nav></aside></div>';
|
|
1206
1790
|
this.navigation = this.querySelector('.file-navigation'); this.tabBar = this.querySelector('.file-tabs');
|
|
1207
|
-
const strip = element('div',undefined,'file-tab-strip'); this.tabBar.before(strip);
|
|
1208
|
-
const
|
|
1791
|
+
const strip = this.tabStrip = element('div',undefined,'file-tab-strip'); this.tabBar.before(strip);
|
|
1792
|
+
const pinned = this.pinnedTabBar = element('div',undefined,'file-pinned-tabs');
|
|
1793
|
+
pinned.setAttribute('role','tablist'); pinned.setAttribute('aria-label',this.chinese?'固定的标签':'Pinned tabs');
|
|
1794
|
+
pinned.style.setProperty('--pinned-tab-width',pinnedTabWidth+'px');
|
|
1795
|
+
this.pinnedTabsMore = iconControl('button','moreTabs',this.chinese?'更多固定标签':'More pinned tabs','pinned-tabs-more');
|
|
1796
|
+
this.pinnedTabsMore.setAttribute('aria-haspopup','menu');
|
|
1797
|
+
this.pinnedTabsMore.onclick = event => this.openPinnedTabsMenu(event);
|
|
1798
|
+
pinned.append(this.pinnedTabsMore); strip.append(pinned,this.tabBar);
|
|
1799
|
+
const actions = this.tabActions = element('div',undefined,'tab-actions'), add = iconControl('button','plus','新标签','new-tab');
|
|
1209
1800
|
add.onclick = () => this.openNew(); actions.append(add); strip.append(actions);
|
|
1210
1801
|
this.explorerToggle = iconControl('button','explorer','折叠文件列表','toggle-explorer');
|
|
1211
1802
|
this.explorerToggle.onclick = () => { this.saveScroll(); this.closest('agentbot-workspace').togglePanel('explorer'); this.restoreScroll(); };
|
|
@@ -1230,13 +1821,24 @@
|
|
|
1230
1821
|
this.diffResize = () => this.updateDiffNavigation(); window.addEventListener('resize',this.diffResize);
|
|
1231
1822
|
this.caretResize = new ResizeObserver(() => this.positionPreviewCaret());
|
|
1232
1823
|
this.previewSelectionChanged = () => {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
if (
|
|
1824
|
+
const selected = this.hasPreviewSelection(), wasSelected = this.previewHasSelection;
|
|
1825
|
+
this.previewHasSelection = selected;
|
|
1826
|
+
if (selected) this.clearPreviewCaret();
|
|
1827
|
+
else if (wasSelected) {
|
|
1828
|
+
const tab = this.tabs.get(this.activeKey);
|
|
1829
|
+
if (tab?.stale) void this.refreshLivePreview(tab);
|
|
1830
|
+
}
|
|
1236
1831
|
};
|
|
1237
1832
|
document.addEventListener('selectionchange',this.previewSelectionChanged);
|
|
1833
|
+
this.content.addEventListener('pointerdown',this.beginPreviewLineSelection);
|
|
1238
1834
|
this.content.onclick = event => {
|
|
1239
1835
|
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
1836
|
+
const row = event.target.closest(codeGutter)?.closest('pre.code .line[id]');
|
|
1837
|
+
if (row && this.renderedKey === this.activeKey) {
|
|
1838
|
+
event.preventDefault();
|
|
1839
|
+
if (!this.ignorePreviewLineClick || event.detail === 0) this.highlightPreviewLine(row);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1240
1842
|
const link = event.target.closest('a');
|
|
1241
1843
|
if (!link) { this.placePreviewCaret(event); return; }
|
|
1242
1844
|
this.clearPreviewCaret();
|
|
@@ -1245,6 +1847,14 @@
|
|
|
1245
1847
|
event.preventDefault(); this.navigate(() => { const tab = this.tabs.get(this.activeKey); tab.hash = tab.requestedHash = link.getAttribute('href'); this.restoreHash(tab); });
|
|
1246
1848
|
}
|
|
1247
1849
|
};
|
|
1850
|
+
this.content.ondblclick = event => {
|
|
1851
|
+
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || this.renderedKey !== this.activeKey) return;
|
|
1852
|
+
const row = event.target.closest(codeGutter)?.closest('pre.code .line[id]');
|
|
1853
|
+
if (!row || this.ignorePreviewLineClick) return;
|
|
1854
|
+
event.preventDefault();
|
|
1855
|
+
this.selectPreviewLines(row,row);
|
|
1856
|
+
this.closest('agentbot-workspace').annotations?.selectionChanged();
|
|
1857
|
+
};
|
|
1248
1858
|
this.navigationViews = new Map([['files',this.createNavigationView(this.navigation)]]);
|
|
1249
1859
|
this.addEventListener('click',this.keepTreeRow,true);
|
|
1250
1860
|
this.addEventListener('mousedown',this.startTreeToggle,true);
|
|
@@ -1258,22 +1868,85 @@
|
|
|
1258
1868
|
filesButton.replaceChildren(icon('tree')); filesButton.classList.add('icon-control'); filesButton.dataset.tooltip = '项目文件'; filesButton.setAttribute('aria-label','项目文件');
|
|
1259
1869
|
const count = element('span',undefined,'count-badge'); count.hidden = true; count.setAttribute('aria-hidden','true');
|
|
1260
1870
|
changesButton.replaceChildren(icon('diff'),count); changesButton.classList.add('icon-control'); changesButton.dataset.tooltip = '未提交改动'; changesButton.setAttribute('aria-label','未提交改动');
|
|
1261
|
-
|
|
1262
|
-
this.
|
|
1871
|
+
this.locateButton = iconControl('button','locate','在列表中定位当前文件','locate-current-file');
|
|
1872
|
+
this.querySelector('.file-toolbar').append(this.locateButton); this.locateButton.onclick = () => this.revealCurrentFile();
|
|
1263
1873
|
this.revealMessage = element('div',undefined,'reveal-message'); this.revealMessage.hidden = true; this.revealMessage.setAttribute('role','status'); this.navigation.before(this.revealMessage);
|
|
1264
|
-
if (this.taskId && appBase && !embedded) this.createDirectoryPanel(
|
|
1874
|
+
if (this.taskId && appBase && !embedded) this.createDirectoryPanel();
|
|
1265
1875
|
for (const button of this.querySelectorAll('[data-list]')) {
|
|
1266
1876
|
button.onclick = () => this.selectList(button.dataset.list);
|
|
1267
1877
|
}
|
|
1268
|
-
this.querySelector('.refresh').onclick = () => {
|
|
1269
|
-
this.saveScroll(); this.loadNavigation(this.listMode,true); const tab = this.tabs.get(this.activeKey); if (tab) this.loadTab(tab,true);
|
|
1270
|
-
};
|
|
1271
1878
|
this.renderTabs();
|
|
1272
1879
|
if (!this.fileApi) {
|
|
1273
1880
|
this.content.replaceChildren(element('div','此任务没有主项目目录。','content-empty'));
|
|
1274
1881
|
this.notice(this.navigation,'在新标签中输入路径或选择任务目录。');
|
|
1275
1882
|
}
|
|
1276
1883
|
}
|
|
1884
|
+
hasPreviewSelection() {
|
|
1885
|
+
const selection = window.getSelection?.();
|
|
1886
|
+
return Boolean(selection?.rangeCount && !selection.isCollapsed && this.content.contains(selection.getRangeAt(0).commonAncestorContainer));
|
|
1887
|
+
}
|
|
1888
|
+
highlightPreviewLine(row) {
|
|
1889
|
+
this.clearPreviewCaret();
|
|
1890
|
+
this.navigate(() => {
|
|
1891
|
+
const tab = this.tabs.get(this.activeKey);
|
|
1892
|
+
if (!tab) return;
|
|
1893
|
+
tab.hash = '#'+row.id; tab.requestedHash = undefined;
|
|
1894
|
+
this.restoreHash(tab);
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
beginPreviewLineSelection = event => {
|
|
1898
|
+
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
1899
|
+
this.ignorePreviewLineClick = false;
|
|
1900
|
+
const gutter = event.target.closest(codeGutter), row = gutter?.closest('pre.code .line[id]');
|
|
1901
|
+
if (!row || this.renderedKey !== this.activeKey || this.previewLineDrag) return;
|
|
1902
|
+
event.preventDefault();
|
|
1903
|
+
this.clearPreviewCaret();
|
|
1904
|
+
this.content.focus({preventScroll:true});
|
|
1905
|
+
window.getSelection()?.removeAllRanges();
|
|
1906
|
+
const controller = new AbortController(), {signal} = controller;
|
|
1907
|
+
const drag = this.previewLineDrag = {row,preview:row.closest('pre.code'),x:event.clientX,y:event.clientY,startY:event.clientY,controller,id:event.pointerId};
|
|
1908
|
+
window.addEventListener('pointermove',event => {
|
|
1909
|
+
if (event.pointerId !== drag.id) return;
|
|
1910
|
+
drag.y = event.clientY;
|
|
1911
|
+
if (!this.ignorePreviewLineClick && Math.abs(drag.y-drag.startY) < 3) return;
|
|
1912
|
+
this.ignorePreviewLineClick = true;
|
|
1913
|
+
this.extendPreviewLineSelection(drag);
|
|
1914
|
+
},{signal});
|
|
1915
|
+
const finish = event => { if (event.pointerId === drag.id) this.endPreviewLineSelection(); };
|
|
1916
|
+
window.addEventListener('pointerup',finish,{signal});
|
|
1917
|
+
window.addEventListener('pointercancel',finish,{signal});
|
|
1918
|
+
window.addEventListener('blur',this.endPreviewLineSelection,{signal});
|
|
1919
|
+
gutter.setPointerCapture?.(event.pointerId);
|
|
1920
|
+
};
|
|
1921
|
+
extendPreviewLineSelection(drag) {
|
|
1922
|
+
if (!drag.row.isConnected || this.renderedKey !== this.activeKey) { this.endPreviewLineSelection(); return; }
|
|
1923
|
+
const bounds = this.content.getBoundingClientRect(), top = bounds.top+this.content.clientTop;
|
|
1924
|
+
const bottom = top+this.content.clientHeight, y = Math.max(top+1,Math.min(bottom-1,drag.y));
|
|
1925
|
+
const left = bounds.left+this.content.clientLeft, x = Math.max(left+1,Math.min(left+this.content.clientWidth-1,drag.x));
|
|
1926
|
+
const scroll = this.content.scrollTop;
|
|
1927
|
+
const edge = Math.min(20,this.content.clientHeight/4);
|
|
1928
|
+
const distance = drag.y < top+edge ? drag.y-top-edge : Math.max(0,drag.y-bottom+edge);
|
|
1929
|
+
if (distance) this.content.scrollTop += Math.max(-18,Math.min(18,distance/2));
|
|
1930
|
+
const row = document.elementFromPoint(x,y)?.closest('pre.code .line[id]');
|
|
1931
|
+
if (row && row.closest('pre.code') === drag.preview && row !== drag.current) {
|
|
1932
|
+
drag.current = row; this.selectPreviewLines(drag.row,row);
|
|
1933
|
+
}
|
|
1934
|
+
if (scroll !== this.content.scrollTop && drag.frame === undefined) drag.frame = window.requestAnimationFrame(() => {
|
|
1935
|
+
drag.frame = undefined; this.extendPreviewLineSelection(drag);
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
endPreviewLineSelection = () => {
|
|
1939
|
+
const drag = this.previewLineDrag;
|
|
1940
|
+
if (!drag) return;
|
|
1941
|
+
this.previewLineDrag = undefined; drag.controller.abort();
|
|
1942
|
+
if (drag.frame !== undefined) window.cancelAnimationFrame(drag.frame);
|
|
1943
|
+
};
|
|
1944
|
+
selectPreviewLines(anchor,focus) {
|
|
1945
|
+
const first = anchor.querySelector(codeText), last = focus.querySelector(codeText), selection = window.getSelection();
|
|
1946
|
+
if (!first || !last || !selection) return;
|
|
1947
|
+
const backward = Boolean(anchor.compareDocumentPosition(focus) & window.Node.DOCUMENT_POSITION_PRECEDING);
|
|
1948
|
+
selection.setBaseAndExtent(first,backward ? first.childNodes.length : 0,last,backward ? 0 : last.childNodes.length);
|
|
1949
|
+
}
|
|
1277
1950
|
placePreviewCaret(event) {
|
|
1278
1951
|
this.clearPreviewCaret();
|
|
1279
1952
|
const selection = window.getSelection();
|
|
@@ -1345,7 +2018,7 @@
|
|
|
1345
2018
|
const entries = Array.isArray(history) ? history : [...this.recentTabs].reverse().map(key => this.tabs.get(key));
|
|
1346
2019
|
const valid = [];
|
|
1347
2020
|
for (const item of entries.slice(0,commandPaletteFileLimit)) {
|
|
1348
|
-
if (!item || !['file','diff'].includes(item.kind) || (item.source && (!previewSource(item.kind,item.source) || !this.previewRoot(item.source)))
|
|
2021
|
+
if (!item || item.mode === 'recorded' || !['file','diff'].includes(item.kind) || (item.source && (!previewSource(item.kind,item.source) || !this.previewRoot(item.source)))
|
|
1349
2022
|
|| !this.previewApi(item.source)) continue;
|
|
1350
2023
|
try {
|
|
1351
2024
|
valid.push({path:relativePath(item.path),kind:item.kind,source:item.source,original:item.original === undefined?undefined:relativePath(item.original)});
|
|
@@ -1361,7 +2034,7 @@
|
|
|
1361
2034
|
}
|
|
1362
2035
|
get treeApi() { return this.previewApi(this.explorerDirectory); }
|
|
1363
2036
|
get treeRoot() { return this.directoryPanel?.tabs.find(tab => tab.id === this.explorerDirectory)?.path || this.projectRoot; }
|
|
1364
|
-
createDirectoryPanel(
|
|
2037
|
+
createDirectoryPanel() {
|
|
1365
2038
|
this.directoryStrip = element('div',undefined,'explorer-directory-tabs');
|
|
1366
2039
|
const strip = this.directoryStrip;
|
|
1367
2040
|
strip.hidden = true; strip.setAttribute('role','group'); strip.setAttribute('aria-label','目录标签');
|
|
@@ -1373,8 +2046,7 @@
|
|
|
1373
2046
|
},{passive:false});
|
|
1374
2047
|
this.addDirectory = iconControl('button','plus','添加目录','add-explorer-directory');
|
|
1375
2048
|
this.addDirectory.hidden = true; this.addDirectory.onclick = () => this.showDirectoryChooser(true,true);
|
|
1376
|
-
|
|
1377
|
-
this.addDirectory.after(this.locateButton);
|
|
2049
|
+
this.locateButton.before(this.directoryStrip,this.addDirectory);
|
|
1378
2050
|
this.directoryChooser = element('section',undefined,'explorer-directory-chooser');
|
|
1379
2051
|
this.directoryChooser.hidden = true; this.directoryChooser.setAttribute('aria-label','选择目录');
|
|
1380
2052
|
const form = element('form',undefined,'explorer-directory-form');
|
|
@@ -1415,6 +2087,7 @@
|
|
|
1415
2087
|
const appendTab = (directory, selected, action, close) => {
|
|
1416
2088
|
const row = element('div',undefined,'explorer-directory-tab');
|
|
1417
2089
|
const button = element('button',directory.name); button.type = 'button';
|
|
2090
|
+
if (directory.path) button.dataset.referenceDirectory = directory.path;
|
|
1418
2091
|
if (directory.path && directory.path !== directory.name) button.dataset.tooltip = directory.path;
|
|
1419
2092
|
button.setAttribute('aria-pressed',String(selected)); button.disabled = Boolean(this.directoryPending); button.onclick = action;
|
|
1420
2093
|
row.append(button);
|
|
@@ -1444,6 +2117,7 @@
|
|
|
1444
2117
|
for (const directory of choices.values()) {
|
|
1445
2118
|
if (!directory.path || projectPath(directory.path,this.projectRoot) === projectPath(this.projectRoot,this.projectRoot)) continue;
|
|
1446
2119
|
const button = element('button',undefined,'launch-directory'); button.type = 'button';
|
|
2120
|
+
button.dataset.referenceDirectory = directory.path;
|
|
1447
2121
|
button.dataset.tooltip = directory.path; button.dataset.tooltipOverflow = '.launch-directory-path';
|
|
1448
2122
|
const label = element('span',undefined,'launch-directory-label');
|
|
1449
2123
|
label.append(element('strong',directory.name),element('span',directory.path,'launch-directory-path'));
|
|
@@ -1520,6 +2194,7 @@
|
|
|
1520
2194
|
}
|
|
1521
2195
|
disconnectedCallback() {
|
|
1522
2196
|
document.removeEventListener('selectionchange',this.previewSelectionChanged);
|
|
2197
|
+
this.endPreviewLineSelection();
|
|
1523
2198
|
this.clearPreviewCaret();
|
|
1524
2199
|
this.removeEventListener('click',this.keepTreeRow,true);
|
|
1525
2200
|
this.removeEventListener('mousedown',this.startTreeToggle,true);
|
|
@@ -1530,7 +2205,7 @@
|
|
|
1530
2205
|
for (const controller of this.controllers) controller.abort();
|
|
1531
2206
|
this.controllers.clear();
|
|
1532
2207
|
for (const view of this.navigationViews.values()) for (const observer of view.observers) observer.disconnect();
|
|
1533
|
-
this.tabs.clear(); this.views.clear();
|
|
2208
|
+
this.tabs.clear(); this.pinnedTabs.clear(); this.views.clear();
|
|
1534
2209
|
clearTimeout(this.searchTimer); this.searchController?.abort();
|
|
1535
2210
|
clearTimeout(this.syncTimer); clearTimeout(this.warmTimer);
|
|
1536
2211
|
}
|
|
@@ -1721,6 +2396,7 @@
|
|
|
1721
2396
|
createFileButton(item, mode) {
|
|
1722
2397
|
const changed = mode === 'changes', button = element('button',undefined,changed?'change-file':'tree-file');
|
|
1723
2398
|
button.dataset.filePath = item.path;
|
|
2399
|
+
if (item.originalPath) button.dataset.originalPath = item.originalPath;
|
|
1724
2400
|
button.append(fileIcon(item.path),element('span',item.name,changed?'change-name':undefined));
|
|
1725
2401
|
const title = item.originalPath ? item.originalPath+' → '+item.path : item.path;
|
|
1726
2402
|
button.dataset.tooltip = item.error || title; button.disabled = item.blocked;
|
|
@@ -1739,7 +2415,7 @@
|
|
|
1739
2415
|
}
|
|
1740
2416
|
updateCurrentFile() {
|
|
1741
2417
|
const tab = this.tabs.get(this.activeKey);
|
|
1742
|
-
const hasFile = tab && ['file','diff'].includes(tab.kind);
|
|
2418
|
+
const hasFile = tab && ['file','diff'].includes(tab.kind) && !absoluteFilePath(tab.path);
|
|
1743
2419
|
const path = hasFile && tab.source === (this.explorerDirectory || undefined) ? tab.path : undefined;
|
|
1744
2420
|
const currentPath = this.pathKey(path);
|
|
1745
2421
|
this.locateButton.disabled = !hasFile || this.revealing || (!path && !this.previewRoot(tab.source));
|
|
@@ -1756,7 +2432,7 @@
|
|
|
1756
2432
|
}
|
|
1757
2433
|
async revealCurrentFile(keepView = false, replacePending = false, switchDirectory = !keepView) {
|
|
1758
2434
|
const tab = this.tabs.get(this.activeKey);
|
|
1759
|
-
if ((this.revealing && !replacePending) || !tab || !['file','diff'].includes(tab.kind)) return;
|
|
2435
|
+
if ((this.revealing && !replacePending) || !tab || absoluteFilePath(tab.path) || !['file','diff'].includes(tab.kind)) return;
|
|
1760
2436
|
if (tab.source !== (this.explorerDirectory || undefined)) {
|
|
1761
2437
|
if (!switchDirectory || !this.directoryPanel || !this.previewRoot(tab.source)) return;
|
|
1762
2438
|
const open = tab.source && !this.directoryPanel.tabs.some(directory => directory.id === tab.source);
|
|
@@ -1764,7 +2440,7 @@
|
|
|
1764
2440
|
if (!selected || this.hidden || this.tabs.get(this.activeKey) !== tab) return;
|
|
1765
2441
|
if (keepView) this.navigate(() => this.prepareAddressFile(),true);
|
|
1766
2442
|
}
|
|
1767
|
-
const mode = keepView?this.listMode:tab.kind === 'diff' ? 'changes' : 'files';
|
|
2443
|
+
const mode = keepView?this.listMode:tab.kind === 'diff' && tab.mode !== 'recorded' ? 'changes' : 'files';
|
|
1768
2444
|
if (keepView && this.navigationView(mode).query) { this.pendingFilterTarget = {key:tab.key,mode,path:tab.path,query:this.navigationView(mode).query}; this.revealFilteredFile(); return; }
|
|
1769
2445
|
const reveal = this.revealing = {}; this.revealMessage.hidden = true; this.locateButton.setAttribute('aria-busy','true'); this.updateCurrentFile();
|
|
1770
2446
|
if (!keepView) this.navigate(() => {
|
|
@@ -1904,6 +2580,12 @@
|
|
|
1904
2580
|
}
|
|
1905
2581
|
}
|
|
1906
2582
|
}
|
|
2583
|
+
refreshFiles() {
|
|
2584
|
+
this.saveScroll();
|
|
2585
|
+
void this.loadNavigation(this.listMode,true);
|
|
2586
|
+
const tab = this.tabs.get(this.activeKey);
|
|
2587
|
+
if (tab) void this.loadTab(tab,true);
|
|
2588
|
+
}
|
|
1907
2589
|
async loadNavigation(mode = this.listMode, refresh = false) {
|
|
1908
2590
|
const view = this.navigationView(mode);
|
|
1909
2591
|
if (refresh && view.ready) { await this.refreshTree(mode,{reset:true},true); return; }
|
|
@@ -2233,24 +2915,30 @@
|
|
|
2233
2915
|
return entry === key || entry.startsWith(key+'/');
|
|
2234
2916
|
});
|
|
2235
2917
|
const revision = {};
|
|
2236
|
-
for (const views of this.views.values()) for (const tab of views.values())
|
|
2918
|
+
for (const views of this.views.values()) for (const tab of views.values()) {
|
|
2919
|
+
if (tab.mode === 'recorded' || !['file','diff'].includes(tab.kind) || tab.source !== (this.explorerDirectory || undefined) || !matches(tab)) continue;
|
|
2920
|
+
tab.stale = revision;
|
|
2921
|
+
tab.filePreviews?.clear();
|
|
2922
|
+
}
|
|
2237
2923
|
const tab = this.tabs.get(this.activeKey);
|
|
2238
2924
|
if (tab?.stale) void this.refreshLivePreview(tab);
|
|
2239
2925
|
}
|
|
2240
2926
|
async refreshLivePreview(tab) {
|
|
2241
|
-
const visible = () => this.isConnected && !this.hidden && !document.hidden && this.content.clientHeight > 0
|
|
2242
|
-
|
|
2927
|
+
const visible = () => this.isConnected && !this.hidden && !document.hidden && this.content.clientHeight > 0
|
|
2928
|
+
&& !this.previewLineDrag && !this.hasPreviewSelection();
|
|
2929
|
+
if (tab.mode === 'recorded' || !visible() || !tab.preview || this.loadingTab || this.livePreview || this.toolbar.contains(document.activeElement)) return;
|
|
2243
2930
|
const generation = this.generation, revision = tab.stale, preview = tab.preview;
|
|
2244
2931
|
this.livePreview = true;
|
|
2245
2932
|
const current = () => visible() && generation === this.generation && tab.stale === revision && this.tabs.get(this.activeKey) === tab;
|
|
2246
2933
|
const hint = this.toolbar.querySelector('.launch-hint');
|
|
2247
2934
|
try {
|
|
2248
2935
|
let etag;
|
|
2249
|
-
const data = await this.request(tab.kind,{entry:tab.path,mode:tab.mode,original:tab.original},undefined,
|
|
2936
|
+
const data = await this.request(tab.kind,{entry:tab.path,mode:tab.mode,original:tab.original,source:tab.sourceView?'1':undefined},undefined,
|
|
2250
2937
|
{etag:preview.etag,data:preview}, value => { etag = value; },this.previewApi(tab.source));
|
|
2251
2938
|
if (!current() || this.toolbar.contains(document.activeElement)) return;
|
|
2252
2939
|
if (data.html === preview.html && JSON.stringify(data.change) === JSON.stringify(preview.change)
|
|
2253
|
-
&& data.gitError === preview.gitError && data.canViewFile === preview.canViewFile
|
|
2940
|
+
&& data.gitError === preview.gitError && data.canViewFile === preview.canViewFile
|
|
2941
|
+
&& (data.canTogglePreview === true) === preview.canTogglePreview) {
|
|
2254
2942
|
preview.etag = etag; tab.stale = undefined;
|
|
2255
2943
|
if (hint) { hint.textContent = data.gitError ? '读取 Git 状态失败:'+data.gitError : ''; hint.hidden = !data.gitError; }
|
|
2256
2944
|
} else { this.saveScroll(); await this.loadTab(tab,true,{...data,etag}); }
|
|
@@ -2263,14 +2951,14 @@
|
|
|
2263
2951
|
}
|
|
2264
2952
|
}
|
|
2265
2953
|
activateTab(key) {
|
|
2266
|
-
if (key !== this.activeKey) this.clearPreviewCaret();
|
|
2954
|
+
if (key !== this.activeKey) { this.endPreviewLineSelection(); this.clearPreviewCaret(); }
|
|
2267
2955
|
this.activeKey = key; this.recentTabs = this.recentTabs.filter(current => current !== key && this.tabs.has(current));
|
|
2268
2956
|
if (key) this.recentTabs.push(key);
|
|
2269
2957
|
}
|
|
2270
|
-
tabView(key, path, kind, original, source) {
|
|
2958
|
+
tabView(key, path, kind, original, source, patch) {
|
|
2271
2959
|
let views = this.views.get(key); if (!views) { views = new Map(); this.views.set(key,views); }
|
|
2272
2960
|
const viewKey = previewKey(kind,path,source); let tab = views.get(viewKey);
|
|
2273
|
-
if (!tab) { tab = {key,path,kind,original,source,mode:'all',scrollTop:0,scrollLeft:0}; views.set(viewKey,tab); }
|
|
2961
|
+
if (!tab) { tab = {key,path,kind,original,source,patch,mode:patch?'recorded':'all',scrollTop:0,scrollLeft:0}; views.set(viewKey,tab); }
|
|
2274
2962
|
return tab;
|
|
2275
2963
|
}
|
|
2276
2964
|
showTab(tab) {
|
|
@@ -2278,16 +2966,43 @@
|
|
|
2278
2966
|
this.tabs.set(tab.key,tab); this.activateTab(tab.key); this.dataset.view = 'content';
|
|
2279
2967
|
this.renderTabs(); this.restoreScroll(); this.loadTab(tab);
|
|
2280
2968
|
}
|
|
2281
|
-
closeViews(key) {
|
|
2282
|
-
|
|
2969
|
+
closeViews(key) {
|
|
2970
|
+
for (const tab of this.views.get(key)?.values() || []) { tab.titleController?.abort(); tab.frame?.remove(); tab.frame = tab.preview = undefined; }
|
|
2971
|
+
this.views.delete(key); this.pinnedTabs.delete(key);
|
|
2972
|
+
}
|
|
2973
|
+
setDiffMode(tab,mode,patch = tab.patch) {
|
|
2974
|
+
tab.mode = mode; tab.patch = patch;
|
|
2975
|
+
tab.preview = tab.stale = tab.hash = tab.requestedHash = undefined;
|
|
2976
|
+
[tab.scrollTop,tab.scrollLeft] = tab.diffScroll?.get(diffScrollKey(tab)) ?? [0,0];
|
|
2977
|
+
this.renderedKey = undefined;
|
|
2978
|
+
}
|
|
2979
|
+
toggleFileView(tab) {
|
|
2980
|
+
this.navigate(() => {
|
|
2981
|
+
this.saveScroll();
|
|
2982
|
+
tab.sourceView = tab.sourceView ? undefined : true;
|
|
2983
|
+
[tab.scrollTop,tab.scrollLeft] = tab.fileScroll?.get(Boolean(tab.sourceView)) ?? [0,0];
|
|
2984
|
+
tab.requestedHash = tab.hash;
|
|
2985
|
+
this.renderedKey = undefined;
|
|
2986
|
+
this.loadTab(tab);
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
openFile(path, kind, original, hash, replaceKey, source, patch) {
|
|
2283
2990
|
this.navigate(() => {
|
|
2284
2991
|
this.saveScroll(); this.dataset.view = 'content';
|
|
2285
2992
|
const root = this.previewRoot(source);
|
|
2286
2993
|
let tab = [...this.tabs.values()].find(tab => tab.kind === kind && tab.source === source && projectPath(tab.path,root) === projectPath(path,root));
|
|
2287
|
-
if (tab && ['file','diff','directory'].includes(kind)) {
|
|
2994
|
+
if (tab && ['file','diff','directory'].includes(kind)) {
|
|
2995
|
+
if (original !== undefined && (!patch || tab.original === undefined)) tab.original = original;
|
|
2996
|
+
if (patch) {
|
|
2997
|
+
if (tab.patch !== patch || tab.mode !== 'recorded') this.setDiffMode(tab,'recorded',patch);
|
|
2998
|
+
else tab.preview = undefined;
|
|
2999
|
+
}
|
|
3000
|
+
if (hash) tab.hash = tab.requestedHash = hash;
|
|
3001
|
+
this.showTab(tab); this.revealActiveTab(); return;
|
|
3002
|
+
}
|
|
2288
3003
|
const replace = replaceKey === this.activeKey && this.tabs.get(replaceKey)?.kind === 'new';
|
|
2289
3004
|
if (!tab || replace) {
|
|
2290
|
-
tab ??= this.tabView(replace?replaceKey:kind==='new'?path:instanceId(),path,kind,original,source);
|
|
3005
|
+
tab ??= this.tabView(replace?replaceKey:kind==='new'?path:instanceId(),path,kind,original,source,patch);
|
|
2291
3006
|
const key = tab.key;
|
|
2292
3007
|
const tabs = new Map();
|
|
2293
3008
|
for (const [currentKey,current] of this.tabs) {
|
|
@@ -2416,13 +3131,24 @@
|
|
|
2416
3131
|
hideAddressSuggestions(picker = this.addressPicker) {
|
|
2417
3132
|
if (!picker) return;
|
|
2418
3133
|
picker.sequence++; clearTimeout(picker.timer); picker.controller?.abort(); picker.items = []; picker.index = -1;
|
|
2419
|
-
picker.list.hidden = true;
|
|
3134
|
+
picker.list.hidden = true;
|
|
3135
|
+
for (const control of [picker.input,picker.breadcrumbs]) if (control) {
|
|
3136
|
+
control.setAttribute('aria-expanded','false'); control.removeAttribute('aria-activedescendant'); control.removeAttribute('aria-busy');
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
dismissAddress(picker) {
|
|
3140
|
+
this.hideAddressSuggestions(picker);
|
|
3141
|
+
if (!picker.fileAddress) return;
|
|
3142
|
+
picker.lookupController?.abort(); picker.submission = (picker.submission || 0)+1;
|
|
3143
|
+
picker.browse = undefined; picker.editing = false; picker.tab.draft = undefined;
|
|
3144
|
+
if (this.addressPicker === picker && this.tabs.get(picker.key) === picker.tab) this.updateAddress();
|
|
2420
3145
|
}
|
|
2421
3146
|
setAddressPickerVisible(visible) {
|
|
2422
3147
|
const picker = this.addressPicker; if (!picker) return;
|
|
2423
3148
|
if (visible) document.addEventListener('pointerdown',picker.outside,true);
|
|
2424
3149
|
else {
|
|
2425
|
-
this.
|
|
3150
|
+
this.dismissAddress(picker);
|
|
3151
|
+
if (!picker.fileAddress) { picker.submission = (picker.submission || 0)+1; picker.lookupController?.abort(); }
|
|
2426
3152
|
document.removeEventListener('pointerdown',picker.outside,true);
|
|
2427
3153
|
}
|
|
2428
3154
|
}
|
|
@@ -2431,8 +3157,30 @@
|
|
|
2431
3157
|
picker.index = index;
|
|
2432
3158
|
const options = [...picker.list.querySelectorAll('[role=option]')];
|
|
2433
3159
|
for (const [position,option] of options.entries()) option.setAttribute('aria-selected',String(position === index));
|
|
2434
|
-
|
|
2435
|
-
|
|
3160
|
+
const control = picker.browse ? picker.breadcrumbs : picker.input;
|
|
3161
|
+
if (options[index]) { control.setAttribute('aria-activedescendant',options[index].id); options[index].scrollIntoView({block:'nearest'}); }
|
|
3162
|
+
else control.removeAttribute('aria-activedescendant');
|
|
3163
|
+
}
|
|
3164
|
+
moveAddressOption(picker,direction) {
|
|
3165
|
+
const count = picker.items.length;
|
|
3166
|
+
if (count) this.selectAddressOption(picker,picker.index < 0 ? direction > 0?0:count-1 : (picker.index+direction+count)%count);
|
|
3167
|
+
}
|
|
3168
|
+
showAddressOptions(picker,items,message,choose,labels = {}) {
|
|
3169
|
+
const control = picker.browse ? picker.breadcrumbs : picker.input;
|
|
3170
|
+
picker.items = items; picker.choose = choose; picker.index = -1;
|
|
3171
|
+
picker.list.replaceChildren(); picker.list.hidden = false; control.setAttribute('aria-expanded','true'); control.removeAttribute('aria-busy');
|
|
3172
|
+
control.removeAttribute('aria-activedescendant');
|
|
3173
|
+
for (const [index,item] of items.entries()) {
|
|
3174
|
+
const option = element('button',undefined,'address-option'); option.type = 'button'; option.tabIndex = -1; option.id = picker.list.id+'-'+index;
|
|
3175
|
+
option.setAttribute('role','option'); option.setAttribute('aria-selected','false');
|
|
3176
|
+
if (item.path) { option.dataset.tooltip = item.path; option.dataset.tooltipOverflow = ':scope > span'; }
|
|
3177
|
+
if (item.path === labels.current && item.path !== undefined) option.setAttribute('aria-current','true');
|
|
3178
|
+
option.append(item.directory ? icon('folder') : item.more ? icon('down') : fileIcon(item.path),element('span',labels.short ? item.name : item.path));
|
|
3179
|
+
option.onpointerdown = event => { if (event.button === 0) event.preventDefault(); };
|
|
3180
|
+
option.onclick = () => { if (option.isConnected && !picker.list.hidden) choose(item); };
|
|
3181
|
+
picker.list.append(option);
|
|
3182
|
+
}
|
|
3183
|
+
if (message) { const status = element('div',message,'address-options-status'+(labels.error?' error':'')); status.setAttribute('role','status'); picker.list.append(status); }
|
|
2436
3184
|
}
|
|
2437
3185
|
async suggestAddress(picker, direction) {
|
|
2438
3186
|
this.hideAddressSuggestions(picker); const value = picker.input.value, input = value.trim();
|
|
@@ -2444,16 +3192,7 @@
|
|
|
2444
3192
|
picker.value = value;
|
|
2445
3193
|
const show = (items, message, error = false) => {
|
|
2446
3194
|
if (!active()) return;
|
|
2447
|
-
picker
|
|
2448
|
-
for (const [index,item] of items.entries()) {
|
|
2449
|
-
const option = element('button',undefined,'address-option'); option.type = 'button'; option.tabIndex = -1; option.id = picker.list.id+'-'+index;
|
|
2450
|
-
option.setAttribute('role','option'); option.setAttribute('aria-selected','false'); option.dataset.tooltip = item.path;
|
|
2451
|
-
option.dataset.tooltipOverflow = ':scope > span'; option.append(fileIcon(item.path),element('span',item.path));
|
|
2452
|
-
option.onpointerdown = event => { if (event.button === 0) event.preventDefault(); };
|
|
2453
|
-
option.onclick = () => { if (active() && option.isConnected && !picker.list.hidden) this.openAddress(value,picker.hint,picker.key,item.path); };
|
|
2454
|
-
picker.list.append(option);
|
|
2455
|
-
}
|
|
2456
|
-
if (message) { const status = element('div',message,'address-options-status'+(error?' error':'')); status.setAttribute('role','status'); picker.list.append(status); }
|
|
3195
|
+
this.showAddressOptions(picker,items,message,item => { if (active()) this.openAddress(value,picker.hint,picker.key,item.path); },{error});
|
|
2457
3196
|
if (direction && items.length) this.selectAddressOption(picker,direction > 0?0:items.length-1);
|
|
2458
3197
|
};
|
|
2459
3198
|
if (query.length > 160) { show([],'路径较长,请输入完整路径后按回车。'); return; }
|
|
@@ -2473,8 +3212,82 @@
|
|
|
2473
3212
|
} catch (error) { if (active()) show([],'读取匹配文件失败:'+error.message,true); }
|
|
2474
3213
|
},180);
|
|
2475
3214
|
}
|
|
3215
|
+
browseAddress(picker,entry,path,current) {
|
|
3216
|
+
this.hideAddressSuggestions(picker);
|
|
3217
|
+
const source = picker.tab.source;
|
|
3218
|
+
picker.browse = {entry,path,current,source,items:[],page:0};
|
|
3219
|
+
this.updateAddress();
|
|
3220
|
+
picker.breadcrumbs.focus({preventScroll:true});
|
|
3221
|
+
this.showAddressOptions(picker,[],'正在读取目录…');
|
|
3222
|
+
void this.loadAddressDirectory(picker);
|
|
3223
|
+
}
|
|
3224
|
+
async loadAddressDirectory(picker) {
|
|
3225
|
+
const browse = picker.browse;
|
|
3226
|
+
if (browse.loading) return;
|
|
3227
|
+
const api = this.previewApi(browse.source), active = () => this.addressPicker === picker && picker.input.isConnected
|
|
3228
|
+
&& this.tabs.get(this.activeKey) === picker.tab && picker.browse === browse;
|
|
3229
|
+
const choose = item => {
|
|
3230
|
+
if (!active()) return;
|
|
3231
|
+
if (item.more) { void this.loadAddressDirectory(picker); return; }
|
|
3232
|
+
if (item.directory) { this.browseAddress(picker,item.path,item.path); return; }
|
|
3233
|
+
this.dismissAddress(picker);
|
|
3234
|
+
this.navigateAddress(item.path,'file',picker.key,undefined,browse.source);
|
|
3235
|
+
};
|
|
3236
|
+
const show = (more,message,error) => this.showAddressOptions(picker,
|
|
3237
|
+
more ? [...browse.items,{more:true,name:'加载更多'}] : browse.items,
|
|
3238
|
+
message,choose,{short:true,current:browse.current,error});
|
|
3239
|
+
browse.loading = true;
|
|
3240
|
+
picker.controller = new AbortController(); picker.breadcrumbs.setAttribute('aria-busy','true');
|
|
3241
|
+
try {
|
|
3242
|
+
const data = await this.request('tree',{entry:browse.entry,page:browse.page},picker.controller,undefined,undefined,api);
|
|
3243
|
+
if (!active()) return;
|
|
3244
|
+
const scroll = picker.list.scrollTop, count = browse.items.length;
|
|
3245
|
+
browse.items.push(...data.entries.filter(item => !item.blocked));
|
|
3246
|
+
const more = ++browse.page < data.totalPages;
|
|
3247
|
+
show(more,browse.items.length || more ? '' : '此目录没有可打开的文件或目录。');
|
|
3248
|
+
if (browse.page > 1) {
|
|
3249
|
+
picker.list.scrollTop = scroll;
|
|
3250
|
+
if (browse.items.length > count) this.selectAddressOption(picker,count);
|
|
3251
|
+
}
|
|
3252
|
+
} catch (error) {
|
|
3253
|
+
if (active()) show(true,'读取目录失败:'+error.message,true);
|
|
3254
|
+
} finally { browse.loading = false; }
|
|
3255
|
+
}
|
|
3256
|
+
editAddress(picker) {
|
|
3257
|
+
if (this.addressPicker !== picker || !picker.input.isConnected) return;
|
|
3258
|
+
this.hideAddressSuggestions(picker);
|
|
3259
|
+
picker.browse = undefined; picker.editing = true;
|
|
3260
|
+
picker.input.hidden = false;
|
|
3261
|
+
picker.input.focus({preventScroll:true});
|
|
3262
|
+
this.updateAddress();
|
|
3263
|
+
picker.input.select();
|
|
3264
|
+
}
|
|
3265
|
+
renderAddressPath(picker,tab,suffix) {
|
|
3266
|
+
const breadcrumbs = picker.breadcrumbs;
|
|
3267
|
+
breadcrumbs.hidden = picker.editing; picker.input.hidden = !picker.editing;
|
|
3268
|
+
if (picker.editing) return;
|
|
3269
|
+
const directory = picker.browse?.path, path = directory ?? tab.path;
|
|
3270
|
+
if (directory) suffix = '/';
|
|
3271
|
+
if (breadcrumbs.dataset.path === path && breadcrumbs.dataset.suffix === suffix) return;
|
|
3272
|
+
breadcrumbs.dataset.path = path; breadcrumbs.dataset.suffix = suffix;
|
|
3273
|
+
const segments = path.split(/[\\/]/u);
|
|
3274
|
+
breadcrumbs.replaceChildren();
|
|
3275
|
+
for (const [index,segment] of segments.entries()) {
|
|
3276
|
+
if (index) breadcrumbs.append(element('span','/','address-path-divider'));
|
|
3277
|
+
const last = index === segments.length-1, current = segments.slice(0,index+1).join('/');
|
|
3278
|
+
const crumb = element('button',segment+(last ? suffix : ''),'address-path-segment');
|
|
3279
|
+
crumb.type = 'button'; crumb.setAttribute('aria-haspopup','listbox'); crumb.setAttribute('aria-controls',picker.list.id);
|
|
3280
|
+
crumb.dataset.tooltip = current; crumb.dataset.tooltipOverflow = '';
|
|
3281
|
+
crumb.onclick = event => {
|
|
3282
|
+
if (event.detail && addressPathSelection(breadcrumbs)) return;
|
|
3283
|
+
if (crumb.isConnected && this.addressPicker === picker) this.browseAddress(picker,segments.slice(0,index).join('/'),picker.browse?.path,current);
|
|
3284
|
+
};
|
|
3285
|
+
breadcrumbs.append(crumb);
|
|
3286
|
+
}
|
|
3287
|
+
breadcrumbs.scrollLeft = breadcrumbs.scrollWidth;
|
|
3288
|
+
}
|
|
2476
3289
|
directory(id) { return isLocalDirectory(id) ? this.localDirectories.get(id) : this.taskDirectories?.find(item => item.id === id); }
|
|
2477
|
-
tabTitle(tab) { return tab.kind === 'directory'?this.directory(tab.path)?.name || '任务目录':tab.kind === 'new'?'新标签':tab.kind === 'terminal'?'Terminal':tab.kind === 'web'?tab.pageTitle || tab.path:tab.path.split(
|
|
3290
|
+
tabTitle(tab) { return tab.kind === 'directory'?this.directory(tab.path)?.name || '任务目录':tab.kind === 'new'?'新标签':tab.kind === 'terminal'?'Terminal':tab.kind === 'web'?tab.pageTitle || tab.path:tab.path.split(/[\\/]/u).pop(); }
|
|
2478
3291
|
async loadWebTitle(tab, refresh = false) {
|
|
2479
3292
|
if (tab.titleRead && !refresh) return;
|
|
2480
3293
|
tab.titleRead = true; tab.titleController?.abort(); const controller = tab.titleController = new AbortController();
|
|
@@ -2509,31 +3322,110 @@
|
|
|
2509
3322
|
list.id = 'workspace-address-options-'+instanceId(); list.setAttribute('role','listbox'); list.setAttribute('aria-label','匹配的项目文件'); list.hidden = true;
|
|
2510
3323
|
input.placeholder = embedded ? '文件或目录路径' : '文件、目录或 https://…'; input.setAttribute('aria-label',embedded ? '文件路径' : '文件路径或网页地址'); input.maxLength = 4096; input.autocomplete = 'off'; input.spellcheck = false;
|
|
2511
3324
|
input.setAttribute('role','combobox'); input.setAttribute('aria-autocomplete','list'); input.setAttribute('aria-controls',list.id); input.setAttribute('aria-expanded','false');
|
|
2512
|
-
this.addressInput = input;
|
|
2513
|
-
const
|
|
3325
|
+
this.addressInput = input;
|
|
3326
|
+
const fileAddress = ['file','diff'].includes(tab.kind);
|
|
3327
|
+
const picker = this.addressPicker = {input,list,field,hint,tab,fileAddress,key:tab.key,sequence:0,items:[],index:-1,editing:false};
|
|
2514
3328
|
const active = () => input.isConnected && this.addressPicker === picker && this.activeKey === tab.key;
|
|
2515
|
-
picker.outside = event => { if (!field.contains(event.target)) this.
|
|
3329
|
+
picker.outside = event => { if (!field.contains(event.target)) this.dismissAddress(picker); }; if (!this.hidden) this.setAddressPickerVisible(true);
|
|
2516
3330
|
const changed = event => { if (!active()) return; picker.lookupController?.abort(); picker.submission = (picker.submission || 0)+1; this.tabs.get(tab.key).draft = input.value; this.hideAddressSuggestions(picker); if (!picker.composing && !event?.isComposing) this.suggestAddress(picker); };
|
|
2517
3331
|
input.oninput = changed; input.addEventListener('compositionstart',() => { picker.composing = true; changed(); }); input.addEventListener('compositionend',event => { picker.composing = false; changed(event); }); input.onfocus = () => { if (active() && !picker.composing) this.suggestAddress(picker); };
|
|
2518
|
-
|
|
3332
|
+
field.addEventListener('focusout',event => { if (!field.contains(event.relatedTarget)) this.dismissAddress(picker); });
|
|
2519
3333
|
input.onkeydown = event => {
|
|
2520
3334
|
if (!active() || picker.composing || event.isComposing) return;
|
|
2521
3335
|
if (event.key === 'Escape') { event.preventDefault(); picker.lookupController?.abort(); picker.submission = (picker.submission || 0)+1; this.hideAddressSuggestions(picker); }
|
|
2522
3336
|
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
2523
3337
|
event.preventDefault(); const direction = event.key === 'ArrowDown'?1:-1;
|
|
2524
3338
|
if (list.hidden || !picker.items.length) this.suggestAddress(picker,direction);
|
|
2525
|
-
else this.
|
|
3339
|
+
else this.moveAddressOption(picker,direction);
|
|
2526
3340
|
} else if (event.key === 'Enter') {
|
|
2527
3341
|
event.preventDefault(); const item = !list.hidden && picker.value === input.value ? picker.items[picker.index] : undefined;
|
|
2528
3342
|
this.openAddress(input.value,hint,tab.key,item?.path);
|
|
2529
3343
|
}
|
|
2530
3344
|
};
|
|
2531
|
-
field.append(input
|
|
3345
|
+
field.append(input);
|
|
3346
|
+
if (fileAddress && !absoluteFilePath(tab.path) && this.previewApi(tab.source) && this.previewRoot(tab.source)) {
|
|
3347
|
+
const breadcrumbs = picker.breadcrumbs = element('div',undefined,'address-breadcrumbs');
|
|
3348
|
+
breadcrumbs.tabIndex = -1; breadcrumbs.setAttribute('role','combobox'); breadcrumbs.setAttribute('aria-label','浏览文件路径');
|
|
3349
|
+
breadcrumbs.setAttribute('aria-controls',list.id); breadcrumbs.setAttribute('aria-expanded','false');
|
|
3350
|
+
breadcrumbs.onpointerdown = event => {
|
|
3351
|
+
if (event.target === breadcrumbs && event.button === 0 && !event.shiftKey && addressPathSelection(breadcrumbs)) {
|
|
3352
|
+
window.getSelection().removeAllRanges();
|
|
3353
|
+
}
|
|
3354
|
+
};
|
|
3355
|
+
breadcrumbs.onclick = event => {
|
|
3356
|
+
if (event.target === breadcrumbs && !addressPathSelection(breadcrumbs)) this.editAddress(picker);
|
|
3357
|
+
};
|
|
3358
|
+
breadcrumbs.ondblclick = () => this.editAddress(picker);
|
|
3359
|
+
breadcrumbs.addEventListener('copy',event => {
|
|
3360
|
+
const range = addressPathSelection(breadcrumbs);
|
|
3361
|
+
if (!range || !event.clipboardData) return;
|
|
3362
|
+
event.clipboardData.setData('text/plain',range.toString());
|
|
3363
|
+
event.preventDefault();
|
|
3364
|
+
});
|
|
3365
|
+
breadcrumbs.addEventListener('wheel',event => {
|
|
3366
|
+
if (event.ctrlKey || Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
3367
|
+
const left = breadcrumbs.scrollLeft;
|
|
3368
|
+
breadcrumbs.scrollLeft += event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? breadcrumbs.clientWidth : 1);
|
|
3369
|
+
if (breadcrumbs.scrollLeft !== left) event.preventDefault();
|
|
3370
|
+
},{passive:false});
|
|
3371
|
+
breadcrumbs.onkeydown = event => {
|
|
3372
|
+
if (event.key === 'F2') { event.preventDefault(); this.editAddress(picker); }
|
|
3373
|
+
else if (picker.browse && event.key === 'Escape') { event.preventDefault(); this.dismissAddress(picker); }
|
|
3374
|
+
else if (picker.browse && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
|
3375
|
+
event.preventDefault(); this.moveAddressOption(picker,event.key === 'ArrowDown' ? 1 : -1);
|
|
3376
|
+
} else if (picker.browse && event.target === breadcrumbs && event.key === 'Enter' && picker.items[picker.index]) {
|
|
3377
|
+
event.preventDefault(); picker.choose(picker.items[picker.index]);
|
|
3378
|
+
}
|
|
3379
|
+
};
|
|
3380
|
+
field.append(breadcrumbs);
|
|
3381
|
+
}
|
|
3382
|
+
field.append(list);
|
|
3383
|
+
if (fileAddress) {
|
|
3384
|
+
const zoom = picker.zoom = iconControl('button','zoomIn','恢复预览缩放','reset-preview-zoom');
|
|
3385
|
+
zoom.onclick = () => {
|
|
3386
|
+
this.hideAddressSuggestions(picker);
|
|
3387
|
+
this.closest('agentbot-workspace').setPreviewFontSize(defaultPreviewFontSize);
|
|
3388
|
+
this.content.focus({preventScroll:true});
|
|
3389
|
+
};
|
|
3390
|
+
field.append(zoom); this.updatePreviewZoom();
|
|
3391
|
+
}
|
|
3392
|
+
address.append(this.navigationBack,this.navigationForward,field);
|
|
3393
|
+
if (!embedded) {
|
|
3394
|
+
const app = this.closest('agentbot-workspace');
|
|
3395
|
+
const expand = picker.expand = iconControl('button','expandFiles','展开文件区','toggle-file-expansion');
|
|
3396
|
+
expand.type = 'button'; expand.onclick = () => app.togglePanel('chat');
|
|
3397
|
+
address.append(expand);
|
|
3398
|
+
this.updateFileExpansion(app.panelCollapsed('chat'));
|
|
3399
|
+
}
|
|
3400
|
+
this.toolbar.append(address); this.updateAddress(); return input;
|
|
3401
|
+
}
|
|
3402
|
+
updateFileExpansion(expanded) {
|
|
3403
|
+
const button = this.addressPicker?.expand;
|
|
3404
|
+
if (!button || button.getAttribute('aria-pressed') === String(expanded)) return;
|
|
3405
|
+
const label = expanded ? '恢复聊天栏' : '展开文件区';
|
|
3406
|
+
button.replaceChildren(icon(expanded ? 'restoreFiles' : 'expandFiles'));
|
|
3407
|
+
button.dataset.tooltip = label; button.setAttribute('aria-label',label); button.setAttribute('aria-pressed',String(expanded));
|
|
3408
|
+
}
|
|
3409
|
+
hasTextPreview() {
|
|
3410
|
+
return this.renderedKey === this.activeKey && Boolean(this.content.querySelector('pre.code,.markdown-body'));
|
|
3411
|
+
}
|
|
3412
|
+
updatePreviewZoom() {
|
|
3413
|
+
const button = this.addressPicker?.zoom;
|
|
3414
|
+
if (!button) return;
|
|
3415
|
+
const size = this.closest('agentbot-workspace').previewFontSize ?? defaultPreviewFontSize;
|
|
3416
|
+
button.hidden = size === defaultPreviewFontSize || !this.hasTextPreview();
|
|
3417
|
+
if (button.hidden) return;
|
|
3418
|
+
const percent = Math.round(size/defaultPreviewFontSize*100), glyph = size > defaultPreviewFontSize ? 'zoomIn' : 'zoomOut';
|
|
3419
|
+
if (button.dataset.zoomIcon !== glyph) { button.dataset.zoomIcon = glyph; button.replaceChildren(icon(glyph)); }
|
|
3420
|
+
button.dataset.tooltip = `预览缩放 ${percent}%`;
|
|
3421
|
+
button.setAttribute('aria-label',`预览缩放 ${percent}%,点击恢复 100%`);
|
|
2532
3422
|
}
|
|
2533
3423
|
updateAddress() {
|
|
2534
3424
|
const tab = this.tabs.get(this.activeKey); if (!this.addressInput || !tab) return;
|
|
2535
3425
|
const suffix = (tab.hash || '').replace(/^#L(\d+)$/u,':$1');
|
|
2536
3426
|
this.addressInput.value = tab.draft ?? (['file','diff'].includes(tab.kind)?tab.path+suffix:tab.kind==='web'?tab.path:tab.kind==='directory'?this.directory(tab.path)?.path || '':'');
|
|
3427
|
+
const picker = this.addressPicker;
|
|
3428
|
+
if (picker?.tab === tab && picker.breadcrumbs) this.renderAddressPath(picker,tab,suffix);
|
|
2537
3429
|
}
|
|
2538
3430
|
setTaskDirectories(directories = []) {
|
|
2539
3431
|
if (JSON.stringify(this.taskDirectories) === JSON.stringify(directories)) return;
|
|
@@ -2556,6 +3448,7 @@
|
|
|
2556
3448
|
section.append(element('h3','任务目录'),list);
|
|
2557
3449
|
for (const directory of this.taskDirectories) {
|
|
2558
3450
|
const row = element('li'), button = element('button',undefined,'launch-directory');
|
|
3451
|
+
button.dataset.referenceDirectory = directory.path;
|
|
2559
3452
|
const label = element('span',undefined,'launch-directory-label');
|
|
2560
3453
|
label.append(element('strong',directory.name),element('span',directory.path,'launch-directory-path'));
|
|
2561
3454
|
button.append(icon('folder'),label);
|
|
@@ -2677,7 +3570,14 @@
|
|
|
2677
3570
|
}
|
|
2678
3571
|
saveScroll() {
|
|
2679
3572
|
const previous = this.tabs.get(this.activeKey);
|
|
2680
|
-
if (previous && this.renderedKey === this.activeKey && this.content.clientHeight > 0) {
|
|
3573
|
+
if (previous && this.renderedKey === this.activeKey && this.content.clientHeight > 0) {
|
|
3574
|
+
previous.scrollTop = this.content.scrollTop; previous.scrollLeft = this.content.scrollLeft;
|
|
3575
|
+
if (previous.kind === 'diff') {
|
|
3576
|
+
(previous.diffScroll ??= new Map()).set(diffScrollKey(previous),[previous.scrollTop,previous.scrollLeft]);
|
|
3577
|
+
} else if (previous.preview?.canTogglePreview) {
|
|
3578
|
+
(previous.fileScroll ??= new Map()).set(Boolean(previous.sourceView),[previous.scrollTop,previous.scrollLeft]);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
2681
3581
|
const view = this.navigationViews.get(this.listMode);
|
|
2682
3582
|
if (view.ready && this.navigation.clientHeight > 0) {
|
|
2683
3583
|
if (view.query) this.listScrollTop = view.filterScrollTop = this.navigation.scrollTop;
|
|
@@ -2709,8 +3609,9 @@
|
|
|
2709
3609
|
for (const node of this.content.querySelectorAll('.workspace-anchor')) node.classList.remove('workspace-anchor');
|
|
2710
3610
|
if (!tab.hash) return;
|
|
2711
3611
|
let id; try { id = decodeURIComponent(tab.hash.slice(1)); } catch { return; }
|
|
2712
|
-
|
|
2713
|
-
if (target && this.content.contains(target))
|
|
3612
|
+
let target = document.getElementById(id);
|
|
3613
|
+
if (target && !this.content.contains(target)) target = [...this.content.querySelectorAll('[id]')].find(node => node.id === id);
|
|
3614
|
+
if (target) {
|
|
2714
3615
|
target.classList.add('workspace-anchor');
|
|
2715
3616
|
if (tab.requestedHash && this.content.clientHeight > 0) {
|
|
2716
3617
|
if (tab.kind === 'diff' && this.diffBlocks.includes(target)) this.content.scrollTop = this.diffBlockScrollTop(target);
|
|
@@ -2752,14 +3653,14 @@
|
|
|
2752
3653
|
this.saveScroll(); this.updateDiffNavigation();
|
|
2753
3654
|
});
|
|
2754
3655
|
}
|
|
2755
|
-
restoreView(route,
|
|
3656
|
+
restoreView(route, listScrollTop) {
|
|
2756
3657
|
this.selectList(route.listMode); this.dataset.view = route.view;
|
|
2757
|
-
|
|
3658
|
+
this.listScrollTop = listScrollTop;
|
|
2758
3659
|
if (route.tab) {
|
|
2759
3660
|
const key = route.tab.id, tab = this.tabs.get(key);
|
|
2760
3661
|
const retained = this.activeKey === key && tab?.mode === route.tab.mode && this.renderedKey === key;
|
|
2761
3662
|
if (tab.mode !== route.tab.mode) this.renderedKey = undefined;
|
|
2762
|
-
tab.mode = route.tab.mode; tab.hash = route.tab.hash;
|
|
3663
|
+
tab.mode = route.tab.mode; tab.hash = route.tab.hash;
|
|
2763
3664
|
this.activateTab(key);
|
|
2764
3665
|
this.renderTabs();
|
|
2765
3666
|
this.restoreScroll(); if (!retained) this.loadTab(tab);
|
|
@@ -2768,13 +3669,50 @@
|
|
|
2768
3669
|
this.toolbar.hidden = true; this.syncFrames(); this.showExplorerEmpty(); this.renderTabs(); this.restoreScroll();
|
|
2769
3670
|
}
|
|
2770
3671
|
}
|
|
3672
|
+
tabIcon(tab) { return ['file','diff'].includes(tab.kind)?fileIcon(tab.path):icon(tab.kind === 'directory'?'folder':tab.kind); }
|
|
3673
|
+
selectTab(key) { this.navigate(() => { this.saveScroll(); this.showTab(this.tabs.get(key)); }); }
|
|
3674
|
+
setTabPinned(key,pinned,trigger) {
|
|
3675
|
+
if (!this.tabs.has(key) || pinned === this.pinnedTabs.has(key)) return;
|
|
3676
|
+
this.navigate(() => {
|
|
3677
|
+
if (pinned) this.pinnedTabs.add(key); else this.pinnedTabs.delete(key);
|
|
3678
|
+
this.renderTabs();
|
|
3679
|
+
(trigger.closest('.file-tab').hidden ? this.pinnedTabsMore : trigger).focus({preventScroll:true});
|
|
3680
|
+
},true);
|
|
3681
|
+
}
|
|
3682
|
+
resizePinnedTabs() {
|
|
3683
|
+
const rows = [...this.pinnedTabBar.querySelectorAll('.file-tab')], width = this.tabStrip.clientWidth;
|
|
3684
|
+
this.pinnedTabBar.hidden = !rows.length;
|
|
3685
|
+
const regularWidth = this.tabs.size > rows.length ? 64 : 0;
|
|
3686
|
+
const capacity = width > 0 ? Math.max(2,Math.floor((width-this.tabActions.offsetWidth-regularWidth-1)/pinnedTabWidth)) : rows.length;
|
|
3687
|
+
const overflow = rows.length > capacity, visible = rows.slice(0,overflow?capacity-1:capacity);
|
|
3688
|
+
const active = rows.find(row => row.dataset.key === this.activeKey);
|
|
3689
|
+
if (overflow && visible.length && active && !visible.includes(active)) visible[visible.length-1] = active;
|
|
3690
|
+
this.pinnedTabsMore.hidden = !overflow;
|
|
3691
|
+
for (const row of rows) {
|
|
3692
|
+
const hidden = !visible.includes(row);
|
|
3693
|
+
if (row.hidden === hidden) continue;
|
|
3694
|
+
if (hidden && row.contains(document.activeElement)) this.pinnedTabsMore.focus({preventScroll:true});
|
|
3695
|
+
row.hidden = hidden;
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
openPinnedTabsMenu(event) {
|
|
3699
|
+
const actions = [...this.pinnedTabBar.querySelectorAll('.file-tab[hidden]')].map(row => {
|
|
3700
|
+
const tab = this.tabs.get(row.dataset.key), select = row.querySelector('[role=tab]');
|
|
3701
|
+
return [this.tabIcon(tab),this.tabTitle(tab),() => {
|
|
3702
|
+
this.selectTab(tab.key);
|
|
3703
|
+
if (!row.hidden) select.focus({preventScroll:true});
|
|
3704
|
+
}];
|
|
3705
|
+
});
|
|
3706
|
+
if (actions.length) this.closest('agentbot-workspace').annotations.showReferenceMenu(event,this.pinnedTabsMore,actions);
|
|
3707
|
+
}
|
|
2771
3708
|
renderTabs() {
|
|
2772
|
-
const left = this.rememberTabsScroll(), rows = new Map([...this.
|
|
3709
|
+
const left = this.rememberTabsScroll(), rows = new Map([...this.tabStrip.querySelectorAll('.file-tab')].map(row => [row.dataset.key,row]));
|
|
2773
3710
|
this.tabBar.querySelector('.file-tabs-placeholder')?.remove();
|
|
2774
3711
|
for (const [key,row] of rows) if (!this.tabs.has(key)) row.remove();
|
|
2775
|
-
let activeRow, addedActive = this.revealTabKey === this.activeKey, index = 0;
|
|
3712
|
+
let activeRow, addedActive = this.revealTabKey === this.activeKey, index = 0, pinnedIndex = 0;
|
|
2776
3713
|
this.revealTabKey = undefined;
|
|
2777
3714
|
for (const tab of this.tabs.values()) {
|
|
3715
|
+
const pinned = this.pinnedTabs.has(tab.key);
|
|
2778
3716
|
let row = rows.get(tab.key);
|
|
2779
3717
|
if (!row) {
|
|
2780
3718
|
row = element('div',undefined,'file-tab'); row.dataset.key = tab.key;
|
|
@@ -2784,19 +3722,21 @@
|
|
|
2784
3722
|
}
|
|
2785
3723
|
const select = row.querySelector('[role=tab]'), close = row.querySelector('.close-tab');
|
|
2786
3724
|
if (select.dataset.tabPath !== tab.path || row.dataset.kind !== tab.kind) {
|
|
2787
|
-
select.replaceChildren(
|
|
3725
|
+
select.replaceChildren(this.tabIcon(tab),element('span',this.tabTitle(tab),'tab-name'));
|
|
2788
3726
|
if (tab.kind === 'diff') { const badge = element('span','±','tab-diff-badge'); badge.setAttribute('aria-hidden','true'); select.append(badge); }
|
|
2789
3727
|
select.dataset.tabPath = tab.path; row.dataset.kind = tab.kind;
|
|
2790
3728
|
}
|
|
2791
3729
|
const name = select.querySelector('.tab-name'), title = this.tabTitle(tab); if (name.textContent !== title) name.textContent = title;
|
|
3730
|
+
name.hidden = close.hidden = pinned;
|
|
3731
|
+
if (tab.kind === 'diff') select.querySelector('.tab-diff-badge').hidden = pinned;
|
|
2792
3732
|
const source = tab.source ? this.previewRoot(tab.source) : undefined;
|
|
2793
3733
|
const fullPath = source ? source+' · '+tab.path : tab.kind === 'directory' ? this.directory(tab.path)?.path : ['file','diff','web'].includes(tab.kind) ? tab.path : undefined;
|
|
2794
|
-
if (fullPath && fullPath !== title) { select.dataset.tooltip = fullPath; delete select.dataset.tooltipOverflow; }
|
|
3734
|
+
if (pinned || fullPath && fullPath !== title) { select.dataset.tooltip = fullPath || title; delete select.dataset.tooltipOverflow; }
|
|
2795
3735
|
else { delete select.dataset.tooltip; select.dataset.tooltipOverflow = '.tab-name'; }
|
|
2796
3736
|
select.setAttribute('aria-label',tab.kind === 'directory'?'浏览目录 '+title:(tab.kind === 'diff'?'查看改动 ':tab.kind === 'web'?'查看网页 ':tab.kind === 'terminal'?'查看终端 ':tab.kind === 'new'?'':'查看文件 ')+(tab.kind === 'new'?'新标签':tab.kind === 'web' && tab.pageTitle?tab.pageTitle+' · '+tab.path:tab.path));
|
|
2797
3737
|
const label = '关闭 '+title+(tab.kind === 'diff'?' 改动':'');
|
|
2798
3738
|
if (close.getAttribute('aria-label') !== label) { close.dataset.tooltip = label; close.setAttribute('aria-label',label); }
|
|
2799
|
-
select.onclick = () => this.
|
|
3739
|
+
select.onclick = () => this.selectTab(tab.key);
|
|
2800
3740
|
close.onclick = () => this.navigate(() => {
|
|
2801
3741
|
const keys = [...this.tabs.keys()], index = keys.indexOf(tab.key);
|
|
2802
3742
|
this.saveScroll(); this.tabs.delete(tab.key); this.closeViews(tab.key);
|
|
@@ -2809,12 +3749,14 @@
|
|
|
2809
3749
|
}
|
|
2810
3750
|
this.renderTabs();
|
|
2811
3751
|
},true);
|
|
2812
|
-
|
|
2813
|
-
|
|
3752
|
+
const rail = pinned ? this.pinnedTabBar : this.tabBar, position = pinned ? pinnedIndex++ : index++;
|
|
3753
|
+
if (rail.children[position] !== row) rail.insertBefore(row,rail.children[position] || null);
|
|
3754
|
+
if (!pinned) row.hidden = false;
|
|
2814
3755
|
row.classList.toggle('is-active',tab.key === this.activeKey);
|
|
2815
3756
|
row.querySelector('[role=tab]').setAttribute('aria-selected',String(tab.key === this.activeKey));
|
|
2816
|
-
if (tab.key === this.activeKey) activeRow = row;
|
|
3757
|
+
if (!pinned && tab.key === this.activeKey) activeRow = row;
|
|
2817
3758
|
}
|
|
3759
|
+
this.resizePinnedTabs();
|
|
2818
3760
|
if (!this.tabs.size) this.tabBar.append(element('span','文件预览','file-tabs-placeholder'));
|
|
2819
3761
|
this.syncFrames();
|
|
2820
3762
|
this.updateCurrentFile();
|
|
@@ -2843,74 +3785,94 @@
|
|
|
2843
3785
|
if (width > 0) this.tabScrollLeft = Math.min(this.tabScrollLeft,Math.max(0,this.tabBar.scrollWidth-width));
|
|
2844
3786
|
this.tabWidth = width; this.tabBar.scrollLeft = this.tabScrollLeft;
|
|
2845
3787
|
}
|
|
2846
|
-
resizeTabs() { this.scrollTabs(this.rememberTabsScroll()); }
|
|
3788
|
+
resizeTabs() { this.resizePinnedTabs(); this.scrollTabs(this.rememberTabsScroll()); }
|
|
3789
|
+
loadRecordedDiff(tab,signal) {
|
|
3790
|
+
const [turn,tool,patch] = JSON.parse(tab.patch);
|
|
3791
|
+
return this.closest('agentbot-workspace').sessions.fetch('/tool',{params:{task:this.taskId,turn,tool,patch},signal});
|
|
3792
|
+
}
|
|
2847
3793
|
async loadTab(tab, forceRefresh = false, liveData) {
|
|
2848
|
-
if (!forceRefresh && this.loadingTab?.key === tab.key && this.loadingTab.path === tab.path && this.loadingTab.kind === tab.kind && this.loadingTab.mode === tab.mode && this.loadingTab.original === tab.original && this.loadingTab.source === tab.source && !this.tabController.signal.aborted) return;
|
|
3794
|
+
if (!forceRefresh && this.loadingTab?.key === tab.key && this.loadingTab.path === tab.path && this.loadingTab.kind === tab.kind && this.loadingTab.mode === tab.mode && this.loadingTab.original === tab.original && this.loadingTab.source === tab.source && this.loadingTab.patch === tab.patch && this.loadingTab.sourceView === tab.sourceView && !this.tabController.signal.aborted) return;
|
|
2849
3795
|
const generation = ++this.generation, revision = tab.stale;
|
|
2850
3796
|
this.tabController?.abort(); const controller = new AbortController(); this.tabController = controller;
|
|
2851
3797
|
this.syncFrames();
|
|
2852
3798
|
if (tab.kind === 'directory') { this.loadingTab = undefined; this.diffBlocks = []; this.diffControls = undefined; await this.loadDirectoryTab(tab,controller); return; }
|
|
2853
3799
|
if (['new','web','terminal'].includes(tab.kind)) { this.loadingTab = undefined; this.diffBlocks = []; this.diffControls = undefined; await this.loadSpecialTab(tab,forceRefresh,generation,controller); return; }
|
|
2854
|
-
const
|
|
3800
|
+
const recorded = tab.mode === 'recorded';
|
|
3801
|
+
const candidate = tab.filePreviews?.get(Boolean(tab.sourceView)) ?? tab.preview;
|
|
3802
|
+
const cached = !forceRefresh && candidate?.mode === tab.mode && candidate.original === tab.original
|
|
3803
|
+
&& candidate.sourceView === tab.sourceView && (!recorded || candidate.patch === tab.patch) ? candidate : undefined;
|
|
2855
3804
|
const focusFirstDiff = tab.kind === 'diff' && !tab.preview && !tab.hash && tab.scrollTop === 0;
|
|
2856
|
-
this.loadingTab = cached ? undefined : {key:tab.key,path:tab.path,kind:tab.kind,mode:tab.mode,original:tab.original,source:tab.source};
|
|
3805
|
+
this.loadingTab = cached ? undefined : {key:tab.key,path:tab.path,kind:tab.kind,mode:tab.mode,original:tab.original,source:tab.source,patch:tab.patch,sourceView:tab.sourceView};
|
|
2857
3806
|
this.diffBlocks = []; this.diffControls = undefined;
|
|
2858
3807
|
if (!cached) tab.preview = undefined;
|
|
2859
3808
|
this.toolbar.hidden = false; this.toolbar.replaceChildren();
|
|
2860
3809
|
const hint = element('p',undefined,'launch-hint'); hint.hidden = true; this.renderAddress(tab,hint); this.toolbar.append(hint);
|
|
2861
3810
|
const actions = element('div',undefined,'workspace-view-actions'); this.toolbar.append(actions);
|
|
2862
|
-
const refresh = iconControl('button','refresh','刷新当前文件','content-refresh');
|
|
2863
3811
|
const list = iconControl('button','tree',this.listMode === 'changes'?'返回改动列表':'返回文件列表','mobile-list');
|
|
2864
3812
|
list.onclick = () => this.showList();
|
|
2865
|
-
refresh.onclick = () => { this.saveScroll(); this.loadTab(tab,true); };
|
|
2866
3813
|
actions.append(list);
|
|
2867
3814
|
if (tab.kind === 'diff') {
|
|
2868
3815
|
const previous = iconControl('button','up','上一处改动','diff-previous'), next = iconControl('button','down','下一处改动','diff-next');
|
|
2869
3816
|
previous.disabled = next.disabled = true; previous.onclick = () => this.jumpDiff('previous'); next.onclick = () => this.jumpDiff('next');
|
|
2870
3817
|
this.diffControls = {previous,next}; actions.append(previous,next);
|
|
2871
3818
|
const select = element('select'); select.setAttribute('aria-label','Diff 范围');
|
|
2872
|
-
|
|
2873
|
-
|
|
3819
|
+
const scopes = [['all','全部'],['staged','已暂存'],['unstaged','未暂存']];
|
|
3820
|
+
if (this.taskId) scopes.push(['recorded','本次修改']);
|
|
3821
|
+
const gitAvailable = !absoluteFilePath(tab.path) && Boolean(this.previewApi(tab.source));
|
|
3822
|
+
for (const [value,label] of scopes) {
|
|
3823
|
+
const option = element('option',label); option.value = value; option.selected = value === tab.mode;
|
|
3824
|
+
option.disabled = value === 'recorded' ? !tab.patch : !gitAvailable;
|
|
3825
|
+
select.append(option);
|
|
2874
3826
|
}
|
|
2875
|
-
select.onchange = () =>
|
|
3827
|
+
select.onchange = () => {
|
|
3828
|
+
const mode = select.value;
|
|
3829
|
+
if (mode === tab.mode || ![...select.options].some(option => option.value === mode && !option.disabled)) return;
|
|
3830
|
+
this.navigate(() => { this.saveScroll(); this.setDiffMode(tab,mode); this.loadTab(tab,true); });
|
|
3831
|
+
};
|
|
2876
3832
|
actions.append(select);
|
|
2877
3833
|
}
|
|
2878
|
-
actions.append(this.explorerToggle
|
|
3834
|
+
actions.append(this.explorerToggle);
|
|
2879
3835
|
const retained = this.renderedKey === tab.key;
|
|
2880
3836
|
if (!retained && !cached) { this.renderedKey = undefined; this.content.replaceChildren(element('div','正在读取…','content-empty')); }
|
|
2881
3837
|
try {
|
|
2882
3838
|
let etag = liveData?.etag;
|
|
2883
|
-
const data = liveData || cached || await
|
|
3839
|
+
const data = liveData || cached || await (recorded ? this.loadRecordedDiff(tab,controller.signal)
|
|
3840
|
+
: this.request(tab.kind,{entry:tab.path,mode:tab.mode,original:tab.original,source:tab.sourceView?'1':undefined},controller,undefined,value => { etag = value; },this.previewApi(tab.source)));
|
|
2884
3841
|
if (!this.isConnected || generation !== this.generation || !this.tabs.has(tab.key)) return;
|
|
2885
3842
|
const visible = retained && this.content.clientHeight > 0;
|
|
2886
3843
|
const top = visible ? this.content.scrollTop : tab.scrollTop, left = visible ? this.content.scrollLeft : tab.scrollLeft;
|
|
2887
3844
|
if (cached) {
|
|
2888
3845
|
if (!retained) { this.clearPreviewCaret(); this.content.replaceChildren(...cached.nodes); }
|
|
3846
|
+
tab.preview = cached;
|
|
2889
3847
|
} else {
|
|
2890
3848
|
this.clearPreviewCaret();
|
|
2891
3849
|
this.content.innerHTML = data.html;
|
|
2892
|
-
tab.preview = {mode:tab.mode,original:tab.original,
|
|
3850
|
+
tab.preview = {mode:tab.mode,original:tab.original,patch:recorded?tab.patch:undefined,sourceView:tab.sourceView,etag,html:data.html,
|
|
3851
|
+
nodes:[...this.content.childNodes],canViewFile:data.canViewFile,canTogglePreview:data.canTogglePreview === true,change:data.change,gitError:data.gitError};
|
|
3852
|
+
if (tab.preview.canTogglePreview) (tab.filePreviews ??= new Map()).set(Boolean(tab.sourceView),tab.preview);
|
|
2893
3853
|
if (tab.stale === revision) tab.stale = undefined;
|
|
2894
3854
|
}
|
|
2895
3855
|
this.renderedKey = tab.key;
|
|
2896
|
-
|
|
3856
|
+
this.updatePreviewZoom();
|
|
3857
|
+
if (!forceRefresh && !recorded) this.rememberRecentFile(tab);
|
|
2897
3858
|
if (tab.kind === 'diff') this.diffBlocks = [...this.content.querySelectorAll('.git-diff .diff-addition,.git-diff .diff-deletion')].filter(block => !block.previousElementSibling?.matches('.diff-addition,.diff-deletion'));
|
|
2898
3859
|
this.content.scrollTop = top; this.content.scrollLeft = left;
|
|
2899
3860
|
if (focusFirstDiff && this.diffBlocks.length) tab.hash = tab.requestedHash = '#'+this.diffBlocks[0].id;
|
|
2900
3861
|
window.agentBotDiagrams?.scan();
|
|
2901
3862
|
this.restoreHash(tab); this.updateDiffNavigation(); this.queuePersist();
|
|
2902
|
-
if (tab.kind === 'diff') {
|
|
3863
|
+
if (tab.kind === 'diff' && !recorded) {
|
|
2903
3864
|
const file = iconControl('button','openFile','查看文件内容','file-content'); file.disabled = !data.canViewFile;
|
|
2904
|
-
file.onclick = () => this.openFile(tab.path,'file',undefined,undefined,undefined,tab.source);
|
|
2905
|
-
} else if (data.
|
|
2906
|
-
const
|
|
2907
|
-
|
|
3865
|
+
file.onclick = () => this.openFile(tab.path,'file',undefined,undefined,undefined,tab.source); this.explorerToggle.before(file);
|
|
3866
|
+
} else if (tab.kind === 'file' && data.canTogglePreview) {
|
|
3867
|
+
const toggle = iconControl('button',tab.sourceView?'preview':'code',tab.sourceView?'切换到预览模式':'查看原文件','toggle-file-preview');
|
|
3868
|
+
toggle.onclick = () => this.toggleFileView(tab); this.explorerToggle.before(toggle);
|
|
2908
3869
|
}
|
|
2909
|
-
if (tab.kind === 'file' && data.change) { const changes = iconControl('button','diff','查看文件变更','file-changes'); changes.onclick = () => this.openFile(data.change.path,'diff',data.change.originalPath,undefined,undefined,tab.source);
|
|
3870
|
+
if (tab.kind === 'file' && data.change) { const changes = iconControl('button','diff','查看文件变更','file-changes'); changes.onclick = () => this.openFile(data.change.path,'diff',data.change.originalPath,undefined,undefined,tab.source); this.explorerToggle.before(changes); }
|
|
2910
3871
|
if (data.gitError) { hint.textContent = '读取 Git 状态失败:'+data.gitError; hint.hidden = false; }
|
|
2911
3872
|
} catch (error) {
|
|
2912
3873
|
if (this.isConnected && generation === this.generation) {
|
|
2913
3874
|
this.renderedKey = undefined;
|
|
3875
|
+
this.updatePreviewZoom();
|
|
2914
3876
|
this.updateDiffNavigation();
|
|
2915
3877
|
this.notice(this.content,'读取'+(tab.kind === 'diff'?' Diff':'文件')+'失败:'+error.message,() => this.loadTab(tab,true));
|
|
2916
3878
|
}
|
|
@@ -2923,6 +3885,7 @@
|
|
|
2923
3885
|
}
|
|
2924
3886
|
}
|
|
2925
3887
|
class AgentBotWorkspace extends HTMLElement {
|
|
3888
|
+
createIcon(name) { return icon(name); }
|
|
2926
3889
|
toolIcon(kind) {
|
|
2927
3890
|
const glyph = icon(Object.hasOwn(toolIcons,kind) ? toolIcons[kind] : 'tool');
|
|
2928
3891
|
glyph.classList.add('session-tool-icon');
|
|
@@ -2940,18 +3903,36 @@
|
|
|
2940
3903
|
this.historyMaximumKnown = state?.workspace !== historyScope || state.maximum !== undefined;
|
|
2941
3904
|
this.historyGuard = Boolean(state?.workspace === historyScope && state.guarded);
|
|
2942
3905
|
this.dataset.pane = 'files';
|
|
3906
|
+
if (!embedded) this.dataset.taskSidebar = stored(taskSidebarKey) === true ? 'pinned' : 'closed';
|
|
3907
|
+
this.taskSidebarWidth = stored(taskSidebarWidthKey);
|
|
2943
3908
|
this.innerHTML = '<header class="workspace-header"><div class="workspace-title"></div><small class="workspace-status">只读工作台</small><nav class="workspace-nav" aria-label="工作台区域"><button data-pane="tasks">任务</button><button data-pane="chat">聊天</button><button data-pane="files" aria-pressed="true">文件</button></nav></header><main class="workspace-layout"><workspace-task-list></workspace-task-list><workspace-chat></workspace-chat></main>';
|
|
2944
3909
|
this.layout = appBase ? this.globalLayout() : {};
|
|
2945
|
-
this.
|
|
3910
|
+
this.taskSplitter = this.separator('sidebar','调整任务侧栏宽度');
|
|
3911
|
+
this.querySelector('workspace-chat').before(this.taskSplitter);
|
|
2946
3912
|
this.querySelector('.workspace-layout').append(this.separator('chat','调整聊天区域宽度'));
|
|
2947
3913
|
// The signed entry authorizes this project's files, not the task's conversation.
|
|
2948
3914
|
const files = root && initialTask ? this.createFilesPanel(initialTask,apiBase,root) : this.getGuestPanel();
|
|
2949
3915
|
this.showFilesPanel(files);
|
|
2950
|
-
const collapse = iconControl('button','sidebar','折叠任务侧栏','toggle-sidebar');
|
|
3916
|
+
const collapse = this.taskToggle = iconControl('button','sidebar','折叠任务侧栏','toggle-sidebar');
|
|
3917
|
+
this.taskSidebar = this.querySelector('workspace-task-list');
|
|
3918
|
+
this.taskSidebar.id = 'workspace-task-sidebar'; collapse.setAttribute('aria-controls',this.taskSidebar.id);
|
|
3919
|
+
collapse.onclick = () => this.toggleTaskSidebar();
|
|
3920
|
+
collapse.onpointerenter = event => {
|
|
3921
|
+
if (event.pointerType === 'mouse' && this.mediumLayout() && this.dataset.pane !== 'tasks') this.setTaskPreview(true);
|
|
3922
|
+
};
|
|
3923
|
+
this.taskSidebar.onpointerenter = this.taskSplitter.onpointerenter = () => clearTimeout(this.taskPreviewTimer);
|
|
3924
|
+
collapse.onpointerleave = this.taskSidebar.onpointerleave = this.taskSplitter.onpointerleave = () => this.deferTaskPreviewClose();
|
|
3925
|
+
this.taskSplitter.onfocusout = () => this.deferTaskPreviewClose();
|
|
3926
|
+
this.taskSidebar.onfocusout = () => {
|
|
3927
|
+
if (!this.taskSidebar.matches(':hover') && !collapse.matches(':hover')) this.deferTaskPreviewClose();
|
|
3928
|
+
};
|
|
3929
|
+
window.addEventListener('keydown',this.dismissTaskPreview);
|
|
3930
|
+
this.querySelector('.workspace-header').prepend(collapse);
|
|
2951
3931
|
const collapseFiles = iconControl('button','explorer','折叠文件工作区','toggle-files'); collapseFiles.onclick = () => this.togglePanel('files'); this.querySelector('.workspace-header').append(collapseFiles);
|
|
2952
3932
|
this.themeToggle = iconControl('button','moon','切换到深色模式','toggle-theme');
|
|
2953
3933
|
this.themeToggle.type = 'button';
|
|
2954
3934
|
collapseFiles.before(this.themeToggle);
|
|
3935
|
+
if (!embedded) this.installFullscreenToggle();
|
|
2955
3936
|
this.systemTheme = window.matchMedia?.('(prefers-color-scheme: dark)');
|
|
2956
3937
|
this.themePreference = stored(themeKey);
|
|
2957
3938
|
this.themeToggle.onclick = () => {
|
|
@@ -2960,10 +3941,14 @@
|
|
|
2960
3941
|
this.applyTheme();
|
|
2961
3942
|
};
|
|
2962
3943
|
this.systemTheme?.addEventListener?.('change',this.applyTheme);
|
|
2963
|
-
window.addEventListener('storage',this.
|
|
3944
|
+
window.addEventListener('storage',this.syncPreferences);
|
|
3945
|
+
window.addEventListener('keydown',this.zoomPreviewText);
|
|
3946
|
+
this.applyPreviewFontSize(stored(previewFontKey));
|
|
2964
3947
|
this.applyTheme();
|
|
2965
|
-
this.
|
|
3948
|
+
this.layoutWidth = window.innerWidth;
|
|
3949
|
+
window.addEventListener('resize',this.layoutResize);
|
|
2966
3950
|
this.scrollbars = new WorkspaceScrollbars(this);
|
|
3951
|
+
this.scrollbars.layer.addEventListener('pointerout',() => this.deferTaskPreviewClose());
|
|
2967
3952
|
this.tooltips = new WorkspaceTooltips(this);
|
|
2968
3953
|
this.commandPalette = new WorkspaceCommandPalette(this);
|
|
2969
3954
|
if (!embedded) {
|
|
@@ -3005,15 +3990,28 @@
|
|
|
3005
3990
|
this.handleEmbeddedAction = event => {
|
|
3006
3991
|
const address = event.data?.address, files = this.filesPanel, tab = files?.tabs.get(files.activeKey);
|
|
3007
3992
|
if (event.origin !== window.location.origin) return;
|
|
3008
|
-
if (
|
|
3009
|
-
const {annotation,request,task} = event.data;
|
|
3993
|
+
if (['agentbot-workspace-annotate','agentbot-workspace-reference'].includes(event.data?.type)) {
|
|
3994
|
+
const {type,annotation,id,note,remove,request,task,reference} = event.data;
|
|
3010
3995
|
const source = [...(files?.tabs.values() || [])].find(tab => tab.kind === 'directory' && tab.frame?.contentWindow === event.source);
|
|
3011
|
-
if (!source || typeof request !== 'string' || request.length > 64 || !this.sessions
|
|
3012
|
-
|
|
3996
|
+
if (!source || typeof request !== 'string' || request.length > 64 || !this.sessions) return;
|
|
3997
|
+
if (type === 'agentbot-workspace-reference') {
|
|
3998
|
+
const error = this.sessions.addReference(reference,task);
|
|
3999
|
+
event.source.postMessage({type:'agentbot-workspace-reference-result',request,error},window.location.origin);
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
const editing = typeof id === 'string' && id.length > 0 && id.length <= 64;
|
|
4003
|
+
if (!editing && (remove === true || typeof annotation?.path !== 'string')) return;
|
|
4004
|
+
const error = remove === true ? this.sessions.removeAnnotation(id,task,{fileOnly:true})
|
|
4005
|
+
: editing ? this.sessions.editAnnotation(id,note,task,{fileOnly:true}) : this.sessions.addAnnotation(annotation,task);
|
|
3013
4006
|
event.source.postMessage({type:'agentbot-workspace-annotation-result',request,error},window.location.origin);
|
|
3014
4007
|
return;
|
|
3015
4008
|
}
|
|
3016
4009
|
if (!tab?.frame || event.source !== tab.frame.contentWindow || files.dataset.view !== 'content') return;
|
|
4010
|
+
if (event.data?.type === 'agentbot-workspace-shortcut-hints' && tab.kind === 'directory') {
|
|
4011
|
+
if (event.data.visible === true) this.tooltips.showHints(event.source);
|
|
4012
|
+
else if (this.tooltips.hintSource === event.source) this.tooltips.hideHints();
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
3017
4015
|
if (event.data?.type === 'agentbot-workspace-open-file-search' && tab.kind === 'terminal') {
|
|
3018
4016
|
this.commandPalette.open(event.data.commands === true ? 'commands' : 'files'); return;
|
|
3019
4017
|
}
|
|
@@ -3036,7 +4034,7 @@
|
|
|
3036
4034
|
window.addEventListener('popstate',this.historyChanged); window.addEventListener('pagehide',this.persistHistory);
|
|
3037
4035
|
window.addEventListener('beforeunload',this.persistHistory);
|
|
3038
4036
|
if (appBase) this.sessions = new window.AgentBotSessionWorkspace(this,appBase);
|
|
3039
|
-
|
|
4037
|
+
this.annotations = new WorkspaceAnnotations(this);
|
|
3040
4038
|
// Reload may snapshot its URL before beforeunload saves the final reading position.
|
|
3041
4039
|
const reload = state?.workspace === historyScope && window.performance?.getEntriesByType('navigation')[0]?.type === 'reload';
|
|
3042
4040
|
if (root || !initialTask) this.restoreFilesPanel(reload?state.position:undefined,reload?state.url:undefined);
|
|
@@ -3044,6 +4042,7 @@
|
|
|
3044
4042
|
const params = new URL(initialHref).searchParams;
|
|
3045
4043
|
const rememberedPane = state?.workspace === historyScope && state.route?.task === initialTask ? state.route.pane : undefined;
|
|
3046
4044
|
const pane = params.get('pane') || rememberedPane;
|
|
4045
|
+
this.layout.filesCollapsed = true;
|
|
3047
4046
|
this.selectPane(['tasks','chat','files'].includes(pane) ? pane : params.has('list') || params.has('entry') ? 'files' : 'chat');
|
|
3048
4047
|
this.applyLayout();
|
|
3049
4048
|
}
|
|
@@ -3066,7 +4065,9 @@
|
|
|
3066
4065
|
this.annotations?.disconnect();
|
|
3067
4066
|
this.commandPalette.disconnect();
|
|
3068
4067
|
this.systemTheme?.removeEventListener?.('change',this.applyTheme);
|
|
3069
|
-
|
|
4068
|
+
for (const event of ['fullscreenchange','webkitfullscreenchange']) document.removeEventListener(event,this.updateFullscreenButton);
|
|
4069
|
+
window.removeEventListener('storage',this.syncPreferences);
|
|
4070
|
+
window.removeEventListener('keydown',this.zoomPreviewText);
|
|
3070
4071
|
clearTimeout(this.cacheSaveTimer); this.directoryCache.persist();
|
|
3071
4072
|
document.removeEventListener('visibilitychange',this.resumeFileSync);
|
|
3072
4073
|
document.removeEventListener('visibilitychange',this.checkWorkspaceVersion);
|
|
@@ -3077,6 +4078,7 @@
|
|
|
3077
4078
|
this.scrollbars.disconnect(); this.tooltips.disconnect();
|
|
3078
4079
|
this.finishHistoryTraversal();
|
|
3079
4080
|
window.removeEventListener('resize',this.layoutResize); this.endDrag?.();
|
|
4081
|
+
window.removeEventListener('keydown',this.dismissTaskPreview); clearTimeout(this.taskPreviewTimer);
|
|
3080
4082
|
this.removeEventListener('scroll',this.queuePersist,true); window.removeEventListener('hashchange',this.urlChanged); clearTimeout(this.persistTimer);
|
|
3081
4083
|
window.removeEventListener('popstate',this.historyChanged); window.removeEventListener('pagehide',this.persistHistory); window.removeEventListener('beforeunload',this.persistHistory);
|
|
3082
4084
|
}
|
|
@@ -3090,12 +4092,73 @@
|
|
|
3090
4092
|
this.themeToggle.setAttribute('aria-label',label);
|
|
3091
4093
|
if (theme !== previousTheme) window.agentBotDiagrams?.scan();
|
|
3092
4094
|
};
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
this.
|
|
4095
|
+
installFullscreenToggle() {
|
|
4096
|
+
const page = document.documentElement;
|
|
4097
|
+
const enter = page.requestFullscreen || page.webkitRequestFullscreen, exit = document.exitFullscreen || document.webkitExitFullscreen;
|
|
4098
|
+
const button = this.fullscreenToggle = iconControl('button','fullscreen','进入全屏','toggle-fullscreen');
|
|
4099
|
+
button.type = 'button';
|
|
4100
|
+
button.disabled = !enter || !exit || (document.fullscreenEnabled ?? document.webkitFullscreenEnabled) === false;
|
|
4101
|
+
this.themeToggle.after(button);
|
|
4102
|
+
this.updateFullscreenButton();
|
|
4103
|
+
if (button.disabled) return;
|
|
4104
|
+
for (const event of ['fullscreenchange','webkitfullscreenchange']) document.addEventListener(event,this.updateFullscreenButton);
|
|
4105
|
+
button.onclick = async () => {
|
|
4106
|
+
try {
|
|
4107
|
+
if (document.fullscreenElement || document.webkitFullscreenElement) await exit.call(document);
|
|
4108
|
+
else await enter.call(page);
|
|
4109
|
+
} catch { button.dataset.tooltip = '浏览器未能切换全屏'; }
|
|
4110
|
+
};
|
|
4111
|
+
}
|
|
4112
|
+
updateFullscreenButton = () => {
|
|
4113
|
+
const button = this.fullscreenToggle, active = Boolean(document.fullscreenElement || document.webkitFullscreenElement);
|
|
4114
|
+
const label = button.disabled ? '此浏览器不支持网页全屏' : active ? '退出全屏' : '进入全屏';
|
|
4115
|
+
button.replaceChildren(icon(active ? 'exitFullscreen' : 'fullscreen'));
|
|
4116
|
+
button.dataset.tooltip = label; button.setAttribute('aria-label',label); button.setAttribute('aria-pressed',String(active));
|
|
4117
|
+
};
|
|
4118
|
+
syncPreferences = event => {
|
|
4119
|
+
if (event.key === themeKey || event.key === null) {
|
|
4120
|
+
this.themePreference = stored(themeKey);
|
|
4121
|
+
this.applyTheme();
|
|
4122
|
+
}
|
|
4123
|
+
if (event.key === previewFontKey || event.key === null) this.applyPreviewFontSize(stored(previewFontKey));
|
|
4124
|
+
};
|
|
4125
|
+
applyPreviewFontSize(size) {
|
|
4126
|
+
if (!Number.isInteger(size) || size < minPreviewFontSize || size > maxPreviewFontSize) size = defaultPreviewFontSize;
|
|
4127
|
+
const previous = this.previewFontSize;
|
|
4128
|
+
if (previous === size) return;
|
|
4129
|
+
const files = this.filesPanel, content = files?.content;
|
|
4130
|
+
const top = content?.querySelector('pre.code') ? content.scrollTop : 0;
|
|
4131
|
+
this.previewFontSize = size;
|
|
4132
|
+
this.style.setProperty('--workspace-preview-font-size',`${size}px`);
|
|
4133
|
+
if (previous && top > 0) content.scrollTop = top*size/previous;
|
|
4134
|
+
files?.updatePreviewZoom();
|
|
4135
|
+
files?.updateDiffNavigation();
|
|
4136
|
+
this.annotations?.refresh();
|
|
4137
|
+
}
|
|
4138
|
+
setPreviewFontSize(size) {
|
|
4139
|
+
this.applyPreviewFontSize(size);
|
|
4140
|
+
put(previewFontKey,size);
|
|
4141
|
+
}
|
|
4142
|
+
zoomPreviewText = event => {
|
|
4143
|
+
if (event.defaultPrevented || !(event.ctrlKey || event.metaKey) || event.altKey || event.isComposing) return;
|
|
4144
|
+
const delta = event.key === '-' ? -1 : event.key === '+' || event.key === '=' ? 1 : 0;
|
|
4145
|
+
if (!delta) return;
|
|
4146
|
+
const files = this.filesPanel, content = files?.content, target = event.target;
|
|
4147
|
+
if (!content?.clientHeight || !files.hasTextPreview()) return;
|
|
4148
|
+
if (target?.closest?.('input,textarea,select,[contenteditable]:not([contenteditable=false])') || this.querySelector('dialog[open]')) return;
|
|
4149
|
+
const hover = (target === document.body || target === document.documentElement) && content.matches(':hover');
|
|
4150
|
+
if (target?.closest?.('workspace-files') !== files && !hover) return;
|
|
4151
|
+
event.preventDefault();
|
|
4152
|
+
const size = this.previewFontSize + delta;
|
|
4153
|
+
if (size < minPreviewFontSize || size > maxPreviewFontSize) return;
|
|
4154
|
+
this.setPreviewFontSize(size);
|
|
3097
4155
|
};
|
|
3098
4156
|
selectPane(pane) {
|
|
4157
|
+
this.setTaskPreview(false);
|
|
4158
|
+
if (!this.restoring && (pane === 'files' || pane === 'chat' && window.innerWidth > 950) && this.panelCollapsed(pane)) {
|
|
4159
|
+
this.setPanelCollapsed(pane,false);
|
|
4160
|
+
this.applyLayout();
|
|
4161
|
+
}
|
|
3099
4162
|
if (pane === this.dataset.pane) return;
|
|
3100
4163
|
const files = this.filesPanel, scrollers = this.paneScrollers();
|
|
3101
4164
|
files.saveScroll();
|
|
@@ -3103,6 +4166,7 @@
|
|
|
3103
4166
|
this.dataset.pane = pane;
|
|
3104
4167
|
files.syncFrames();
|
|
3105
4168
|
for (const button of this.querySelectorAll('[data-pane]')) button.setAttribute('aria-pressed',String(button.dataset.pane === pane));
|
|
4169
|
+
this.updateTaskSidebarButton();
|
|
3106
4170
|
files.restoreScroll();
|
|
3107
4171
|
for (const node of scrollers) {
|
|
3108
4172
|
const position = this.paneScrollPositions.get(node);
|
|
@@ -3128,6 +4192,20 @@
|
|
|
3128
4192
|
}
|
|
3129
4193
|
savedSessionChat(id) { return chatAnchor(stored('agentbot-workspace-task:'+id)?.chat); }
|
|
3130
4194
|
rightLayout() { const {sidebar,sidebarCollapsed,...right} = this.layout; return right; }
|
|
4195
|
+
panelCollapsed(panel) {
|
|
4196
|
+
const draft = this.sessions?.newDraft;
|
|
4197
|
+
if (draft && panel === 'files') return draft.filesCollapsed !== false;
|
|
4198
|
+
if (draft && panel === 'chat') return Boolean(draft.chatCollapsed);
|
|
4199
|
+
return Boolean(this.layout[panel+'Collapsed']);
|
|
4200
|
+
}
|
|
4201
|
+
setPanelCollapsed(panel,collapsed) {
|
|
4202
|
+
const draft = this.sessions?.newDraft;
|
|
4203
|
+
const key = panel+'Collapsed';
|
|
4204
|
+
if (draft && (panel === 'files' || panel === 'chat')) {
|
|
4205
|
+
draft[key] = collapsed;
|
|
4206
|
+
if (panel === 'files') this.sessions.saveNewTaskDraft();
|
|
4207
|
+
} else this.layout[key] = collapsed;
|
|
4208
|
+
}
|
|
3131
4209
|
createFilesPanel(taskId, fileApi, projectRoot) {
|
|
3132
4210
|
const files = document.createElement('workspace-files');
|
|
3133
4211
|
files.taskId = taskId; files.fileApi = fileApi;
|
|
@@ -3152,7 +4230,7 @@
|
|
|
3152
4230
|
this.filesPanel = files;
|
|
3153
4231
|
this.initTreeStorage(files.treeRoot,files.taskId);
|
|
3154
4232
|
if (files.panelLayout) this.layout = {...this.globalLayout(),...files.panelLayout};
|
|
3155
|
-
files.hidden = false; files.setAddressPickerVisible(true);
|
|
4233
|
+
files.hidden = false; files.setAddressPickerVisible(true); files.updatePreviewZoom();
|
|
3156
4234
|
this.statusChanged({target:files,detail:files.lastStatus || {label:'只读',repository:false}});
|
|
3157
4235
|
this.watchFiles(files);
|
|
3158
4236
|
}
|
|
@@ -3242,6 +4320,7 @@
|
|
|
3242
4320
|
this.restoreFilesPanel(nav.position,href || this.taskRouteUrl(task.id,list),pane);
|
|
3243
4321
|
if (!this.savedTreeModes.has(files.listMode)) void files.revealCurrentFile(true);
|
|
3244
4322
|
} else if (!nav.initial && (!nav.history || !this.restoreUrl(true,nav.position,nav.href,false,pane))) this.selectPane(pane);
|
|
4323
|
+
if (typeof nav.sentDraft?.filesCollapsed === 'boolean') this.layout.filesCollapsed = nav.sentDraft.filesCollapsed;
|
|
3245
4324
|
this.updateProjectHeading(task.project.name,task.project.root);
|
|
3246
4325
|
if (previous !== files) this.applyLayout();
|
|
3247
4326
|
render();
|
|
@@ -3339,44 +4418,165 @@
|
|
|
3339
4418
|
if (original) url.searchParams.set('original',original);
|
|
3340
4419
|
return url.href;
|
|
3341
4420
|
}
|
|
3342
|
-
openChatFile(entry,kind,hash,source,original) {
|
|
4421
|
+
openChatFile(entry,kind,hash,source,original,patch) {
|
|
3343
4422
|
const files = this.filesPanel;
|
|
3344
|
-
if (!this.taskId || !files.previewApi(source) || source && !files.previewRoot(source)) return;
|
|
4423
|
+
if (!this.taskId || !patch && (!files.previewApi(source) || source && !files.previewRoot(source))) return;
|
|
3345
4424
|
this.navigate(() => {
|
|
3346
4425
|
this.selectPane('files');
|
|
3347
|
-
|
|
3348
|
-
files.openFile(entry,kind,original,hash,undefined,source);
|
|
4426
|
+
files.openFile(entry,kind,original,hash,undefined,source,patch);
|
|
3349
4427
|
});
|
|
3350
4428
|
}
|
|
3351
4429
|
paneScrollers() { return [...this.querySelectorAll('workspace-task-list,.chat-body,workspace-chat textarea'),this.filesPanel.tabBar]; }
|
|
4430
|
+
mediumLayout() { return !embedded && window.innerWidth > 650 && window.innerWidth <= 950; }
|
|
4431
|
+
layoutResize = () => {
|
|
4432
|
+
const previousWidth = this.layoutWidth, pane = this.dataset.pane;
|
|
4433
|
+
this.layoutWidth = window.innerWidth;
|
|
4434
|
+
const widening = !embedded && previousWidth > 650 && previousWidth <= 950 && this.layoutWidth > 950;
|
|
4435
|
+
const reveal = widening && (pane === 'chat' || pane === 'files') && this.panelCollapsed(pane);
|
|
4436
|
+
if (reveal) this.setPanelCollapsed(pane,false);
|
|
4437
|
+
if (previousWidth > 950 && this.mediumLayout()) {
|
|
4438
|
+
if (this.panelCollapsed('chat')) this.selectPane('files');
|
|
4439
|
+
else if (pane !== 'chat' && (this.taskId || this.sessions?.newDraft)) this.selectPane('chat');
|
|
4440
|
+
}
|
|
4441
|
+
this.applyLayout();
|
|
4442
|
+
if (reveal || pane !== this.dataset.pane) this.queuePersist();
|
|
4443
|
+
};
|
|
4444
|
+
applyTaskSidebarWidth(requested = this.taskSidebarWidth) {
|
|
4445
|
+
const width = this.querySelector('.workspace-layout').clientWidth || window.innerWidth;
|
|
4446
|
+
const min = 180, max = Math.max(min,Math.min(400,width-321));
|
|
4447
|
+
const preferred = Number.isFinite(requested) ? requested : Math.max(220,Math.min(280,width*.3));
|
|
4448
|
+
const size = Math.round(Math.max(min,Math.min(preferred,max)));
|
|
4449
|
+
this.style.setProperty('--task-sidebar-width',size+'px');
|
|
4450
|
+
this.taskSplitter.setAttribute('aria-valuemin',String(min));
|
|
4451
|
+
this.taskSplitter.setAttribute('aria-valuemax',String(max));
|
|
4452
|
+
this.taskSplitter.setAttribute('aria-valuenow',String(size));
|
|
4453
|
+
return size;
|
|
4454
|
+
}
|
|
4455
|
+
setTaskPreview(open) {
|
|
4456
|
+
clearTimeout(this.taskPreviewTimer);
|
|
4457
|
+
const state = this.dataset.taskSidebar;
|
|
4458
|
+
if (state === 'pinned' || open === (state === 'preview')) return;
|
|
4459
|
+
this.dataset.taskSidebar = open ? 'preview' : 'closed';
|
|
4460
|
+
if (!open) {
|
|
4461
|
+
if (this.taskSplitter.classList.contains('is-dragging')) this.endDrag?.();
|
|
4462
|
+
if (this.taskSidebar.contains(document.activeElement) || this.taskSplitter === document.activeElement) {
|
|
4463
|
+
this.taskToggle.focus({preventScroll:true});
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
this.updateTaskSidebarButton();
|
|
4467
|
+
}
|
|
4468
|
+
deferTaskPreviewClose() {
|
|
4469
|
+
if (this.dataset.taskSidebar !== 'preview' || this.taskSplitter.classList.contains('is-dragging')) return;
|
|
4470
|
+
clearTimeout(this.taskPreviewTimer);
|
|
4471
|
+
this.taskPreviewTimer = setTimeout(() => {
|
|
4472
|
+
const hovered = this.scrollbars.hovered, focused = document.activeElement;
|
|
4473
|
+
if (!this.taskSidebar.contains(focused) && !this.taskSidebar.contains(this.annotations?.referenceTrigger ?? null)
|
|
4474
|
+
&& focused !== this.taskSplitter && !hovered.has(this.taskSidebar)
|
|
4475
|
+
&& !hovered.has(this.taskSplitter) && !hovered.has(this.taskToggle)) this.setTaskPreview(false);
|
|
4476
|
+
},150);
|
|
4477
|
+
}
|
|
4478
|
+
dismissTaskPreview = event => {
|
|
4479
|
+
if (!event.defaultPrevented && event.key === 'Escape' && this.dataset.taskSidebar === 'preview') {
|
|
4480
|
+
event.preventDefault(); this.setTaskPreview(false);
|
|
4481
|
+
}
|
|
4482
|
+
};
|
|
4483
|
+
toggleTaskSidebar() {
|
|
4484
|
+
if (!this.mediumLayout()) { this.togglePanel('sidebar'); return; }
|
|
4485
|
+
if (this.dataset.pane === 'tasks') { this.navigate(() => this.selectPane('chat')); return; }
|
|
4486
|
+
const pin = this.dataset.taskSidebar !== 'pinned';
|
|
4487
|
+
clearTimeout(this.taskPreviewTimer);
|
|
4488
|
+
this.changeLayout(() => {
|
|
4489
|
+
this.dataset.taskSidebar = pin ? 'pinned' : 'closed';
|
|
4490
|
+
put(taskSidebarKey,pin);
|
|
4491
|
+
});
|
|
4492
|
+
}
|
|
4493
|
+
updateTaskSidebarButton() {
|
|
4494
|
+
const medium = this.mediumLayout(), taskView = this.dataset.pane === 'tasks';
|
|
4495
|
+
const pinned = this.dataset.taskSidebar === 'pinned', preview = this.dataset.taskSidebar === 'preview';
|
|
4496
|
+
const expanded = medium ? taskView || pinned || preview : !this.layout.sidebarCollapsed;
|
|
4497
|
+
const taskLabel = medium ? (taskView || pinned ? '收起任务侧栏' : '固定任务侧栏')
|
|
4498
|
+
: (expanded ? '折叠任务侧栏' : '展开任务侧栏');
|
|
4499
|
+
const glyph = medium ? 'tasks' : 'sidebar';
|
|
4500
|
+
if (this.taskToggle.dataset.glyph !== glyph) {
|
|
4501
|
+
this.taskToggle.dataset.glyph = glyph; this.taskToggle.replaceChildren(icon(glyph));
|
|
4502
|
+
}
|
|
4503
|
+
this.taskToggle.dataset.tooltip = taskLabel; this.taskToggle.setAttribute('aria-label',taskLabel);
|
|
4504
|
+
this.taskToggle.setAttribute('aria-expanded',String(expanded));
|
|
4505
|
+
this.taskToggle.setAttribute('aria-pressed',String(medium ? taskView || pinned : expanded));
|
|
4506
|
+
}
|
|
3352
4507
|
route() {
|
|
3353
4508
|
const files = this.filesPanel, tab = files.tabs.get(files.activeKey);
|
|
3354
|
-
return {task:files.taskId,pane:this.dataset.pane,listMode:files.listMode,view:files.dataset.view,tab:tab?{id:tab.key,path:tab.path,kind:tab.kind,original:tab.original,mode:tab.mode,hash:tab.hash,directoryEntry:tab.directoryEntry,source:tab.source}:null};
|
|
4509
|
+
return {task:files.taskId,pane:this.dataset.pane,listMode:files.listMode,view:files.dataset.view,tab:tab?{id:tab.key,path:tab.path,kind:tab.kind,original:tab.original,mode:tab.mode,patch:tab.patch,hash:tab.hash,directoryEntry:tab.directoryEntry,source:tab.source,sourceView:tab.sourceView}:null};
|
|
3355
4510
|
}
|
|
3356
4511
|
separator(panel, label) {
|
|
3357
4512
|
const node = element('div',undefined,'workspace-separator'); node.dataset.panel = panel; node.tabIndex = 0;
|
|
3358
4513
|
node.setAttribute('role','separator'); node.setAttribute('aria-orientation','vertical'); node.setAttribute('aria-label',label);
|
|
3359
4514
|
node.dataset.tooltipShortcut = '← / →'; node.setAttribute('aria-keyshortcuts','ArrowLeft ArrowRight');
|
|
4515
|
+
const mediumTasks = () => panel === 'sidebar' && this.mediumLayout();
|
|
4516
|
+
const width = () => (panel === 'explorer' ? this.filesPanel.querySelector('.file-explorer')
|
|
4517
|
+
: this.querySelector(panel === 'sidebar'?'workspace-task-list':'workspace-chat')).getBoundingClientRect().width;
|
|
3360
4518
|
const change = delta => {
|
|
3361
|
-
|
|
3362
|
-
|
|
4519
|
+
this.layout[panel] = width() + (panel === 'explorer'?-delta:delta); this.applyLayout(); this.queuePersist();
|
|
4520
|
+
};
|
|
4521
|
+
const storeTaskWidth = () => {
|
|
4522
|
+
if (Number.isFinite(this.taskSidebarWidth)) put(taskSidebarWidthKey,this.taskSidebarWidth);
|
|
4523
|
+
};
|
|
4524
|
+
node.onkeydown = event => {
|
|
4525
|
+
if (!['ArrowLeft','ArrowRight'].includes(event.key)) return;
|
|
4526
|
+
event.preventDefault();
|
|
4527
|
+
const delta = event.key === 'ArrowRight' ? 16 : -16;
|
|
4528
|
+
if (mediumTasks()) {
|
|
4529
|
+
this.taskSidebarWidth = this.applyTaskSidebarWidth(width()+delta);
|
|
4530
|
+
storeTaskWidth();
|
|
4531
|
+
} else change(delta);
|
|
3363
4532
|
};
|
|
3364
|
-
node.onkeydown = event => { if (['ArrowLeft','ArrowRight'].includes(event.key)) { event.preventDefault(); change(event.key === 'ArrowRight'?16:-16); } };
|
|
3365
4533
|
node.onpointerdown = event => {
|
|
3366
4534
|
if (event.button !== 0) return;
|
|
3367
4535
|
event.preventDefault(); this.endDrag?.(); node.setPointerCapture(event.pointerId);
|
|
4536
|
+
const resizeTasks = mediumTasks(), startWidth = resizeTasks ? width() : undefined;
|
|
4537
|
+
if (resizeTasks) clearTimeout(this.taskPreviewTimer);
|
|
3368
4538
|
let x = event.clientX; this.classList.add('is-resizing'); node.classList.add('is-dragging');
|
|
3369
|
-
const move = next => {
|
|
3370
|
-
|
|
4539
|
+
const move = next => {
|
|
4540
|
+
if (next.pointerId !== event.pointerId) return;
|
|
4541
|
+
if (resizeTasks !== mediumTasks()) { end(next); return; }
|
|
4542
|
+
if (resizeTasks) {
|
|
4543
|
+
this.taskSidebarWidth = this.applyTaskSidebarWidth(startWidth+next.clientX-event.clientX);
|
|
4544
|
+
} else {
|
|
4545
|
+
const delta = next.clientX-x; x = next.clientX; change(delta);
|
|
4546
|
+
}
|
|
4547
|
+
};
|
|
4548
|
+
const end = next => {
|
|
4549
|
+
if (next && next.pointerId !== event.pointerId) return;
|
|
4550
|
+
this.classList.remove('is-resizing'); node.classList.remove('is-dragging');
|
|
4551
|
+
window.removeEventListener('pointermove',move); window.removeEventListener('pointerup',end); window.removeEventListener('pointercancel',end);
|
|
4552
|
+
if (node.hasPointerCapture?.(event.pointerId)) node.releasePointerCapture(event.pointerId);
|
|
4553
|
+
this.endDrag = undefined;
|
|
4554
|
+
if (!this.isConnected) return;
|
|
4555
|
+
if (resizeTasks) { storeTaskWidth(); this.deferTaskPreviewClose(); }
|
|
4556
|
+
else this.persistHistory();
|
|
4557
|
+
};
|
|
3371
4558
|
this.endDrag = end; window.addEventListener('pointermove',move); window.addEventListener('pointerup',end); window.addEventListener('pointercancel',end);
|
|
3372
4559
|
};
|
|
3373
4560
|
return node;
|
|
3374
4561
|
}
|
|
3375
4562
|
togglePanel(panel) {
|
|
4563
|
+
this.changeLayout(() => {
|
|
4564
|
+
const collapsed = !this.panelCollapsed(panel);
|
|
4565
|
+
this.setPanelCollapsed(panel,collapsed);
|
|
4566
|
+
if (panel === 'chat' && collapsed) {
|
|
4567
|
+
if (this.panelCollapsed('files')) this.setPanelCollapsed('files',false);
|
|
4568
|
+
this.selectPane('files');
|
|
4569
|
+
} else if (panel === 'files' && collapsed && this.panelCollapsed('chat')) {
|
|
4570
|
+
this.setPanelCollapsed('chat',false);
|
|
4571
|
+
this.selectPane('chat');
|
|
4572
|
+
}
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
changeLayout(change) {
|
|
3376
4576
|
const files = this.filesPanel, scrollers = this.paneScrollers();
|
|
3377
4577
|
files.saveScroll();
|
|
3378
4578
|
for (const node of scrollers) if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
3379
|
-
|
|
4579
|
+
change(); this.applyLayout(); files.restoreScroll();
|
|
3380
4580
|
for (const node of scrollers) {
|
|
3381
4581
|
const position = this.paneScrollPositions.get(node);
|
|
3382
4582
|
if (position && node.clientHeight > 0) { node.scrollTop = position.top; if (node === files.tabBar) files.scrollTabs(position.left); else node.scrollLeft = position.left; }
|
|
@@ -3390,24 +4590,31 @@
|
|
|
3390
4590
|
const width = this.querySelector('.workspace-layout').clientWidth || window.innerWidth;
|
|
3391
4591
|
const sidebar = this.layout.sidebarCollapsed ? 0 : clamp(this.layout.sidebar ?? width*.16,140,Math.min(400,Math.max(140,width-600)));
|
|
3392
4592
|
const chat = clamp(this.layout.chat ?? (width-sidebar)*.4,200,Math.max(200,width-sidebar-402));
|
|
4593
|
+
if (this.layout.filesCollapsed && this.layout.chatCollapsed) this.layout.chatCollapsed = false;
|
|
4594
|
+
const filesCollapsed = this.panelCollapsed('files'), chatCollapsed = this.panelCollapsed('chat') && !filesCollapsed;
|
|
3393
4595
|
this.style.setProperty('--sidebar-size',sidebar+'px'); this.style.setProperty('--chat-size',chat+'px');
|
|
3394
|
-
this.dataset.sidebarCollapsed = String(Boolean(this.layout.sidebarCollapsed)); this.dataset.filesCollapsed = String(
|
|
3395
|
-
|
|
4596
|
+
this.dataset.sidebarCollapsed = String(Boolean(this.layout.sidebarCollapsed)); this.dataset.filesCollapsed = String(filesCollapsed); files.dataset.explorerCollapsed = String(Boolean(this.layout.explorerCollapsed));
|
|
4597
|
+
this.dataset.chatCollapsed = String(chatCollapsed);
|
|
4598
|
+
files.updateFileExpansion(chatCollapsed);
|
|
4599
|
+
const available = files.clientWidth || Math.max(400,width-sidebar-(chatCollapsed ? 0 : chat)-2), explorer = clamp(this.layout.explorer ?? available*.32,120,Math.max(120,Math.min(600,available-161)));
|
|
3396
4600
|
files.style.setProperty('--explorer-size',explorer+'px');
|
|
3397
4601
|
for (const [panel,size,min,max] of [['sidebar',sidebar,140,400],['chat',chat,200,Math.max(200,width-sidebar-402)],['explorer',explorer,120,Math.max(120,available-161)]]) {
|
|
3398
4602
|
const splitter = (panel === 'explorer' ? files : this).querySelector('.workspace-separator[data-panel='+panel+']'); splitter.setAttribute('aria-valuenow',String(Math.round(size))); splitter.setAttribute('aria-valuemin',String(min)); splitter.setAttribute('aria-valuemax',String(Math.round(max)));
|
|
3399
4603
|
if (this.layout[panel] !== undefined && (panel === 'explorer'?window.innerWidth>650:window.innerWidth>950) && !this.layout[panel+'Collapsed']) this.layout[panel] = size;
|
|
3400
4604
|
}
|
|
3401
|
-
for (const panel of ['
|
|
3402
|
-
const
|
|
3403
|
-
button.dataset.tooltip = (collapsed?'展开':'折叠')+
|
|
4605
|
+
for (const [panel,button,label] of [['files',this.querySelector('.toggle-files'),'文件工作区'],['explorer',files.explorerToggle,'文件列表']]) {
|
|
4606
|
+
const collapsed = panel === 'files' ? filesCollapsed : Boolean(this.layout.explorerCollapsed);
|
|
4607
|
+
button.dataset.tooltip = (collapsed?'展开':'折叠')+label; button.setAttribute('aria-label',button.dataset.tooltip); button.setAttribute('aria-pressed',String(!collapsed));
|
|
3404
4608
|
}
|
|
4609
|
+
if (this.mediumLayout()) this.applyTaskSidebarWidth();
|
|
4610
|
+
else this.setTaskPreview(false);
|
|
4611
|
+
this.updateTaskSidebarButton();
|
|
3405
4612
|
files.syncFrames();
|
|
3406
4613
|
files.resizeTabs();
|
|
3407
4614
|
}
|
|
3408
4615
|
rememberPosition() {
|
|
3409
|
-
const files = this.filesPanel; files.saveScroll();
|
|
3410
|
-
const position = {listScrollTop:files.listScrollTop,treeDirectory:files.explorerDirectory || undefined,
|
|
4616
|
+
const files = this.filesPanel; files.saveScroll();
|
|
4617
|
+
const position = {listScrollTop:files.listScrollTop,treeDirectory:files.explorerDirectory || undefined,chat:this.taskId ? this.sessions?.position() : undefined};
|
|
3411
4618
|
this.positions.set(this.historyIndex,position); return position;
|
|
3412
4619
|
}
|
|
3413
4620
|
historyState() { return {workspace:historyScope,index:this.historyIndex,maximum:this.historyMaximumKnown?this.historyMaximum:undefined,guarded:this.historyGuard,route:this.route(),position:this.rememberPosition(),url:this.stateUrl()}; }
|
|
@@ -3438,25 +4645,30 @@
|
|
|
3438
4645
|
url.searchParams.set('tab',route.tab.id);
|
|
3439
4646
|
if (route.tab.kind !== 'file') url.searchParams.set('kind',route.tab.kind);
|
|
3440
4647
|
if (route.tab.mode !== 'all') url.searchParams.set('mode',route.tab.mode);
|
|
4648
|
+
if (route.tab.patch) url.searchParams.set('patch',route.tab.patch);
|
|
3441
4649
|
if (route.tab.original) url.searchParams.set('original',route.tab.original);
|
|
3442
4650
|
if (route.tab.directoryEntry) url.searchParams.set('directoryFile',route.tab.directoryEntry);
|
|
3443
4651
|
if (route.tab.source) url.searchParams.set('sourceDir',route.tab.source);
|
|
4652
|
+
if (route.tab.sourceView) url.searchParams.set('source','1');
|
|
3444
4653
|
if (route.view !== 'content') url.searchParams.set('view',route.view);
|
|
3445
4654
|
} else if (route.view !== 'list') url.searchParams.set('view',route.view);
|
|
3446
4655
|
const tabs = [...files.tabs.values()].map(tab => {
|
|
3447
4656
|
const value = {id:tab.key,path:tab.path};
|
|
4657
|
+
if (files.pinnedTabs.has(tab.key)) value.pinned = true;
|
|
3448
4658
|
if (tab.kind !== 'file') value.kind = tab.kind;
|
|
3449
4659
|
if (tab.mode !== 'all') value.mode = tab.mode;
|
|
4660
|
+
if (tab.patch) value.patch = tab.patch;
|
|
3450
4661
|
if (tab.original) value.original = tab.original;
|
|
3451
4662
|
if (tab.directoryEntry) value.directoryEntry = tab.directoryEntry;
|
|
3452
4663
|
if (tab.source) value.source = tab.source;
|
|
4664
|
+
if (tab.sourceView) value.sourceView = true;
|
|
3453
4665
|
if (tab.scrollTop > 0) value.scrollTop = tab.scrollTop;
|
|
3454
4666
|
if (tab.scrollLeft > 0) value.scrollLeft = tab.scrollLeft;
|
|
3455
4667
|
if (tab.hash) value.hash = tab.hash;
|
|
3456
4668
|
if (tab.requestedHash) value.requestedHash = tab.requestedHash;
|
|
3457
4669
|
return value;
|
|
3458
4670
|
});
|
|
3459
|
-
if (tabs.length !== (route.tab?1:0) || tabs.some(tab => tab.scrollTop || tab.scrollLeft || tab.hash || tab.requestedHash)) extra.tabs = tabs;
|
|
4671
|
+
if (tabs.length !== (route.tab?1:0) || tabs.some(tab => tab.pinned || tab.scrollTop || tab.scrollLeft || tab.hash || tab.requestedHash)) extra.tabs = tabs;
|
|
3460
4672
|
if (files.recentTabs.length > 1) extra.recentTabs = files.recentTabs;
|
|
3461
4673
|
const trees = {};
|
|
3462
4674
|
if (files.explorerDirectory) extra.treeDirectory = files.explorerDirectory;
|
|
@@ -3489,7 +4701,10 @@
|
|
|
3489
4701
|
this.persistTrees();
|
|
3490
4702
|
if (embedded) this.embeddedHistory.set(this.historyIndex,state);
|
|
3491
4703
|
if (this.taskId) put('agentbot-workspace-task:'+this.taskId,{root:this.filesPanel.projectRoot,href:url,chat:state.position.chat});
|
|
3492
|
-
|
|
4704
|
+
const current = window.history.state;
|
|
4705
|
+
if (current?.workspace !== historyScope || current.url !== url || current.index !== this.historyIndex || current.route?.pane !== state.route.pane) {
|
|
4706
|
+
window.history.replaceState(state,'',url);
|
|
4707
|
+
}
|
|
3493
4708
|
this.syncedUrl = url; this.historyRoutes.set(this.historyIndex,state.route); this.updateNavigation();
|
|
3494
4709
|
};
|
|
3495
4710
|
navigate(action, replace = false) {
|
|
@@ -3576,6 +4791,7 @@
|
|
|
3576
4791
|
saved.route.task = files.taskId;
|
|
3577
4792
|
if (!files.fileApi) {
|
|
3578
4793
|
const allowed = tab => appBase && (['new','web'].includes(tab.kind)
|
|
4794
|
+
|| tab.patch && files.taskId
|
|
3579
4795
|
|| tab.kind === 'directory' && (isLocalDirectory(tab.path) || files.taskDirectories?.length)
|
|
3580
4796
|
|| tab.source && files.previewRoot(tab.source));
|
|
3581
4797
|
const tab = saved.route.tab;
|
|
@@ -3590,14 +4806,35 @@
|
|
|
3590
4806
|
if (merge) {
|
|
3591
4807
|
const tab = saved.tabs.find(tab => tab.id === activeKey), previous = files.tabs.get(activeKey);
|
|
3592
4808
|
if (tab) {
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
4809
|
+
const {scrollTop,scrollLeft,requestedHash: _request,...target} = tab;
|
|
4810
|
+
const view = files.tabView(activeKey,tab.path,tab.kind,tab.original,tab.source,tab.patch);
|
|
4811
|
+
const scopeChanged = tab.kind === 'diff' && diffScrollKey(view) !== diffScrollKey(tab);
|
|
4812
|
+
const sourceChanged = tab.kind === 'file' && view.sourceView !== tab.sourceView;
|
|
4813
|
+
const sameFile = files.activeKey === activeKey && previous === view && ['file','diff'].includes(tab.kind);
|
|
4814
|
+
const jump = sameFile && (scopeChanged || sourceChanged || previous.hash !== tab.hash) || !scopeChanged && !sourceChanged && view.requestedHash === tab.hash;
|
|
4815
|
+
if (scopeChanged) [view.scrollTop,view.scrollLeft] = view.diffScroll?.get(diffScrollKey(tab)) ?? [scrollTop,scrollLeft];
|
|
4816
|
+
if (sourceChanged) [view.scrollTop,view.scrollLeft] = view.fileScroll?.get(Boolean(tab.sourceView)) ?? [scrollTop,scrollLeft];
|
|
4817
|
+
if (files.activeKey === activeKey && (previous !== view || previous.mode !== tab.mode || sourceChanged
|
|
4818
|
+
|| previous.original !== tab.original || previous.directoryEntry !== tab.directoryEntry || previous.patch !== tab.patch)) files.renderedKey = undefined;
|
|
4819
|
+
files.tabs.set(activeKey,Object.assign(view,target,{requestedHash:jump ? tab.hash : undefined}));
|
|
3596
4820
|
}
|
|
3597
4821
|
if (local) saved.route.listMode = files.listMode;
|
|
3598
4822
|
} else {
|
|
3599
|
-
this.layout = {...(appBase ? this.globalLayout() : {}),...saved.layout};
|
|
3600
|
-
|
|
4823
|
+
this.layout = {...(appBase ? this.globalLayout() : {}),...saved.layout};
|
|
4824
|
+
if (files.taskId && this.layout.filesCollapsed === undefined) {
|
|
4825
|
+
const previous = stored('agentbot-workspace-task:'+files.taskId);
|
|
4826
|
+
let wasOpen = false;
|
|
4827
|
+
if (typeof previous?.href === 'string' && previous.root === files.projectRoot) {
|
|
4828
|
+
try {
|
|
4829
|
+
const {layout} = readUrlState(previous.href);
|
|
4830
|
+
wasOpen = layout.filesCollapsed === false || layout.chatCollapsed === true;
|
|
4831
|
+
} catch { /* Ignore an invalid saved task URL. */ }
|
|
4832
|
+
}
|
|
4833
|
+
this.layout.filesCollapsed = saved.route.pane !== 'files' && !saved.layout.chatCollapsed && !wasOpen;
|
|
4834
|
+
}
|
|
4835
|
+
this.applyLayout();
|
|
4836
|
+
files.tabs = new Map(saved.tabs.map(tab => [tab.id,Object.assign(files.tabView(tab.id,tab.path,tab.kind,tab.original,tab.source,tab.patch),tab)])); files.recentTabs = (saved.recentTabs || []).filter(key => files.tabs.has(key));
|
|
4837
|
+
files.pinnedTabs = new Set(saved.tabs.filter(tab => tab.pinned).map(tab => tab.id));
|
|
3601
4838
|
const trees = {};
|
|
3602
4839
|
for (const mode of ['files','changes']) {
|
|
3603
4840
|
const value = this.treeStates[mode] || {};
|
|
@@ -3609,9 +4846,8 @@
|
|
|
3609
4846
|
if (merge) for (const node of this.paneScrollers()) if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
3610
4847
|
this.selectPane(saved.route.pane);
|
|
3611
4848
|
const tree = files.navigationView(saved.route.listMode);
|
|
3612
|
-
const
|
|
3613
|
-
|
|
3614
|
-
files.restoreView(saved.route,target);
|
|
4849
|
+
const listScrollTop = !merge && position?.treeDirectory === (files.explorerDirectory || undefined) ? position?.listScrollTop : undefined;
|
|
4850
|
+
files.restoreView(saved.route,listScrollTop ?? (tree.query?tree.filterScrollTop:tree.scrollTop) ?? 0);
|
|
3615
4851
|
if (!merge) for (const [name,selector] of [['tasks','workspace-task-list'],['chat','.chat-body'],['composer','workspace-chat textarea'],['tabs','.file-tabs']]) {
|
|
3616
4852
|
const node = name === 'tabs' ? files.tabBar : this.querySelector(selector), values = saved.scroll[name];
|
|
3617
4853
|
if (node && values) { this.paneScrollPositions.set(node,{top:values[0],left:values[1]}); if (node === files.tabBar) files.scrollTabs(values[1]); if (node.clientHeight > 0) { node.scrollTop = values[0]; if (node !== files.tabBar) node.scrollLeft = values[1]; } }
|