feat: 拦截聊天区文件打开 — 聊天里的文件点击默认开进侧边栏编辑器
包装 ctx.workspaces.openPath(聊天区文件打开的唯一漏斗),接管时 经 openSidebarFile 开进 sidebar 编辑器而非系统默认应用;由 interceptOpenPath pref(默认开)与 editor tab 启用态双重门控, 拒接时原样放行,dispose 还原原始方法引用(HMR 安全)。 - prefs-shared/config/prefs: 新增 interceptOpenPath 字段(默认 true) - openpath-intercept.ts: 零依赖包装器,纯插件层面实现,不改 DSH - intercept.tsx: registerOpenPathInterception 接线(当前会话 scope) - SideCardSection: 常规区新增开关卡片(zh/en 文案) - 测试: 包装器单测 6 个 + 接线集成测试 + pref 解析/设置页断言更新
This commit is contained in:
1 parent
8f3bb1b264
commit
67ec136e98
13 files changed
+298
-12
No files matched your search
@@ -11,6 +11,7 @@ import type { Context } from '../context-types.ts'
|
||||
import type { SidebarStore } from './state.ts'
|
||||
import { t } from './locales.ts'
|
||||
import { resolveSidebarPath, selectProducedFiles } from './produced-files.ts'
|
||||
import { wrapOpenPath } from './openpath-intercept.ts'
|
||||
import css from './sidebar.module.css'
|
||||
|
||||
/** Open a file in the sidebar's editor (used by the intercepted row and the explorer). */
|
||||
@@ -74,3 +75,20 @@ export function registerTurnTailInterception(ctx: Context, store: SidebarStore):
|
||||
}),
|
||||
}, SidebarProducedFiles)
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the chat file-open interception: wraps `ctx.workspaces.openPath`
|
||||
* — the single funnel every chat-side file open goes through (tool-row path
|
||||
* links, the produced-files row, prose mentions) — so opens land in the
|
||||
* sidebar editor instead of the Host OS. Gated by BOTH the `interceptOpenPath`
|
||||
* pref and the editor tab's enable switch; declined opens fall through to
|
||||
* the original method. Returns the disposer restoring the original (HMR-safe).
|
||||
*/
|
||||
export function registerOpenPathInterception(ctx: Context, store: SidebarStore): () => void {
|
||||
return wrapOpenPath(ctx.workspaces, {
|
||||
takeoverEnabled: () => store.getPrefs().interceptOpenPath !== false
|
||||
&& store.getPrefs().tabsEnabled['editor'] !== false,
|
||||
currentSessionId: () => ctx.sessions.list.getSnapshot().current,
|
||||
openInSidebar: (path, sessionId) => { openSidebarFile(ctx, store, sessionId, path) },
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user