feat: rename settings section to Better Chat and make approval shortcuts configurable
The settings section is now 'Better Chat' in both dictionaries. Approval key bindings are configurable in that section and persisted under dsh.better-chat.v1: click a keycap and press the new combination. Allow-type actions stay on Enter and reject on Esc; modifiers are free. Always-allow can be cleared, and a restore-defaults button resets everything. Invalid base keys, modifier-less always-allow and conflicts are rejected with inline copy. The approval routing and the key hint read the live bindings, and saving dispatches better-chat:bindings-changed so the card hint rebuilds without a restart. Adds bindings tests and extends the approval/key-hint tests; version 0.4.2.
This commit is contained in:
parent
a4844006a6
commit
6ed202f029
|
|
@ -1,5 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## 0.4.2 — 2026-11-12
|
||||
|
||||
- 设置页的 **Better Display** 选项栏改名为 **Better Chat**(中英文案同步)。
|
||||
- 审批快捷键可自定义并写入插件配置(持久化键 `dsh.better-chat.v1`):允许(单次)/始终允许/拒绝三行,点键帽后按新组合键即可录制;基础键固定为 Enter(允许类)与 Esc(拒绝),修饰键自由,支持清除「始终允许」和恢复默认。冲突、缺少修饰键、用错基础键都会在设置页提示并拒绝保存。
|
||||
- 审批卡上的键帽提示与按键判定都读取实时配置:保存后卡片提示立即重建,无需重启 DSH。
|
||||
|
||||
## 0.4.1 — 2026-11-12
|
||||
|
||||
- 审批卡新增键盘提示(方案 A):操作行左侧显示 `Enter 允许(单次) · Ctrl+Enter 始终允许 · Esc 拒绝` 的键帽提示,文案直接取卡片按钮的实际文字;卡片作答后立即移除,React 重渲染后自动重建。鼠标不可点、不参与焦点,纯说明。
|
||||
|
|
|
|||
30
README.en.md
30
README.en.md
|
|
@ -30,29 +30,37 @@ tools and approvals remain.
|
|||
skins that hang the composer off that marker still show it.
|
||||
- ````mcp-app` code blocks in the final answer render as interactive cards inside
|
||||
`<iframe sandbox="allow-scripts allow-forms">`.
|
||||
- **Better Display** settings: preview deliverables in the right sidebar, frosted
|
||||
glass (off by default), auto-fold the process (on by default), and detect
|
||||
whether the `generative-mcpapps` skill is installed in the host skill roots.
|
||||
- **Better Chat** settings: preview deliverables in the right sidebar, frosted
|
||||
glass (off by default), auto-fold the process (on by default), approval-card
|
||||
shortcuts, and detect whether the `generative-mcpapps` skill is installed.
|
||||
- Upstream design notes, extension points and runbooks live in [`docs/`](docs/).
|
||||
|
||||
## Feature 2: Enter approves, Esc rejects on approval cards (v0.1.0, hints and always-allow chord in v0.4.1)
|
||||
## Feature 2: Enter approves, Esc rejects on approval cards (v0.1.0; hints in v0.4.1, customization in v0.4.2)
|
||||
|
||||
DSH's approval card handles Enter / Esc itself, but only when focus is already
|
||||
inside the card. This plugin adds:
|
||||
|
||||
1. **Auto-focus**: when an approval appears and the user is not typing elsewhere,
|
||||
focus moves into the card's detail region.
|
||||
2. **Document-level routing**: with focus outside the card, Enter clicks
|
||||
"Allow once" (never "Always allow") and Esc clicks "Reject".
|
||||
3. **Key hint**: the action row shows `Enter Allow once · Ctrl+Enter Always allow
|
||||
· Esc Reject` keycaps, using the card's real button labels. It disappears once
|
||||
the card is answered, is not focusable and is not clickable. macOS shows Cmd.
|
||||
2. **Document-level routing**: with focus outside the card, the configured key
|
||||
clicks "Allow once" (never "Always allow" by default) and Esc clicks "Reject".
|
||||
3. **Key hint**: the action row shows keycaps for the current bindings (default
|
||||
`Enter Allow once · Ctrl+Enter Always allow · Esc Reject`), using the card's
|
||||
real button labels. It disappears once answered, is not focusable and is not
|
||||
clickable. macOS shows Cmd instead of Ctrl.
|
||||
4. **Ctrl+Enter / Cmd+Enter = Always allow**, only when the card has the third
|
||||
button. The official card ignores modified keys, so this chord is handled here
|
||||
even while focus is inside the card. It never fires while typing in an input.
|
||||
5. **Customizable shortcuts**: Settings → Better Chat → Approval card shortcuts.
|
||||
Click a keycap and press the new combination. Allow-type actions stay on Enter,
|
||||
reject stays on Esc; modifiers are free. You can clear "Always allow" or
|
||||
restore defaults. Bindings persist under `dsh.better-chat.v1` and the card hint
|
||||
updates immediately — no restart needed.
|
||||
|
||||
It never intercepts while typing, with Shift/Alt, auto-repeat, IME composition,
|
||||
when Enter lands on another button or link, or when the card is answered.
|
||||
It never intercepts while typing, for a plain Enter/Esc when focus is inside the
|
||||
card, for modifier sets that do not match the current binding, on auto-repeat,
|
||||
during IME composition, when Enter lands on another button or link, or when the
|
||||
card is answered.
|
||||
|
||||
## Feature 3: permission UI (v0.2.0, tightened in v0.3.1)
|
||||
|
||||
|
|
|
|||
21
README.md
21
README.md
|
|
@ -25,25 +25,28 @@ dsh plugin --profile desktop add git+https://git.qyhhh.top/DeepsSeekHarness/dsh-
|
|||
- 阅读列保留宿主 ChatView 的 `data-chat-flow` 钩子,依赖该标记显示输入框的第三方
|
||||
皮肤不会把阅读页当成仅检视视图。
|
||||
- 最终回答里的 ````mcp-app` 代码块会挂成交互卡片(`<iframe sandbox="allow-scripts allow-forms">`)。
|
||||
- 设置里的 **Better Display**:产物右侧预览、半透明毛玻璃(默认关)、过程自动折叠
|
||||
(默认开),并检测 `generative-mcpapps` 技能是否已装进宿主技能目录。
|
||||
- 设置里的 **Better Chat**:产物右侧预览、半透明毛玻璃(默认关)、过程自动折叠
|
||||
(默认开)、审批卡快捷键,并检测 `generative-mcpapps` 技能是否已装进宿主技能目录。
|
||||
- 上游的设计说明、扩展点文档与开发 runbook 一并保留在 [`docs/`](docs/)。
|
||||
|
||||
## 功能二:审批卡片的回车批准 / Esc 拒绝(v0.1.0,v0.4.1 加提示与始终允许快捷键)
|
||||
## 功能二:审批卡片的回车批准 / Esc 拒绝(v0.1.0,v0.4.1 加提示,v0.4.2 快捷键可配置)
|
||||
|
||||
DSH 官方审批卡本身支持 Enter 批准、Esc 拒绝,但前提是焦点先落在卡内。本插件补上:
|
||||
|
||||
1. **自动送入焦点**:审批卡出现时,若没有正在别处输入,把焦点送进卡片详情区。
|
||||
2. **全局兜底路由**:焦点不在卡内时,在 document 捕获阶段接住回车 / Esc —— 回车
|
||||
永远点「允许(单次)」(不会误触「始终允许」),Esc 点「拒绝」。
|
||||
3. **键盘提示**:操作行左侧显示 `Enter 允许(单次) · Ctrl+Enter 始终允许 · Esc 拒绝`
|
||||
的键帽提示,文案取卡片按钮的实际文字,卡片作答后自动消失;只做说明,不占焦点、
|
||||
不可点击。Mac 上显示 Cmd+Enter。
|
||||
2. **全局兜底路由**:焦点不在卡内时,在 document 捕获阶段接住配置的快捷键 —— 默认
|
||||
回车点「允许(单次)」(不会误触「始终允许」),Esc 点「拒绝」。
|
||||
3. **键盘提示**:操作行左侧显示当前绑定的键帽提示(默认
|
||||
`Enter 允许(单次) · Ctrl+Enter 始终允许 · Esc 拒绝`),文案取卡片按钮的实际文字,
|
||||
卡片作答后自动消失;只做说明,不占焦点、不可点击。Mac 上 Ctrl 显示为 Cmd。
|
||||
4. **Ctrl+Enter / Cmd+Enter = 始终允许**:仅当卡片有第三个按钮时生效。官方卡片对带
|
||||
修饰键的按键不作答,所以这条即使在卡片内也由本插件处理;正在输入控件里打字时
|
||||
不拦截。
|
||||
5. **快捷键可自定义**:设置 → Better Chat → 审批卡快捷键,点键帽后按下新组合键。
|
||||
允许类动作固定在 Enter 上、拒绝固定在 Esc 上,修饰键自由;可清除「始终允许」或
|
||||
恢复默认。配置持久化在 `dsh.better-chat.v1`,保存后卡片提示立即更新,无需重启。
|
||||
|
||||
防误触:正在输入控件里打字、焦点已在卡内(Ctrl/Cmd+Enter 除外)、带 Shift/Alt、
|
||||
防误触:正在输入控件里打字、裸 Enter/Esc 且焦点已在卡内、与当前绑定不符的修饰键、
|
||||
长按连发、输入法组词、回车落在别的按钮或链接上、卡片已作答或按钮禁用时,都不拦截。
|
||||
|
||||
## 功能三:权限 UI(v0.2.0,v0.3.1 收紧)
|
||||
|
|
|
|||
396
lib/client.js
396
lib/client.js
|
|
@ -15,10 +15,120 @@ window.__ModuleLoader__.load({
|
|||
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
||||
return flags & 2 ? target : Object.preventExtensions(target);
|
||||
};
|
||||
let react = require("react");
|
||||
let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
|
||||
let react = require("react");
|
||||
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
||||
let react_jsx_runtime = require("react/jsx-runtime");
|
||||
// src/client/chat/bindings.ts
|
||||
const DEFAULT_BINDINGS = {
|
||||
allow: {
|
||||
key: "Enter",
|
||||
primary: false,
|
||||
shift: false,
|
||||
alt: false
|
||||
},
|
||||
always: {
|
||||
key: "Enter",
|
||||
primary: true,
|
||||
shift: false,
|
||||
alt: false
|
||||
},
|
||||
reject: {
|
||||
key: "Escape",
|
||||
primary: false,
|
||||
shift: false,
|
||||
alt: false
|
||||
}
|
||||
};
|
||||
/** 设置页保存快捷键后派发的窗口事件;提示与判定都靠实时 getter,无需重启。 */
|
||||
const BINDINGS_CHANGED_EVENT = "better-chat:bindings-changed";
|
||||
/** 每个动作允许的基础键:允许类只能用 Enter,拒绝只能用 Esc。 */
|
||||
function baseKeyFor(action) {
|
||||
return action === "reject" ? "Escape" : "Enter";
|
||||
}
|
||||
/** 展示用键帽文案,例如 Enter / Ctrl+Enter / Shift+Alt+Enter / Esc。 */
|
||||
function bindingKeycap(binding, mac) {
|
||||
const parts = [];
|
||||
if (binding.primary) parts.push(mac ? "Cmd" : "Ctrl");
|
||||
if (binding.shift) parts.push("Shift");
|
||||
if (binding.alt) parts.push("Alt");
|
||||
parts.push(binding.key === "Escape" ? "Esc" : binding.key);
|
||||
return parts.join("+");
|
||||
}
|
||||
/** 纯判定:按键事件是否命中这条绑定(修饰键必须完全一致)。 */
|
||||
function bindingMatches(binding, event) {
|
||||
const primary = Boolean(event.ctrlKey) || Boolean(event.metaKey);
|
||||
return event.key === binding.key && primary === binding.primary && Boolean(event.shiftKey) === binding.shift && Boolean(event.altKey) === binding.alt;
|
||||
}
|
||||
/** 是否是不带任何修饰键的裸键(Enter / Esc)。 */
|
||||
function isPlainBinding(binding) {
|
||||
return Boolean(binding) && !binding.primary && !binding.shift && !binding.alt;
|
||||
}
|
||||
/** 两条绑定是否相同。 */
|
||||
function bindingsEqual(left, right) {
|
||||
if (!left || !right) return left === right;
|
||||
return left.key === right.key && left.primary === right.primary && left.shift === right.shift && left.alt === right.alt;
|
||||
}
|
||||
function booleanOrFalse(value) {
|
||||
return value === true;
|
||||
}
|
||||
/** 校验并收敛一条绑定;形状不对时返回 undefined。 */
|
||||
function normalizeBinding(value) {
|
||||
if (!value || typeof value !== "object") return void 0;
|
||||
const record = value;
|
||||
if (record.key !== "Enter" && record.key !== "Escape") return void 0;
|
||||
return {
|
||||
key: record.key,
|
||||
primary: booleanOrFalse(record.primary),
|
||||
shift: booleanOrFalse(record.shift),
|
||||
alt: booleanOrFalse(record.alt)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 把持久化快照收敛成合法绑定;`{ bindings: ... }` 或内层对象都接受。
|
||||
* 缺失/非法/冲突的项回落到默认值,保证任何旧快照都能用。
|
||||
*/
|
||||
function normalizeBindings(value) {
|
||||
const inner = value && typeof value === "object" && "bindings" in value ? value.bindings : value;
|
||||
const record = inner && typeof inner === "object" ? inner : {};
|
||||
const allowRaw = normalizeBinding(record.allow);
|
||||
const rejectRaw = normalizeBinding(record.reject);
|
||||
const allow = allowRaw && allowRaw.key === "Enter" ? allowRaw : { ...DEFAULT_BINDINGS.allow };
|
||||
const reject = rejectRaw && rejectRaw.key === "Escape" ? rejectRaw : { ...DEFAULT_BINDINGS.reject };
|
||||
const alwaysRaw = "always" in record ? record.always : DEFAULT_BINDINGS.always;
|
||||
const alwaysParsed = alwaysRaw === null ? null : normalizeBinding(alwaysRaw);
|
||||
const out = {
|
||||
allow,
|
||||
always: alwaysParsed && alwaysParsed.key === "Enter" ? alwaysParsed : alwaysRaw === null ? null : { ...DEFAULT_BINDINGS.always },
|
||||
reject
|
||||
};
|
||||
if (out.always && (!hasModifier(out.always) || bindingsEqual(out.allow, out.always))) {
|
||||
out.allow = { ...DEFAULT_BINDINGS.allow };
|
||||
out.always = { ...DEFAULT_BINDINGS.always };
|
||||
}
|
||||
if (out.always && bindingsEqual(out.reject, out.always)) out.reject = { ...DEFAULT_BINDINGS.reject };
|
||||
if (bindingsEqual(out.allow, out.reject)) {
|
||||
out.allow = { ...DEFAULT_BINDINGS.allow };
|
||||
out.reject = { ...DEFAULT_BINDINGS.reject };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function hasModifier(binding) {
|
||||
return binding.primary || binding.shift || binding.alt;
|
||||
}
|
||||
/**
|
||||
* 保存前的校验:基础键是否匹配动作、始终允许是否有修饰键、是否与其他动作冲突。
|
||||
*/
|
||||
function validateBinding(action, binding, current) {
|
||||
if (binding.key !== baseKeyFor(action)) return "key";
|
||||
if (action === "always" && !hasModifier(binding)) return "modifier";
|
||||
const others = [];
|
||||
if (action !== "allow") others.push(current.allow);
|
||||
if (action !== "always" && current.always) others.push(current.always);
|
||||
if (action !== "reject") others.push(current.reject);
|
||||
if (others.some((other) => bindingsEqual(other, binding))) return "conflict";
|
||||
return "ok";
|
||||
}
|
||||
// src/client/chat/approval-keys.ts
|
||||
/**
|
||||
* 功能一:审批卡片的回车批准 / Esc 拒绝(自动送入焦点 + 全局兜底路由)。
|
||||
|
|
@ -51,28 +161,34 @@ window.__ModuleLoader__.load({
|
|||
/**
|
||||
* 纯判定:这次 keydown 是否应该路由到审批卡。
|
||||
*
|
||||
* - Enter → 允许(单次)
|
||||
* - Esc → 拒绝
|
||||
* - Ctrl/Cmd+Enter → 始终允许(仅当卡片有第三个按钮时;官方卡片本身
|
||||
* 对带修饰键的按键不作答,所以这条即使在卡内也由本插件处理)
|
||||
* 默认绑定:Enter → 允许(单次)、Ctrl/Cmd+Enter → 始终允许、Esc → 拒绝;
|
||||
* 绑定可由设置页改写(见 bindings.ts),基础键固定 Enter/Escape,只调修饰键。
|
||||
* 官方卡片本身对带修饰键的按键不作答,所以带修饰键的绑定即使在卡内也由
|
||||
* 本插件处理;裸 Enter/Esc 在卡内交给官方。
|
||||
*
|
||||
* @returns 'allow' | 'reject' | 'always' | null
|
||||
*/
|
||||
function decideKeyAction(input) {
|
||||
const { key, ctrlKey, metaKey, altKey, shiftKey, repeat, isComposing, keyCode, defaultPrevented, target, activeElement, card } = input;
|
||||
const { repeat, isComposing, keyCode, defaultPrevented, target, activeElement, card, hasAlways } = input;
|
||||
if (!card) return null;
|
||||
if (defaultPrevented) return null;
|
||||
if (key !== "Enter" && key !== "Escape") return null;
|
||||
if (altKey || shiftKey) return null;
|
||||
if (repeat || isComposing || keyCode === 229) return null;
|
||||
if (target && typeof target.closest === "function" && target.closest(EDITABLE_SELECTOR) !== null) return null;
|
||||
if (ctrlKey || metaKey) {
|
||||
if (key !== "Enter" || !input.hasAlways) return null;
|
||||
return "always";
|
||||
const bindings = input.bindings ?? DEFAULT_BINDINGS;
|
||||
const candidates = [
|
||||
["allow", bindings.allow],
|
||||
["always", hasAlways ? bindings.always : null],
|
||||
["reject", bindings.reject]
|
||||
];
|
||||
for (const [action, binding] of candidates) {
|
||||
if (!binding || !bindingMatches(binding, input)) continue;
|
||||
if (isPlainBinding(binding)) {
|
||||
if (activeElement && card.contains(activeElement)) return null;
|
||||
if (binding.key === "Enter" && target && typeof target.closest === "function" && target.closest("button, a[href], [role=\"button\"]") !== null) return null;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
if (activeElement && card.contains(activeElement)) return null;
|
||||
if (key === "Enter" && target && typeof target.closest === "function" && target.closest("button, a[href], [role=\"button\"]") !== null) return null;
|
||||
return key === "Enter" ? "allow" : "reject";
|
||||
return null;
|
||||
}
|
||||
/** 纯判定:审批卡出现时是否应该把焦点送进详情区。 */
|
||||
function shouldAutoFocus(activeElement, card) {
|
||||
|
|
@ -83,7 +199,7 @@ window.__ModuleLoader__.load({
|
|||
return true;
|
||||
}
|
||||
/** 安装审批键盘增强,返回卸载函数。 */
|
||||
function install(doc) {
|
||||
function install(doc, getBindings) {
|
||||
const focusedCards = /* @__PURE__ */ new WeakSet();
|
||||
const tryAutoFocus = () => {
|
||||
const card = findPendingCard(doc);
|
||||
|
|
@ -117,7 +233,8 @@ window.__ModuleLoader__.load({
|
|||
target: event.target,
|
||||
activeElement: doc.activeElement,
|
||||
card,
|
||||
hasAlways
|
||||
hasAlways,
|
||||
bindings: getBindings?.() ?? DEFAULT_BINDINGS
|
||||
});
|
||||
if (!action) return;
|
||||
const button = action === "allow" ? buttons[1] : action === "always" ? buttons[2] : buttons[0];
|
||||
|
|
@ -132,6 +249,37 @@ window.__ModuleLoader__.load({
|
|||
doc.removeEventListener("keydown", onKeyDown, true);
|
||||
};
|
||||
}
|
||||
// src/client/chat/bindings-store.ts
|
||||
/**
|
||||
* 聊天增强的持久化设置:审批卡快捷键。存储键 `dsh.better-chat.v1`,由宿主
|
||||
* 客户端 store 的 persist 机制写入配置,重启后仍在。
|
||||
*/
|
||||
const CHAT_PREFS_KEY = "dsh.better-chat.v1";
|
||||
function createChatStore() {
|
||||
return (0, _deepseek_ai_dsh_client_store.defineStore)({
|
||||
init: () => ({ bindings: normalizeBindings(void 0) }),
|
||||
persist: CHAT_PREFS_KEY,
|
||||
actions: {
|
||||
setApprovalBinding: (draft, action, binding) => {
|
||||
draft.bindings = normalizeBindings({
|
||||
...draft.bindings,
|
||||
[action]: binding
|
||||
});
|
||||
},
|
||||
resetApprovalBindings: (draft) => {
|
||||
draft.bindings = normalizeBindings(void 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/** 从设置实例读取当前绑定;旧快照/非法值自动回落默认。 */
|
||||
function currentBindings(prefs) {
|
||||
try {
|
||||
return normalizeBindings(prefs?.getSnapshot());
|
||||
} catch {
|
||||
return normalizeBindings(void 0);
|
||||
}
|
||||
}
|
||||
// src/client/chat/key-hint.ts
|
||||
/**
|
||||
* 审批卡键盘提示:在操作行左侧显示「Enter 允许(单次) · Ctrl+Enter
|
||||
|
|
@ -149,21 +297,21 @@ window.__ModuleLoader__.load({
|
|||
return typeof platform === "string" && /Mac|iPhone|iPad|iPod/.test(platform);
|
||||
}
|
||||
/**
|
||||
* 纯函数:根据卡片上实际存在的按钮文案,生成提示的分段。
|
||||
* 没有「始终允许」按钮时就不显示 Ctrl+Enter。
|
||||
* 纯函数:根据卡片上实际存在的按钮文案与当前绑定,生成提示的分段。
|
||||
* 「始终允许」被关掉(binding 为 null)时就不显示这一段。
|
||||
*/
|
||||
function hintParts(labels, mac) {
|
||||
function hintParts(labels, mac, bindings = DEFAULT_BINDINGS) {
|
||||
const parts = [];
|
||||
if (labels.allow) parts.push({
|
||||
key: "Enter",
|
||||
key: bindingKeycap(bindings.allow, mac),
|
||||
label: labels.allow
|
||||
});
|
||||
if (labels.always) parts.push({
|
||||
key: mac ? "Cmd+Enter" : "Ctrl+Enter",
|
||||
if (labels.always && bindings.always) parts.push({
|
||||
key: bindingKeycap(bindings.always, mac),
|
||||
label: labels.always
|
||||
});
|
||||
if (labels.reject) parts.push({
|
||||
key: "Esc",
|
||||
key: bindingKeycap(bindings.reject, mac),
|
||||
label: labels.reject
|
||||
});
|
||||
return parts;
|
||||
|
|
@ -234,12 +382,10 @@ window.__ModuleLoader__.load({
|
|||
function removeHints(doc) {
|
||||
for (const hint of doc.querySelectorAll(`[${HINT_ATTR}]`)) hint.remove();
|
||||
}
|
||||
/**
|
||||
* 安装审批卡键盘提示,返回卸载函数。
|
||||
* @param platform 用于区分 Cmd/Ctrl;默认读 navigator.platform。
|
||||
*/
|
||||
function installKeyHints(doc, platform = doc.defaultView?.navigator?.platform) {
|
||||
const mac = isMacPlatform(platform);
|
||||
/** 安装审批卡键盘提示,返回卸载函数。 */
|
||||
function installKeyHints(doc, options = {}) {
|
||||
const mac = isMacPlatform(options.platform ?? doc.defaultView?.navigator?.platform);
|
||||
const getBindings = options.getBindings ?? (() => DEFAULT_BINDINGS);
|
||||
let disposed = false;
|
||||
const syncCard = (card) => {
|
||||
const buttons = actionButtons(card);
|
||||
|
|
@ -253,7 +399,7 @@ window.__ModuleLoader__.load({
|
|||
allow: labelOf(buttons[1]),
|
||||
always: labelOf(always),
|
||||
reject: labelOf(buttons[0])
|
||||
}, mac);
|
||||
}, mac, getBindings());
|
||||
if (parts.length === 0) {
|
||||
existing?.remove();
|
||||
return;
|
||||
|
|
@ -283,10 +429,13 @@ window.__ModuleLoader__.load({
|
|||
attributes: true,
|
||||
attributeFilter: ["aria-busy", "disabled"]
|
||||
});
|
||||
const view = doc.defaultView;
|
||||
view?.addEventListener?.(BINDINGS_CHANGED_EVENT, sync);
|
||||
sync();
|
||||
return () => {
|
||||
disposed = true;
|
||||
observer.disconnect();
|
||||
view?.removeEventListener?.(BINDINGS_CHANGED_EVENT, sync);
|
||||
removeHints(doc);
|
||||
};
|
||||
}
|
||||
|
|
@ -52721,7 +52870,7 @@ ${trimmed}
|
|||
}
|
||||
// src/client/settings-copy.ts
|
||||
const en = {
|
||||
nav: "Better Display",
|
||||
nav: "Better Chat",
|
||||
openTitle: "Open deliverables in built-in panel",
|
||||
openDescription: "Off by default: chips and inline file mentions open in the system app. Turn this on to preview them in the right Sidebar, matching official chat. Reveal and folder actions still use the system file manager.",
|
||||
glassTitle: "Translucent frosted glass",
|
||||
|
|
@ -52731,6 +52880,18 @@ ${trimmed}
|
|||
foldNone: "Off",
|
||||
foldStandard: "On",
|
||||
foldSummary: "Summary",
|
||||
shortcutTitle: "Approval card shortcuts",
|
||||
shortcutDescription: "Click a keycap and press the new combination. Allow-type actions use Enter, reject uses Esc; modifiers are free. Esc alone cancels while recording. Stored in the plugin config.",
|
||||
shortcutAllow: "Allow once",
|
||||
shortcutAlways: "Always allow",
|
||||
shortcutReject: "Reject",
|
||||
shortcutRecording: "Press keys…",
|
||||
shortcutDisabled: "Not set",
|
||||
shortcutDisable: "Clear",
|
||||
shortcutReset: "Restore defaults",
|
||||
shortcutErrorKey: "Allow actions must use Enter; reject must use Esc.",
|
||||
shortcutErrorModifier: "Always allow needs at least one modifier key.",
|
||||
shortcutErrorConflict: "That combination is already used by another action.",
|
||||
skillTitle: "generative-mcpapps skill",
|
||||
skillInstalled: "Installed",
|
||||
skillMissing: "Not detected",
|
||||
|
|
@ -52742,7 +52903,7 @@ ${trimmed}
|
|||
skillUnavailable: "Could not query the host skill catalog. Copy into .dsh/skills or .agents/skills (home or project), then Re-check."
|
||||
};
|
||||
const zh = {
|
||||
nav: "Better Display",
|
||||
nav: "Better Chat",
|
||||
openTitle: "在内置面板中打开产物",
|
||||
openDescription: "默认关闭:产物芯片和正文中的文件提及会用系统应用打开。打开后与官方对话一致,在右侧栏预览。访达 / 资源管理器中的显示与打开所在文件夹不受此开关控制。",
|
||||
glassTitle: "半透明毛玻璃",
|
||||
|
|
@ -52752,6 +52913,18 @@ ${trimmed}
|
|||
foldNone: "关闭",
|
||||
foldStandard: "开启",
|
||||
foldSummary: "摘要",
|
||||
shortcutTitle: "审批卡快捷键",
|
||||
shortcutDescription: "点键帽后按下新的组合键。允许类只能用 Enter,拒绝只能用 Esc,修饰键随意;录制时单独按 Esc 取消。保存在插件配置里,重启后仍在。",
|
||||
shortcutAllow: "允许(单次)",
|
||||
shortcutAlways: "始终允许",
|
||||
shortcutReject: "拒绝",
|
||||
shortcutRecording: "按下组合键…",
|
||||
shortcutDisabled: "未设置",
|
||||
shortcutDisable: "清除",
|
||||
shortcutReset: "恢复默认",
|
||||
shortcutErrorKey: "允许类动作只能用 Enter,拒绝只能用 Esc。",
|
||||
shortcutErrorModifier: "「始终允许」至少需要一个修饰键(Ctrl/Shift/Alt)。",
|
||||
shortcutErrorConflict: "这个组合键已经被另一个动作占用。",
|
||||
skillTitle: "generative-mcpapps 技能",
|
||||
skillInstalled: "已安装",
|
||||
skillMissing: "未检测到",
|
||||
|
|
@ -52847,7 +53020,7 @@ ${trimmed}
|
|||
return (list?.byId ? Object.keys(list.byId) : [])[0];
|
||||
}
|
||||
// \0dshx-css-module:src/client/SettingsSection.module.css.mjs
|
||||
const css = ".TSdzRq_section{flex-direction:column;gap:28px;width:100%;max-width:720px;display:flex}.TSdzRq_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.TSdzRq_rowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:24px;display:flex}.TSdzRq_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.TSdzRq_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.TSdzRq_switch{background:var(--dsw-alias-bg-module-platform);cursor:pointer;border:none;border-radius:12px;flex:none;width:40px;height:24px;padding:0;position:relative}.TSdzRq_switch:after{content:\"\";background:var(--dsw-alias-label-primary);border-radius:50%;width:18px;height:18px;transition:transform .16s;position:absolute;top:3px;left:3px}.TSdzRq_switch[data-on]:after{transform:translate(16px)}.TSdzRq_switch[data-on]{background:var(--dsw-alias-state-business-primary)}.TSdzRq_block{flex-direction:column;gap:10px;display:flex}.TSdzRq_status{color:var(--dsw-alias-label-secondary);align-items:center;gap:8px;font-size:13px;line-height:20px;display:inline-flex}.TSdzRq_badge{background:var(--dsw-alias-bg-module-platform);height:22px;color:var(--dsw-alias-label-secondary);border-radius:11px;align-items:center;padding:0 8px;font-size:12px;display:inline-flex}.TSdzRq_badge[data-ok]{color:#059669;background:#10b98124}.TSdzRq_pre{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;white-space:pre-wrap;border-radius:8px;margin:0;padding:10px 12px;font-size:12px;line-height:18px}.TSdzRq_roots{color:var(--dsw-alias-label-tertiary);margin:0;padding-left:18px;font-size:12px;line-height:18px}.TSdzRq_actions{gap:8px;display:flex}.TSdzRq_button{border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-module-platform);height:32px;color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;border-radius:8px;padding:0 12px;font-size:13px}.TSdzRq_button:hover{background:var(--dsw-alias-interactive-bg-hover)}.TSdzRq_button:disabled{opacity:.6;cursor:default}.TSdzRq_segment{background:var(--dsw-alias-bg-module-platform);border-radius:10px;gap:2px;width:100%;margin-top:8px;padding:2px;display:flex}.TSdzRq_segmentStop{min-width:0;height:32px;color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:8px;flex:1 1 0;padding:0 8px;font-size:12px;line-height:18px}.TSdzRq_segmentStop[data-on]{background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);box-shadow:0 0 0 .5px var(--dsw-alias-border-l2)}.TSdzRq_slider{width:100%;accent-color:var(--dsw-alias-state-business-primary);margin:10px 0 0}";
|
||||
const css = ".TSdzRq_section{flex-direction:column;gap:28px;width:100%;max-width:720px;display:flex}.TSdzRq_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.TSdzRq_rowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:24px;display:flex}.TSdzRq_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.TSdzRq_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.TSdzRq_switch{background:var(--dsw-alias-bg-module-platform);cursor:pointer;border:none;border-radius:12px;flex:none;width:40px;height:24px;padding:0;position:relative}.TSdzRq_switch:after{content:\"\";background:var(--dsw-alias-label-primary);border-radius:50%;width:18px;height:18px;transition:transform .16s;position:absolute;top:3px;left:3px}.TSdzRq_switch[data-on]:after{transform:translate(16px)}.TSdzRq_switch[data-on]{background:var(--dsw-alias-state-business-primary)}.TSdzRq_block{flex-direction:column;gap:10px;display:flex}.TSdzRq_status{color:var(--dsw-alias-label-secondary);align-items:center;gap:8px;font-size:13px;line-height:20px;display:inline-flex}.TSdzRq_badge{background:var(--dsw-alias-bg-module-platform);height:22px;color:var(--dsw-alias-label-secondary);border-radius:11px;align-items:center;padding:0 8px;font-size:12px;display:inline-flex}.TSdzRq_badge[data-ok]{color:#059669;background:#10b98124}.TSdzRq_pre{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;white-space:pre-wrap;border-radius:8px;margin:0;padding:10px 12px;font-size:12px;line-height:18px}.TSdzRq_roots{color:var(--dsw-alias-label-tertiary);margin:0;padding-left:18px;font-size:12px;line-height:18px}.TSdzRq_actions{gap:8px;display:flex}.TSdzRq_button{border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-module-platform);height:32px;color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;border-radius:8px;padding:0 12px;font-size:13px}.TSdzRq_button:hover{background:var(--dsw-alias-interactive-bg-hover)}.TSdzRq_button:disabled{opacity:.6;cursor:default}.TSdzRq_segment{background:var(--dsw-alias-bg-module-platform);border-radius:10px;gap:2px;width:100%;margin-top:8px;padding:2px;display:flex}.TSdzRq_segmentStop{min-width:0;height:32px;color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:8px;flex:1 1 0;padding:0 8px;font-size:12px;line-height:18px}.TSdzRq_segmentStop[data-on]{background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);box-shadow:0 0 0 .5px var(--dsw-alias-border-l2)}.TSdzRq_slider{width:100%;accent-color:var(--dsw-alias-state-business-primary);margin:10px 0 0}.TSdzRq_keyActions{flex:none;align-items:center;gap:8px;display:flex}.TSdzRq_keyButton{border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base);min-width:96px;height:32px;color:var(--dsw-alias-label-primary);font-family:var(--ds-font-family-code,ui-monospace, SFMono-Regular, Consolas, monospace);cursor:pointer;border-radius:8px;padding:0 12px;font-size:12px;line-height:20px}.TSdzRq_keyButton:hover{border-color:var(--dsw-alias-border-l3)}.TSdzRq_keyButton[data-recording]{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-bg-module-platform)}.TSdzRq_error{color:var(--dsw-alias-state-error-primary,#d1483c);margin:0;font-size:12px;line-height:18px}";
|
||||
const tagId = "dsh-better-chat/SettingsSection.module.css";
|
||||
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
||||
const tag = document.createElement("style");
|
||||
|
|
@ -52862,6 +53035,9 @@ ${trimmed}
|
|||
"block": "TSdzRq_block",
|
||||
"button": "TSdzRq_button",
|
||||
"desc": "TSdzRq_desc",
|
||||
"error": "TSdzRq_error",
|
||||
"keyActions": "TSdzRq_keyActions",
|
||||
"keyButton": "TSdzRq_keyButton",
|
||||
"pre": "TSdzRq_pre",
|
||||
"roots": "TSdzRq_roots",
|
||||
"row": "TSdzRq_row",
|
||||
|
|
@ -52913,6 +53089,65 @@ ${trimmed}
|
|||
(0, react.useEffect)(() => {
|
||||
recheck();
|
||||
}, [recheck]);
|
||||
const chat = props.chat;
|
||||
const chatSnap = (0, react.useSyncExternalStore)(chat?.subscribe ?? (() => () => {}), () => chat?.getSnapshot() ?? { bindings: void 0 }, () => ({ bindings: void 0 }));
|
||||
const bindings = normalizeBindings(chatSnap);
|
||||
const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform);
|
||||
const [recording, setRecording] = (0, react.useState)(null);
|
||||
const [keyError, setKeyError] = (0, react.useState)();
|
||||
const announceBindings = (0, react.useCallback)(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
window.dispatchEvent(new CustomEvent(BINDINGS_CHANGED_EVENT));
|
||||
}, []);
|
||||
(0, react.useEffect)(() => {
|
||||
if (!recording || !chat) return;
|
||||
const onKey = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (event.key === "Escape" && recording !== "reject" && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
||||
setRecording(null);
|
||||
setKeyError(void 0);
|
||||
return;
|
||||
}
|
||||
const key = event.key === "Enter" ? "Enter" : event.key === "Escape" ? "Escape" : void 0;
|
||||
if (!key) {
|
||||
setKeyError(copy.shortcutErrorKey);
|
||||
return;
|
||||
}
|
||||
const binding = {
|
||||
key,
|
||||
primary: event.ctrlKey || event.metaKey,
|
||||
shift: event.shiftKey,
|
||||
alt: event.altKey
|
||||
};
|
||||
const verdict = validateBinding(recording, binding, bindings);
|
||||
if (verdict === "key") {
|
||||
setKeyError(copy.shortcutErrorKey);
|
||||
return;
|
||||
}
|
||||
if (verdict === "modifier") {
|
||||
setKeyError(copy.shortcutErrorModifier);
|
||||
return;
|
||||
}
|
||||
if (verdict === "conflict") {
|
||||
setKeyError(copy.shortcutErrorConflict);
|
||||
return;
|
||||
}
|
||||
chat.actions.setApprovalBinding(recording, binding);
|
||||
announceBindings();
|
||||
setRecording(null);
|
||||
setKeyError(void 0);
|
||||
};
|
||||
window.addEventListener("keydown", onKey, true);
|
||||
return () => window.removeEventListener("keydown", onKey, true);
|
||||
}, [
|
||||
recording,
|
||||
chat,
|
||||
chatSnap,
|
||||
copy,
|
||||
bindings,
|
||||
announceBindings
|
||||
]);
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||
className: SettingsSection_module_css_default.section,
|
||||
"data-better-display-settings": true,
|
||||
|
|
@ -52987,6 +53222,86 @@ ${trimmed}
|
|||
}
|
||||
})]
|
||||
}),
|
||||
chat ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
||||
className: SettingsSection_module_css_default.block,
|
||||
"data-better-chat-shortcuts": true,
|
||||
children: [
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: SettingsSection_module_css_default.title,
|
||||
children: text(props, copy, "shortcutTitle")
|
||||
}),
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
className: SettingsSection_module_css_default.desc,
|
||||
children: text(props, copy, "shortcutDescription")
|
||||
}),
|
||||
[
|
||||
[
|
||||
"allow",
|
||||
"shortcutAllow",
|
||||
bindings.allow
|
||||
],
|
||||
[
|
||||
"always",
|
||||
"shortcutAlways",
|
||||
bindings.always
|
||||
],
|
||||
[
|
||||
"reject",
|
||||
"shortcutReject",
|
||||
bindings.reject
|
||||
]
|
||||
].map(([action, title, binding]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||
className: SettingsSection_module_css_default.row,
|
||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: SettingsSection_module_css_default.rowText,
|
||||
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: SettingsSection_module_css_default.title,
|
||||
children: text(props, copy, title)
|
||||
})
|
||||
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||
className: SettingsSection_module_css_default.keyActions,
|
||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
||||
type: "button",
|
||||
className: SettingsSection_module_css_default.keyButton,
|
||||
"data-recording": recording === action || void 0,
|
||||
onClick: () => {
|
||||
setKeyError(void 0);
|
||||
setRecording(action);
|
||||
},
|
||||
children: recording === action ? text(props, copy, "shortcutRecording") : binding ? bindingKeycap(binding, mac) : text(props, copy, "shortcutDisabled")
|
||||
}), action === "always" && binding ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
||||
type: "button",
|
||||
className: SettingsSection_module_css_default.button,
|
||||
onClick: () => {
|
||||
chat.actions.setApprovalBinding("always", null);
|
||||
announceBindings();
|
||||
setKeyError(void 0);
|
||||
},
|
||||
children: text(props, copy, "shortcutDisable")
|
||||
}) : null]
|
||||
})]
|
||||
}, action)),
|
||||
keyError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
||||
className: SettingsSection_module_css_default.error,
|
||||
"data-better-chat-key-error": true,
|
||||
children: keyError
|
||||
}) : null,
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: SettingsSection_module_css_default.actions,
|
||||
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
||||
type: "button",
|
||||
className: SettingsSection_module_css_default.button,
|
||||
onClick: () => {
|
||||
chat.actions.resetApprovalBindings();
|
||||
announceBindings();
|
||||
setRecording(null);
|
||||
setKeyError(void 0);
|
||||
},
|
||||
children: text(props, copy, "shortcutReset")
|
||||
})
|
||||
})
|
||||
]
|
||||
}) : null,
|
||||
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
||||
className: SettingsSection_module_css_default.block,
|
||||
"data-better-display-skill": skill?.installed ? "installed" : "missing",
|
||||
|
|
@ -53068,7 +53383,7 @@ ${trimmed}
|
|||
}
|
||||
};
|
||||
}
|
||||
function installBetterDisplaySettings(ctx, prefs) {
|
||||
function installBetterDisplaySettings(ctx, prefs, chat) {
|
||||
const locale = ctx.get?.("locale") ?? ctx.locale;
|
||||
if (locale?.register) ctx.effect(() => locale.register("better-display", {
|
||||
zh,
|
||||
|
|
@ -53077,6 +53392,7 @@ ${trimmed}
|
|||
const checkSkill = createSkillProbe(ctx);
|
||||
const injected = () => ({
|
||||
prefs,
|
||||
chat,
|
||||
copy: settingsCopyFor(languageTag(ctx)),
|
||||
languageTag: languageTag(ctx),
|
||||
checkSkill
|
||||
|
|
@ -53100,14 +53416,14 @@ ${trimmed}
|
|||
} else console.warn("[dsh-better-display] remote.session is not available");
|
||||
}
|
||||
ensureStyles();
|
||||
function apply$1(ctx) {
|
||||
function apply$1(ctx, options = {}) {
|
||||
const textTransform = createTextTransformRegistry();
|
||||
const restoreTextTransform = installTextTransformRegistry(textTransform);
|
||||
ctx.provide(TEXT_TRANSFORM_SERVICE, textTransform);
|
||||
ctx.effect(() => restoreTextTransform);
|
||||
const store = createReaderStore();
|
||||
const prefs = store.create();
|
||||
installBetterDisplaySettings(ctx, prefs);
|
||||
installBetterDisplaySettings(ctx, prefs, options.chatPrefs);
|
||||
ctx.slots.inject("conversation.chat.node", function* () {
|
||||
yield ctx.slots.register({
|
||||
name: "conversation.view",
|
||||
|
|
@ -53269,13 +53585,15 @@ ${trimmed}
|
|||
"remote.session"
|
||||
];
|
||||
function apply(ctx) {
|
||||
ctx.effect(() => install(document), "dsh-better-chat: approval enter/esc routing");
|
||||
ctx.effect(() => installKeyHints(document), "dsh-better-chat: approval key hints");
|
||||
const chatPrefs = createChatStore().create();
|
||||
const getBindings = () => currentBindings(chatPrefs);
|
||||
ctx.effect(() => install(document, getBindings), "dsh-better-chat: approval key routing");
|
||||
ctx.effect(() => installKeyHints(document, { getBindings }), "dsh-better-chat: approval key hints");
|
||||
ctx.effect(() => installPermissionPolicy(document), "dsh-better-chat: permission policy (no full access)");
|
||||
try {
|
||||
ctx.plugin(storeUpdatePlugin);
|
||||
} catch {}
|
||||
apply$1(ctx);
|
||||
apply$1(ctx, { chatPrefs });
|
||||
}
|
||||
exports.apply = apply;
|
||||
exports.inject = inject;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsh-better-chat",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"description": "DSH 聊天增强插件:审批回车批准 / Esc 拒绝、权限 UI、插件商店更新,以及 reading view(合并自 dsh-better-display)",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
|
|
@ -182,3 +182,41 @@
|
|||
margin: 10px 0 0;
|
||||
accent-color: var(--dsw-alias-state-business-primary);
|
||||
}
|
||||
|
||||
.keyActions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.keyButton {
|
||||
min-width: 96px;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 0.5px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 8px;
|
||||
background: var(--dsw-alias-bg-base);
|
||||
color: var(--dsw-alias-label-primary);
|
||||
font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Consolas, monospace);
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.keyButton:hover {
|
||||
border-color: var(--dsw-alias-border-l3);
|
||||
}
|
||||
|
||||
.keyButton[data-recording] {
|
||||
border-color: var(--dsw-alias-state-business-primary);
|
||||
color: var(--dsw-alias-state-business-primary);
|
||||
background: var(--dsw-alias-bg-module-platform);
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 0;
|
||||
color: var(--dsw-alias-state-error-primary, #d1483c);
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,14 @@
|
|||
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
|
||||
import { frostedGlassOf, type FoldIntensity } from './fold-intensity.js';
|
||||
import {
|
||||
BINDINGS_CHANGED_EVENT,
|
||||
bindingKeycap,
|
||||
normalizeBindings,
|
||||
validateBinding,
|
||||
type ApprovalAction,
|
||||
type ApprovalBinding,
|
||||
} from './chat/bindings.js';
|
||||
import type { ChatPrefs } from './chat/bindings-store.js';
|
||||
import { deliverableOpenModeOf, type DeliverableOpenMode } from './open-file.js';
|
||||
import { settingsCopyFor, type SettingsCopy, type SettingsCopyKey } from './settings-copy.js';
|
||||
import { CONVENTIONAL_SKILL_ROOTS, detectGenerativeMcpappsSkill, shortestInstallCommand, type SkillStatusProbe, type SkillStatusSnapshot } from './skill-status.js';
|
||||
|
|
@ -26,6 +35,7 @@ export interface OpenPrefs {
|
|||
|
||||
export interface BetterDisplaySettingsInjected {
|
||||
prefs: OpenPrefs;
|
||||
chat?: ChatPrefs;
|
||||
copy?: SettingsCopy;
|
||||
languageTag?: string;
|
||||
checkSkill: SkillStatusProbe;
|
||||
|
|
@ -85,6 +95,58 @@ export function SettingsSection(props: SettingsProps) {
|
|||
|
||||
useEffect(() => { void recheck(); }, [recheck]);
|
||||
|
||||
// 审批快捷键:读插件配置(dsh.better-chat.v1),保存后派发事件让卡片提示立即重建。
|
||||
const chat = props.chat;
|
||||
const chatSnap = useSyncExternalStore(
|
||||
chat?.subscribe ?? (() => () => {}),
|
||||
() => chat?.getSnapshot() ?? ({ bindings: undefined } as never),
|
||||
() => ({ bindings: undefined } as never),
|
||||
);
|
||||
const bindings = normalizeBindings(chatSnap);
|
||||
const mac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.platform);
|
||||
const [recording, setRecording] = useState<ApprovalAction | null>(null);
|
||||
const [keyError, setKeyError] = useState<string | undefined>();
|
||||
|
||||
const announceBindings = useCallback(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.dispatchEvent(new CustomEvent(BINDINGS_CHANGED_EVENT));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!recording || !chat) return;
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (event.key === 'Escape' && recording !== 'reject'
|
||||
&& !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
||||
setRecording(null);
|
||||
setKeyError(undefined);
|
||||
return;
|
||||
}
|
||||
const key = event.key === 'Enter' ? 'Enter' : event.key === 'Escape' ? 'Escape' : undefined;
|
||||
if (!key) {
|
||||
setKeyError(copy.shortcutErrorKey);
|
||||
return;
|
||||
}
|
||||
const binding: ApprovalBinding = {
|
||||
key,
|
||||
primary: event.ctrlKey || event.metaKey,
|
||||
shift: event.shiftKey,
|
||||
alt: event.altKey,
|
||||
};
|
||||
const verdict = validateBinding(recording, binding, bindings);
|
||||
if (verdict === 'key') { setKeyError(copy.shortcutErrorKey); return; }
|
||||
if (verdict === 'modifier') { setKeyError(copy.shortcutErrorModifier); return; }
|
||||
if (verdict === 'conflict') { setKeyError(copy.shortcutErrorConflict); return; }
|
||||
chat.actions.setApprovalBinding(recording, binding);
|
||||
announceBindings();
|
||||
setRecording(null);
|
||||
setKeyError(undefined);
|
||||
};
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [recording, chat, chatSnap, copy, bindings, announceBindings]);
|
||||
|
||||
return (
|
||||
<div className={css.section} data-better-display-settings>
|
||||
<div className={css.row}>
|
||||
|
|
@ -138,6 +200,64 @@ export function SettingsSection(props: SettingsProps) {
|
|||
/>
|
||||
</div>
|
||||
|
||||
{chat ? (
|
||||
<section className={css.block} data-better-chat-shortcuts>
|
||||
<div className={css.title}>{text(props, copy, 'shortcutTitle')}</div>
|
||||
<p className={css.desc}>{text(props, copy, 'shortcutDescription')}</p>
|
||||
{([
|
||||
['allow', 'shortcutAllow', bindings.allow],
|
||||
['always', 'shortcutAlways', bindings.always],
|
||||
['reject', 'shortcutReject', bindings.reject],
|
||||
] as const).map(([action, title, binding]) => (
|
||||
<div className={css.row} key={action}>
|
||||
<div className={css.rowText}>
|
||||
<div className={css.title}>{text(props, copy, title)}</div>
|
||||
</div>
|
||||
<div className={css.keyActions}>
|
||||
<button
|
||||
type="button"
|
||||
className={css.keyButton}
|
||||
data-recording={recording === action || undefined}
|
||||
onClick={() => { setKeyError(undefined); setRecording(action); }}
|
||||
>
|
||||
{recording === action
|
||||
? text(props, copy, 'shortcutRecording')
|
||||
: binding ? bindingKeycap(binding, mac) : text(props, copy, 'shortcutDisabled')}
|
||||
</button>
|
||||
{action === 'always' && binding ? (
|
||||
<button
|
||||
type="button"
|
||||
className={css.button}
|
||||
onClick={() => {
|
||||
chat.actions.setApprovalBinding('always', null);
|
||||
announceBindings();
|
||||
setKeyError(undefined);
|
||||
}}
|
||||
>
|
||||
{text(props, copy, 'shortcutDisable')}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{keyError ? <p className={css.error} data-better-chat-key-error>{keyError}</p> : null}
|
||||
<div className={css.actions}>
|
||||
<button
|
||||
type="button"
|
||||
className={css.button}
|
||||
onClick={() => {
|
||||
chat.actions.resetApprovalBindings();
|
||||
announceBindings();
|
||||
setRecording(null);
|
||||
setKeyError(undefined);
|
||||
}}
|
||||
>
|
||||
{text(props, copy, 'shortcutReset')}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<section className={css.block} data-better-display-skill={skill?.installed ? 'installed' : 'missing'}>
|
||||
<div className={css.title}>{text(props, copy, 'skillTitle')}</div>
|
||||
<div className={css.status}>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,15 @@ const CARD_SELECTOR = '[data-approval-key]'
|
|||
const SCROLL_SELECTOR = '[data-approval-scroll]'
|
||||
const EDITABLE_SELECTOR = 'input, textarea, select, [contenteditable="true"], [contenteditable=""]'
|
||||
|
||||
import {
|
||||
DEFAULT_BINDINGS,
|
||||
bindingMatches,
|
||||
isPlainBinding,
|
||||
type ApprovalAction,
|
||||
type ApprovalBinding,
|
||||
type ApprovalBindings,
|
||||
} from './bindings.js'
|
||||
|
||||
export interface KeyActionInput {
|
||||
key: string
|
||||
ctrlKey?: boolean
|
||||
|
|
@ -30,6 +39,8 @@ export interface KeyActionInput {
|
|||
card?: Element | null
|
||||
/** 卡片是否有可用的「始终允许」按钮(第三个操作按钮)。 */
|
||||
hasAlways?: boolean
|
||||
/** 当前快捷键绑定;缺省使用 DEFAULT_BINDINGS。 */
|
||||
bindings?: ApprovalBindings
|
||||
}
|
||||
|
||||
/** 卡片操作行的按钮:详情滚动区之外的全部按钮,顺序 [拒绝, 允许, 始终允许?]。 */
|
||||
|
|
@ -52,41 +63,45 @@ export function findPendingCard(doc: Document): Element | null {
|
|||
/**
|
||||
* 纯判定:这次 keydown 是否应该路由到审批卡。
|
||||
*
|
||||
* - Enter → 允许(单次)
|
||||
* - Esc → 拒绝
|
||||
* - Ctrl/Cmd+Enter → 始终允许(仅当卡片有第三个按钮时;官方卡片本身
|
||||
* 对带修饰键的按键不作答,所以这条即使在卡内也由本插件处理)
|
||||
* 默认绑定:Enter → 允许(单次)、Ctrl/Cmd+Enter → 始终允许、Esc → 拒绝;
|
||||
* 绑定可由设置页改写(见 bindings.ts),基础键固定 Enter/Escape,只调修饰键。
|
||||
* 官方卡片本身对带修饰键的按键不作答,所以带修饰键的绑定即使在卡内也由
|
||||
* 本插件处理;裸 Enter/Esc 在卡内交给官方。
|
||||
*
|
||||
* @returns 'allow' | 'reject' | 'always' | null
|
||||
*/
|
||||
export function decideKeyAction(input: KeyActionInput): 'allow' | 'reject' | 'always' | null {
|
||||
const {
|
||||
key, ctrlKey, metaKey, altKey, shiftKey, repeat, isComposing,
|
||||
keyCode, defaultPrevented, target, activeElement, card,
|
||||
repeat, isComposing, keyCode, defaultPrevented, target, activeElement, card, hasAlways,
|
||||
} = input
|
||||
if (!card) return null
|
||||
if (defaultPrevented) return null
|
||||
if (key !== 'Enter' && key !== 'Escape') return null
|
||||
if (altKey || shiftKey) return null
|
||||
if (repeat || isComposing || keyCode === 229) return null
|
||||
|
||||
// 正在输入控件里打字时一律不拦截(含卡片内的输入框)。
|
||||
if (target && typeof target.closest === 'function' && target.closest(EDITABLE_SELECTOR) !== null) {
|
||||
return null
|
||||
}
|
||||
|
||||
const chord = ctrlKey || metaKey
|
||||
if (chord) {
|
||||
if (key !== 'Enter' || !input.hasAlways) return null
|
||||
return 'always'
|
||||
}
|
||||
const bindings = input.bindings ?? DEFAULT_BINDINGS
|
||||
const candidates: Array<[ApprovalAction, ApprovalBinding | null]> = [
|
||||
['allow', bindings.allow],
|
||||
['always', hasAlways ? bindings.always : null],
|
||||
['reject', bindings.reject],
|
||||
]
|
||||
|
||||
if (activeElement && card.contains(activeElement)) return null // 焦点在卡内:官方处理
|
||||
if (key === 'Enter' && target && typeof target.closest === 'function'
|
||||
&& target.closest('button, a[href], [role="button"]') !== null) {
|
||||
return null // 回车落在别的按钮/链接上:保留它自己的行为
|
||||
for (const [action, binding] of candidates) {
|
||||
if (!binding || !bindingMatches(binding, input)) continue
|
||||
if (isPlainBinding(binding)) {
|
||||
// 裸键在卡内交给官方;Enter 落在别的按钮/链接上时保留它自己的行为。
|
||||
if (activeElement && card.contains(activeElement)) return null
|
||||
if (binding.key === 'Enter' && target && typeof target.closest === 'function'
|
||||
&& target.closest('button, a[href], [role="button"]') !== null) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return action
|
||||
}
|
||||
return key === 'Enter' ? 'allow' : 'reject'
|
||||
return null
|
||||
}
|
||||
|
||||
/** 纯判定:审批卡出现时是否应该把焦点送进详情区。 */
|
||||
|
|
@ -101,7 +116,7 @@ export function shouldAutoFocus(activeElement: Element | null | undefined, card:
|
|||
}
|
||||
|
||||
/** 安装审批键盘增强,返回卸载函数。 */
|
||||
export function install(doc: Document): () => void {
|
||||
export function install(doc: Document, getBindings?: () => ApprovalBindings): () => void {
|
||||
const focusedCards = new WeakSet<Element>()
|
||||
|
||||
const tryAutoFocus = (): void => {
|
||||
|
|
@ -128,6 +143,7 @@ export function install(doc: Document): () => void {
|
|||
repeat: event.repeat, isComposing: event.isComposing, keyCode: event.keyCode,
|
||||
defaultPrevented: event.defaultPrevented,
|
||||
target: event.target as Element | null, activeElement: doc.activeElement, card, hasAlways,
|
||||
bindings: getBindings?.() ?? DEFAULT_BINDINGS,
|
||||
})
|
||||
if (!action) return
|
||||
const button = action === 'allow'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 聊天增强的持久化设置:审批卡快捷键。存储键 `dsh.better-chat.v1`,由宿主
|
||||
* 客户端 store 的 persist 机制写入配置,重启后仍在。
|
||||
*/
|
||||
import { defineStore } from '@deepseek-ai/dsh-client-store'
|
||||
import type { EngineStoreHandle } from '@deepseek-ai/dsh-client-store'
|
||||
import {
|
||||
normalizeBindings,
|
||||
type ApprovalAction,
|
||||
type ApprovalBinding,
|
||||
type ApprovalBindings,
|
||||
} from './bindings.js'
|
||||
|
||||
export interface ChatState {
|
||||
bindings: ApprovalBindings
|
||||
}
|
||||
|
||||
export type ChatActionsDecl = {
|
||||
setApprovalBinding: (draft: ChatState, action: ApprovalAction, binding: ApprovalBinding | null) => void
|
||||
resetApprovalBindings: (draft: ChatState) => void
|
||||
}
|
||||
|
||||
export interface ChatPrefs {
|
||||
getSnapshot: () => ChatState
|
||||
subscribe: (fn: () => void) => () => void
|
||||
actions: {
|
||||
setApprovalBinding: (action: ApprovalAction, binding: ApprovalBinding | null) => void
|
||||
resetApprovalBindings: () => void
|
||||
}
|
||||
}
|
||||
|
||||
export const CHAT_PREFS_KEY = 'dsh.better-chat.v1'
|
||||
|
||||
export function createChatStore(): EngineStoreHandle<ChatState, ChatActionsDecl> {
|
||||
return defineStore({
|
||||
init: (): ChatState => ({ bindings: normalizeBindings(undefined) }),
|
||||
persist: CHAT_PREFS_KEY,
|
||||
actions: {
|
||||
setApprovalBinding: (draft, action: ApprovalAction, binding: ApprovalBinding | null) => {
|
||||
draft.bindings = normalizeBindings({ ...draft.bindings, [action]: binding })
|
||||
},
|
||||
resetApprovalBindings: (draft) => {
|
||||
draft.bindings = normalizeBindings(undefined)
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 从设置实例读取当前绑定;旧快照/非法值自动回落默认。 */
|
||||
export function currentBindings(prefs: ChatPrefs | undefined): ApprovalBindings {
|
||||
try {
|
||||
return normalizeBindings(prefs?.getSnapshot())
|
||||
} catch {
|
||||
return normalizeBindings(undefined)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* 审批卡快捷键模型:默认 Enter 允许(单次)、Ctrl+Enter 始终允许、Esc 拒绝。
|
||||
*
|
||||
* 允许自定义:允许/始终允许固定在 Enter 上、拒绝固定在 Esc 上,只让修饰键可调,
|
||||
* 避免把普通字母键变成全局快捷键。`primary` 表示 Windows/Linux 的 Ctrl、macOS 的
|
||||
* Cmd —— 判定时 Ctrl 或 Meta 任一按下即算命中,展示时按平台显示 Ctrl/Cmd。
|
||||
*/
|
||||
|
||||
export type ApprovalAction = 'allow' | 'always' | 'reject'
|
||||
export type ApprovalBaseKey = 'Enter' | 'Escape'
|
||||
|
||||
export interface ApprovalBinding {
|
||||
key: ApprovalBaseKey
|
||||
/** Ctrl(Windows/Linux)或 Cmd(macOS)。 */
|
||||
primary: boolean
|
||||
shift: boolean
|
||||
alt: boolean
|
||||
}
|
||||
|
||||
export interface ApprovalBindings {
|
||||
allow: ApprovalBinding
|
||||
/** null = 不绑定「始终允许」。 */
|
||||
always: ApprovalBinding | null
|
||||
reject: ApprovalBinding
|
||||
}
|
||||
|
||||
export interface KeyEventLike {
|
||||
key: string
|
||||
ctrlKey?: boolean
|
||||
metaKey?: boolean
|
||||
shiftKey?: boolean
|
||||
altKey?: boolean
|
||||
}
|
||||
|
||||
export const DEFAULT_BINDINGS: ApprovalBindings = {
|
||||
allow: { key: 'Enter', primary: false, shift: false, alt: false },
|
||||
always: { key: 'Enter', primary: true, shift: false, alt: false },
|
||||
reject: { key: 'Escape', primary: false, shift: false, alt: false },
|
||||
}
|
||||
|
||||
/** 设置页保存快捷键后派发的窗口事件;提示与判定都靠实时 getter,无需重启。 */
|
||||
export const BINDINGS_CHANGED_EVENT = 'better-chat:bindings-changed'
|
||||
|
||||
/** 每个动作允许的基础键:允许类只能用 Enter,拒绝只能用 Esc。 */
|
||||
export function baseKeyFor(action: ApprovalAction): ApprovalBaseKey {
|
||||
return action === 'reject' ? 'Escape' : 'Enter'
|
||||
}
|
||||
|
||||
/** 展示用键帽文案,例如 Enter / Ctrl+Enter / Shift+Alt+Enter / Esc。 */
|
||||
export function bindingKeycap(binding: ApprovalBinding, mac: boolean): string {
|
||||
const parts: string[] = []
|
||||
if (binding.primary) parts.push(mac ? 'Cmd' : 'Ctrl')
|
||||
if (binding.shift) parts.push('Shift')
|
||||
if (binding.alt) parts.push('Alt')
|
||||
parts.push(binding.key === 'Escape' ? 'Esc' : binding.key)
|
||||
return parts.join('+')
|
||||
}
|
||||
|
||||
/** 纯判定:按键事件是否命中这条绑定(修饰键必须完全一致)。 */
|
||||
export function bindingMatches(binding: ApprovalBinding, event: KeyEventLike): boolean {
|
||||
const primary = Boolean(event.ctrlKey) || Boolean(event.metaKey)
|
||||
return event.key === binding.key
|
||||
&& primary === binding.primary
|
||||
&& Boolean(event.shiftKey) === binding.shift
|
||||
&& Boolean(event.altKey) === binding.alt
|
||||
}
|
||||
|
||||
/** 是否是不带任何修饰键的裸键(Enter / Esc)。 */
|
||||
export function isPlainBinding(binding: ApprovalBinding | null | undefined): boolean {
|
||||
return Boolean(binding) && !binding!.primary && !binding!.shift && !binding!.alt
|
||||
}
|
||||
|
||||
/** 两条绑定是否相同。 */
|
||||
export function bindingsEqual(
|
||||
left: ApprovalBinding | null | undefined,
|
||||
right: ApprovalBinding | null | undefined,
|
||||
): boolean {
|
||||
if (!left || !right) return left === right
|
||||
return left.key === right.key
|
||||
&& left.primary === right.primary
|
||||
&& left.shift === right.shift
|
||||
&& left.alt === right.alt
|
||||
}
|
||||
|
||||
function booleanOrFalse(value: unknown): boolean {
|
||||
return value === true
|
||||
}
|
||||
|
||||
/** 校验并收敛一条绑定;形状不对时返回 undefined。 */
|
||||
export function normalizeBinding(value: unknown): ApprovalBinding | undefined {
|
||||
if (!value || typeof value !== 'object') return undefined
|
||||
const record = value as Record<string, unknown>
|
||||
if (record.key !== 'Enter' && record.key !== 'Escape') return undefined
|
||||
return {
|
||||
key: record.key,
|
||||
primary: booleanOrFalse(record.primary),
|
||||
shift: booleanOrFalse(record.shift),
|
||||
alt: booleanOrFalse(record.alt),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把持久化快照收敛成合法绑定;`{ bindings: ... }` 或内层对象都接受。
|
||||
* 缺失/非法/冲突的项回落到默认值,保证任何旧快照都能用。
|
||||
*/
|
||||
export function normalizeBindings(value: unknown): ApprovalBindings {
|
||||
const inner = value && typeof value === 'object' && 'bindings' in (value as Record<string, unknown>)
|
||||
? (value as Record<string, unknown>).bindings
|
||||
: value
|
||||
const record = inner && typeof inner === 'object' ? inner as Record<string, unknown> : {}
|
||||
const allowRaw = normalizeBinding(record.allow)
|
||||
const rejectRaw = normalizeBinding(record.reject)
|
||||
const allow = allowRaw && allowRaw.key === 'Enter' ? allowRaw : { ...DEFAULT_BINDINGS.allow }
|
||||
const reject = rejectRaw && rejectRaw.key === 'Escape' ? rejectRaw : { ...DEFAULT_BINDINGS.reject }
|
||||
const alwaysRaw = 'always' in record ? record.always : DEFAULT_BINDINGS.always
|
||||
const alwaysParsed = alwaysRaw === null ? null : normalizeBinding(alwaysRaw)
|
||||
const always = alwaysParsed && alwaysParsed.key === 'Enter'
|
||||
? alwaysParsed
|
||||
: (alwaysRaw === null ? null : { ...DEFAULT_BINDINGS.always })
|
||||
|
||||
const out: ApprovalBindings = { allow, always, reject }
|
||||
// 冲突(或「始终允许」没修饰键)时把 allow/always 一起回落到默认,
|
||||
// 避免一个按键命中两个动作;默认值本身互不冲突。
|
||||
if (out.always && (!hasModifier(out.always) || bindingsEqual(out.allow, out.always))) {
|
||||
out.allow = { ...DEFAULT_BINDINGS.allow }
|
||||
out.always = { ...DEFAULT_BINDINGS.always }
|
||||
}
|
||||
if (out.always && bindingsEqual(out.reject, out.always)) {
|
||||
out.reject = { ...DEFAULT_BINDINGS.reject }
|
||||
}
|
||||
if (bindingsEqual(out.allow, out.reject)) {
|
||||
out.allow = { ...DEFAULT_BINDINGS.allow }
|
||||
out.reject = { ...DEFAULT_BINDINGS.reject }
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function hasModifier(binding: ApprovalBinding): boolean {
|
||||
return binding.primary || binding.shift || binding.alt
|
||||
}
|
||||
|
||||
export type BindingVerdict = 'ok' | 'key' | 'modifier' | 'conflict'
|
||||
|
||||
/**
|
||||
* 保存前的校验:基础键是否匹配动作、始终允许是否有修饰键、是否与其他动作冲突。
|
||||
*/
|
||||
export function validateBinding(
|
||||
action: ApprovalAction,
|
||||
binding: ApprovalBinding,
|
||||
current: ApprovalBindings,
|
||||
): BindingVerdict {
|
||||
if (binding.key !== baseKeyFor(action)) return 'key'
|
||||
if (action === 'always' && !hasModifier(binding)) return 'modifier'
|
||||
const others: ApprovalBinding[] = []
|
||||
if (action !== 'allow') others.push(current.allow)
|
||||
if (action !== 'always' && current.always) others.push(current.always)
|
||||
if (action !== 'reject') others.push(current.reject)
|
||||
if (others.some((other) => bindingsEqual(other, binding))) return 'conflict'
|
||||
return 'ok'
|
||||
}
|
||||
|
|
@ -7,6 +7,12 @@
|
|||
* 会按按钮文案的签名重新挂回去;卡片作答后(aria-busy)立即移除。
|
||||
*/
|
||||
import { actionButtons } from './approval-keys.js'
|
||||
import {
|
||||
BINDINGS_CHANGED_EVENT,
|
||||
DEFAULT_BINDINGS,
|
||||
bindingKeycap,
|
||||
type ApprovalBindings,
|
||||
} from './bindings.js'
|
||||
|
||||
export const HINT_ATTR = 'data-better-chat-keyhint'
|
||||
const CARD_SELECTOR = '[data-approval-key]'
|
||||
|
|
@ -29,16 +35,22 @@ export function isMacPlatform(platform: string | undefined | null): boolean {
|
|||
}
|
||||
|
||||
/**
|
||||
* 纯函数:根据卡片上实际存在的按钮文案,生成提示的分段。
|
||||
* 没有「始终允许」按钮时就不显示 Ctrl+Enter。
|
||||
* 纯函数:根据卡片上实际存在的按钮文案与当前绑定,生成提示的分段。
|
||||
* 「始终允许」被关掉(binding 为 null)时就不显示这一段。
|
||||
*/
|
||||
export function hintParts(labels: HintLabels, mac: boolean): HintPart[] {
|
||||
export function hintParts(
|
||||
labels: HintLabels,
|
||||
mac: boolean,
|
||||
bindings: ApprovalBindings = DEFAULT_BINDINGS,
|
||||
): HintPart[] {
|
||||
const parts: HintPart[] = []
|
||||
if (labels.allow) parts.push({ key: 'Enter', label: labels.allow })
|
||||
if (labels.allow) parts.push({ key: bindingKeycap(bindings.allow, mac), label: labels.allow })
|
||||
// Use the word "Cmd" instead of the ⌘ glyph: the glyph falls back to a CJK
|
||||
// character under some font stacks, while "Cmd" is always legible.
|
||||
if (labels.always) parts.push({ key: mac ? 'Cmd+Enter' : 'Ctrl+Enter', label: labels.always })
|
||||
if (labels.reject) parts.push({ key: 'Esc', label: labels.reject })
|
||||
if (labels.always && bindings.always) {
|
||||
parts.push({ key: bindingKeycap(bindings.always, mac), label: labels.always })
|
||||
}
|
||||
if (labels.reject) parts.push({ key: bindingKeycap(bindings.reject, mac), label: labels.reject })
|
||||
return parts
|
||||
}
|
||||
|
||||
|
|
@ -115,15 +127,18 @@ function removeHints(doc: Document): void {
|
|||
for (const hint of doc.querySelectorAll(`[${HINT_ATTR}]`)) hint.remove()
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装审批卡键盘提示,返回卸载函数。
|
||||
* @param platform 用于区分 Cmd/Ctrl;默认读 navigator.platform。
|
||||
*/
|
||||
export function installKeyHints(
|
||||
doc: Document,
|
||||
platform: string | undefined | null = doc.defaultView?.navigator?.platform,
|
||||
): () => void {
|
||||
export interface KeyHintOptions {
|
||||
/** 用于区分 Cmd/Ctrl;默认读 navigator.platform。 */
|
||||
platform?: string | null
|
||||
/** 当前绑定;设置页保存后会派发 BINDINGS_CHANGED_EVENT 触发重建。 */
|
||||
getBindings?: () => ApprovalBindings
|
||||
}
|
||||
|
||||
/** 安装审批卡键盘提示,返回卸载函数。 */
|
||||
export function installKeyHints(doc: Document, options: KeyHintOptions = {}): () => void {
|
||||
const platform = options.platform ?? doc.defaultView?.navigator?.platform
|
||||
const mac = isMacPlatform(platform)
|
||||
const getBindings = options.getBindings ?? (() => DEFAULT_BINDINGS)
|
||||
let disposed = false
|
||||
|
||||
const syncCard = (card: Element): void => {
|
||||
|
|
@ -139,7 +154,7 @@ export function installKeyHints(
|
|||
allow: labelOf(buttons[1]),
|
||||
always: labelOf(always),
|
||||
reject: labelOf(buttons[0]),
|
||||
}, mac)
|
||||
}, mac, getBindings())
|
||||
if (parts.length === 0) {
|
||||
existing?.remove()
|
||||
return
|
||||
|
|
@ -171,11 +186,14 @@ export function installKeyHints(
|
|||
attributes: true,
|
||||
attributeFilter: ['aria-busy', 'disabled'],
|
||||
})
|
||||
const view = doc.defaultView
|
||||
view?.addEventListener?.(BINDINGS_CHANGED_EVENT, sync)
|
||||
sync()
|
||||
|
||||
return () => {
|
||||
disposed = true
|
||||
observer.disconnect()
|
||||
view?.removeEventListener?.(BINDINGS_CHANGED_EVENT, sync)
|
||||
removeHints(doc)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
*
|
||||
* 两个半场共用一个 client 产物:
|
||||
* - 阅读视图(原 dsh-better-display):reader-plugin.tsx 及其整棵 React 源码树;
|
||||
* - 聊天增强(原 dsh-better-chat):审批键盘、权限 UI、商店更新按钮。
|
||||
* - 聊天增强(原 dsh-better-chat):审批键盘/提示、权限 UI、商店更新按钮。
|
||||
*
|
||||
* 入口必须导出一个静态字符串 inject 数组(宿主 Cordis 服务注入),
|
||||
* 并在这里统一 apply。
|
||||
* 并在这里统一 apply。审批快捷键的配置存在 dsh.better-chat.v1,由设置页写入。
|
||||
*/
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import { install as installApprovalKeys } from './chat/approval-keys.js'
|
||||
import { createChatStore, currentBindings } from './chat/bindings-store.js'
|
||||
import { installKeyHints } from './chat/key-hint.js'
|
||||
import { installPermissionPolicy } from './chat/permission-policy.js'
|
||||
import { storeUpdatePlugin } from './chat/store-update.js'
|
||||
|
|
@ -28,9 +29,13 @@ export const inject = [
|
|||
]
|
||||
|
||||
export function apply(ctx: Context): void {
|
||||
// 审批快捷键:持久化实例在 apply 里创建,避免模块级单例跨插件重载残留。
|
||||
const chatPrefs = createChatStore().create()
|
||||
const getBindings = () => currentBindings(chatPrefs)
|
||||
|
||||
// 聊天增强:纯 DOM 观察,不依赖任何宿主服务。
|
||||
ctx.effect(() => installApprovalKeys(document), 'dsh-better-chat: approval enter/esc routing')
|
||||
ctx.effect(() => installKeyHints(document), 'dsh-better-chat: approval key hints')
|
||||
ctx.effect(() => installApprovalKeys(document, getBindings), 'dsh-better-chat: approval key routing')
|
||||
ctx.effect(() => installKeyHints(document, { getBindings }), 'dsh-better-chat: approval key hints')
|
||||
ctx.effect(
|
||||
() => installPermissionPolicy(document),
|
||||
'dsh-better-chat: permission policy (no full access)',
|
||||
|
|
@ -41,7 +46,7 @@ export function apply(ctx: Context): void {
|
|||
// 子插件挂不上(旧宿主等)不影响主功能。
|
||||
}
|
||||
|
||||
// 阅读视图:注册 slots、设置页与文本变换服务。
|
||||
applyReader(ctx)
|
||||
// 阅读视图:注册 slots、设置页(含快捷键配置)与文本变换服务。
|
||||
applyReader(ctx, { chatPrefs })
|
||||
void readerName
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { Reader } from './Reader.js';
|
|||
import { createReaderStore } from './store.js';
|
||||
import { installReaderEntry } from './entry.js';
|
||||
import { installBetterDisplaySettings } from './settings.js';
|
||||
import type { ChatPrefs } from './chat/bindings-store.js';
|
||||
import { fillComposerDom } from './mcp-app.js';
|
||||
import { fileAddressFor, modeFromSnapshot, openDeliverableFile } from './open-file.js';
|
||||
import type { ReaderInjected } from './types.js';
|
||||
|
|
@ -65,7 +66,7 @@ export const inject = ['slots', 'sessions', 'conversation', 'uiConversation', 'r
|
|||
// All CSS imports have injected their nodes before this module's body runs.
|
||||
ensureStyles();
|
||||
|
||||
export function apply(ctx: Context): void {
|
||||
export function apply(ctx: Context, options: { chatPrefs?: ChatPrefs } = {}): void {
|
||||
const textTransform = createTextTransformRegistry();
|
||||
const restoreTextTransform = installTextTransformRegistry(textTransform);
|
||||
ctx.provide(TEXT_TRANSFORM_SERVICE, textTransform);
|
||||
|
|
@ -75,7 +76,7 @@ export function apply(ctx: Context): void {
|
|||
// `dsh.reader.v1.<sessionId>`. One root instance keeps glass, fold
|
||||
// intensity, and open-mode on the unsuffixed `dsh.reader.v1` key.
|
||||
const prefs = store.create();
|
||||
installBetterDisplaySettings(ctx, prefs);
|
||||
installBetterDisplaySettings(ctx, prefs, options.chatPrefs);
|
||||
ctx.slots.inject('conversation.chat.node', function* () {
|
||||
yield ctx.slots.register({
|
||||
name: 'conversation.view',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,18 @@ export type SettingsCopyKey =
|
|||
| 'foldNone'
|
||||
| 'foldStandard'
|
||||
| 'foldSummary'
|
||||
| 'shortcutTitle'
|
||||
| 'shortcutDescription'
|
||||
| 'shortcutAllow'
|
||||
| 'shortcutAlways'
|
||||
| 'shortcutReject'
|
||||
| 'shortcutRecording'
|
||||
| 'shortcutDisabled'
|
||||
| 'shortcutDisable'
|
||||
| 'shortcutReset'
|
||||
| 'shortcutErrorKey'
|
||||
| 'shortcutErrorModifier'
|
||||
| 'shortcutErrorConflict'
|
||||
| 'skillTitle'
|
||||
| 'skillInstalled'
|
||||
| 'skillMissing'
|
||||
|
|
@ -22,7 +34,7 @@ export type SettingsCopyKey =
|
|||
export type SettingsCopy = Record<SettingsCopyKey, string>;
|
||||
|
||||
export const en: SettingsCopy = {
|
||||
nav: 'Better Display',
|
||||
nav: 'Better Chat',
|
||||
openTitle: 'Open deliverables in built-in panel',
|
||||
openDescription: 'Off by default: chips and inline file mentions open in the system app. Turn this on to preview them in the right Sidebar, matching official chat. Reveal and folder actions still use the system file manager.',
|
||||
glassTitle: 'Translucent frosted glass',
|
||||
|
|
@ -32,6 +44,18 @@ export const en: SettingsCopy = {
|
|||
foldNone: 'Off',
|
||||
foldStandard: 'On',
|
||||
foldSummary: 'Summary',
|
||||
shortcutTitle: 'Approval card shortcuts',
|
||||
shortcutDescription: 'Click a keycap and press the new combination. Allow-type actions use Enter, reject uses Esc; modifiers are free. Esc alone cancels while recording. Stored in the plugin config.',
|
||||
shortcutAllow: 'Allow once',
|
||||
shortcutAlways: 'Always allow',
|
||||
shortcutReject: 'Reject',
|
||||
shortcutRecording: 'Press keys…',
|
||||
shortcutDisabled: 'Not set',
|
||||
shortcutDisable: 'Clear',
|
||||
shortcutReset: 'Restore defaults',
|
||||
shortcutErrorKey: 'Allow actions must use Enter; reject must use Esc.',
|
||||
shortcutErrorModifier: 'Always allow needs at least one modifier key.',
|
||||
shortcutErrorConflict: 'That combination is already used by another action.',
|
||||
skillTitle: 'generative-mcpapps skill',
|
||||
skillInstalled: 'Installed',
|
||||
skillMissing: 'Not detected',
|
||||
|
|
@ -44,7 +68,7 @@ export const en: SettingsCopy = {
|
|||
};
|
||||
|
||||
export const zh: SettingsCopy = {
|
||||
nav: 'Better Display',
|
||||
nav: 'Better Chat',
|
||||
openTitle: '在内置面板中打开产物',
|
||||
openDescription: '默认关闭:产物芯片和正文中的文件提及会用系统应用打开。打开后与官方对话一致,在右侧栏预览。访达 / 资源管理器中的显示与打开所在文件夹不受此开关控制。',
|
||||
glassTitle: '半透明毛玻璃',
|
||||
|
|
@ -54,6 +78,18 @@ export const zh: SettingsCopy = {
|
|||
foldNone: '关闭',
|
||||
foldStandard: '开启',
|
||||
foldSummary: '摘要',
|
||||
shortcutTitle: '审批卡快捷键',
|
||||
shortcutDescription: '点键帽后按下新的组合键。允许类只能用 Enter,拒绝只能用 Esc,修饰键随意;录制时单独按 Esc 取消。保存在插件配置里,重启后仍在。',
|
||||
shortcutAllow: '允许(单次)',
|
||||
shortcutAlways: '始终允许',
|
||||
shortcutReject: '拒绝',
|
||||
shortcutRecording: '按下组合键…',
|
||||
shortcutDisabled: '未设置',
|
||||
shortcutDisable: '清除',
|
||||
shortcutReset: '恢复默认',
|
||||
shortcutErrorKey: '允许类动作只能用 Enter,拒绝只能用 Esc。',
|
||||
shortcutErrorModifier: '「始终允许」至少需要一个修饰键(Ctrl/Shift/Alt)。',
|
||||
shortcutErrorConflict: '这个组合键已经被另一个动作占用。',
|
||||
skillTitle: 'generative-mcpapps 技能',
|
||||
skillInstalled: '已安装',
|
||||
skillMissing: '未检测到',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { settingsCopyFor, zh, en } from './settings-copy.js';
|
|||
import { SettingsSection, type BetterDisplaySettingsInjected, type OpenPrefs } from './SettingsSection.js';
|
||||
import { firstSessionId, skillsFromListResult, type SkillStatusProbe } from './skill-status.js';
|
||||
import type { HostSkillStatus } from '../skill-status.js';
|
||||
import type { ChatPrefs } from './chat/bindings-store.js';
|
||||
|
||||
interface LocaleFace {
|
||||
register?: (ns: string, dicts: { zh: unknown; en: unknown }) => () => void;
|
||||
|
|
@ -50,7 +51,7 @@ function createSkillProbe(ctx: Context): SkillStatusProbe {
|
|||
};
|
||||
}
|
||||
|
||||
export function installBetterDisplaySettings(ctx: Context, prefs: OpenPrefs): void {
|
||||
export function installBetterDisplaySettings(ctx: Context, prefs: OpenPrefs, chat?: ChatPrefs): void {
|
||||
const locale = (ctx.get?.('locale') ?? (ctx as unknown as { locale?: LocaleFace }).locale) as LocaleFace | undefined;
|
||||
if (locale?.register) {
|
||||
ctx.effect(() => locale.register!('better-display', { zh, en }), 'dsh-better-display: settings copy');
|
||||
|
|
@ -58,6 +59,7 @@ export function installBetterDisplaySettings(ctx: Context, prefs: OpenPrefs): vo
|
|||
const checkSkill = createSkillProbe(ctx);
|
||||
const injected = (): BetterDisplaySettingsInjected => ({
|
||||
prefs,
|
||||
chat,
|
||||
copy: settingsCopyFor(languageTag(ctx)),
|
||||
languageTag: languageTag(ctx),
|
||||
checkSkill,
|
||||
|
|
|
|||
|
|
@ -105,6 +105,21 @@ test('Ctrl/Cmd+Enter 只在卡片确实有可用的「始终允许」按钮时
|
|||
// 正在输入控件里打字时,带修饰键的组合键也不拦截。
|
||||
assert.equal(decideKeyAction({ ...baseInput, target: new El('textarea'), ctrlKey: true, hasAlways: true }), null)
|
||||
})
|
||||
test('自定义绑定生效:Shift+Enter 允许、Alt+Esc 拒绝、Ctrl+Enter 不再允许', () => {
|
||||
const bindings = {
|
||||
allow: { key: 'Enter', primary: false, shift: true, alt: false },
|
||||
always: null,
|
||||
reject: { key: 'Escape', primary: false, shift: false, alt: true },
|
||||
} as const
|
||||
assert.equal(decideKeyAction({ ...baseInput, key: 'Enter', shiftKey: true, bindings }), 'allow')
|
||||
assert.equal(decideKeyAction({ ...baseInput, key: 'Enter', ctrlKey: true, bindings }), null)
|
||||
assert.equal(decideKeyAction({ ...baseInput, key: 'Escape', altKey: true, bindings }), 'reject')
|
||||
assert.equal(decideKeyAction({ ...baseInput, key: 'Escape', bindings }), null)
|
||||
// 带 Shift 的 Enter 属于「带修饰键」的绑定,即使焦点在卡内也由插件处理。
|
||||
const card = approvalCard()
|
||||
const inside = card.querySelector('[data-approval-scroll]')
|
||||
assert.equal(decideKeyAction({ ...baseInput, card, activeElement: inside, key: 'Enter', shiftKey: true, bindings }), 'allow')
|
||||
})
|
||||
test('回车落在别的按钮上 → 保留按钮原生行为;Esc 不受此限', () => {
|
||||
const btn = new El('button')
|
||||
assert.equal(decideKeyAction({ ...baseInput, target: btn }), null)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { test } from 'vitest'
|
||||
import {
|
||||
DEFAULT_BINDINGS,
|
||||
bindingKeycap,
|
||||
bindingMatches,
|
||||
bindingsEqual,
|
||||
isPlainBinding,
|
||||
normalizeBindings,
|
||||
validateBinding,
|
||||
type ApprovalBindings,
|
||||
} from '../../src/client/chat/bindings.ts'
|
||||
|
||||
test('defaults: Enter allow, Ctrl+Enter always, Esc reject', () => {
|
||||
assert.deepEqual(DEFAULT_BINDINGS.allow, { key: 'Enter', primary: false, shift: false, alt: false })
|
||||
assert.deepEqual(DEFAULT_BINDINGS.always, { key: 'Enter', primary: true, shift: false, alt: false })
|
||||
assert.deepEqual(DEFAULT_BINDINGS.reject, { key: 'Escape', primary: false, shift: false, alt: false })
|
||||
assert.equal(bindingKeycap(DEFAULT_BINDINGS.allow, false), 'Enter')
|
||||
assert.equal(bindingKeycap(DEFAULT_BINDINGS.always, false), 'Ctrl+Enter')
|
||||
assert.equal(bindingKeycap(DEFAULT_BINDINGS.always, true), 'Cmd+Enter')
|
||||
assert.equal(bindingKeycap(DEFAULT_BINDINGS.reject, false), 'Esc')
|
||||
assert.equal(bindingKeycap({ key: 'Enter', primary: true, shift: true, alt: true }, false), 'Ctrl+Shift+Alt+Enter')
|
||||
})
|
||||
|
||||
test('bindingMatches requires an exact modifier set and treats Ctrl/Meta as primary', () => {
|
||||
const always = DEFAULT_BINDINGS.always!
|
||||
assert.equal(bindingMatches(always, { key: 'Enter', ctrlKey: true }), true)
|
||||
assert.equal(bindingMatches(always, { key: 'Enter', metaKey: true }), true)
|
||||
assert.equal(bindingMatches(always, { key: 'Enter' }), false)
|
||||
assert.equal(bindingMatches(always, { key: 'Enter', ctrlKey: true, shiftKey: true }), false)
|
||||
assert.equal(bindingMatches(DEFAULT_BINDINGS.allow, { key: 'Enter' }), true)
|
||||
assert.equal(bindingMatches(DEFAULT_BINDINGS.allow, { key: 'Enter', altKey: true }), false)
|
||||
assert.equal(isPlainBinding(DEFAULT_BINDINGS.allow), true)
|
||||
assert.equal(isPlainBinding(DEFAULT_BINDINGS.always), false)
|
||||
assert.equal(isPlainBinding(null), false)
|
||||
})
|
||||
|
||||
test('normalizeBindings falls back for missing, invalid, conflicting or modifier-less values', () => {
|
||||
assert.deepEqual(normalizeBindings(undefined), DEFAULT_BINDINGS)
|
||||
const custom = normalizeBindings({
|
||||
allow: { key: 'Escape', primary: false, shift: false, alt: false }, // 允许不能用 Esc
|
||||
always: { key: 'Enter', primary: false, shift: false, alt: false }, // 没有修饰键
|
||||
reject: { key: 'Escape', primary: true, shift: false, alt: false },
|
||||
})
|
||||
assert.equal(custom.allow.key, 'Enter')
|
||||
assert.equal(custom.always?.primary, true)
|
||||
assert.equal(custom.reject.primary, true)
|
||||
|
||||
const disabled = normalizeBindings({ ...DEFAULT_BINDINGS, always: null })
|
||||
assert.equal(disabled.always, null)
|
||||
|
||||
const conflict = normalizeBindings({
|
||||
allow: { key: 'Enter', primary: true, shift: false, alt: false },
|
||||
always: { key: 'Enter', primary: true, shift: false, alt: false },
|
||||
reject: { key: 'Escape', primary: false, shift: false, alt: false },
|
||||
})
|
||||
assert.equal(bindingsEqual(conflict.allow, conflict.always), false)
|
||||
})
|
||||
|
||||
test('validateBinding: base key, modifier requirement, and conflicts', () => {
|
||||
const current: ApprovalBindings = normalizeBindings(undefined)
|
||||
assert.equal(validateBinding('allow', { key: 'Enter', primary: false, shift: true, alt: false }, current), 'ok')
|
||||
assert.equal(validateBinding('reject', { key: 'Escape', primary: false, shift: false, alt: true }, current), 'ok')
|
||||
assert.equal(validateBinding('allow', { key: 'Escape', primary: false, shift: false, alt: false }, current), 'key')
|
||||
assert.equal(validateBinding('always', { key: 'Enter', primary: false, shift: false, alt: false }, current), 'modifier')
|
||||
assert.equal(validateBinding('allow', current.allow, current), 'ok')
|
||||
assert.equal(validateBinding('reject', current.reject, current), 'ok')
|
||||
assert.equal(validateBinding('always', current.always!, current), 'ok')
|
||||
|
||||
const custom = normalizeBindings({
|
||||
allow: { key: 'Enter', primary: false, shift: true, alt: false },
|
||||
always: { key: 'Enter', primary: true, shift: false, alt: false },
|
||||
reject: { key: 'Escape', primary: false, shift: false, alt: false },
|
||||
})
|
||||
assert.equal(validateBinding('always', custom.allow, custom), 'conflict')
|
||||
assert.equal(validateBinding('allow', custom.always, custom), 'conflict')
|
||||
})
|
||||
|
||||
test('validateBinding accepts a shifted Enter as a custom allow binding without colliding', () => {
|
||||
const current = normalizeBindings({
|
||||
allow: { key: 'Enter', primary: false, shift: true, alt: false },
|
||||
always: null,
|
||||
reject: { key: 'Escape', primary: false, shift: false, alt: false },
|
||||
})
|
||||
assert.equal(validateBinding('reject', { key: 'Escape', primary: false, shift: true, alt: false }, current), 'ok')
|
||||
assert.equal(validateBinding('allow', { key: 'Enter', primary: false, shift: true, alt: false }, current), 'ok')
|
||||
})
|
||||
|
|
@ -134,7 +134,7 @@ function textOf(node: FakeEl): string {
|
|||
|
||||
test('installKeyHints inserts the hint as the first child of the action row', () => {
|
||||
const { doc, card, row } = cardWithButtons(['拒绝', '允许(单次)', '始终允许'])
|
||||
const dispose = installKeyHints(doc as unknown as Document, 'Win32')
|
||||
const dispose = installKeyHints(doc as unknown as Document, { platform: 'Win32' })
|
||||
const hint = card.querySelector(`[${HINT_ATTR}]`) as FakeEl | null
|
||||
assert.ok(hint, 'hint must be inserted')
|
||||
assert.equal(row.children[0], hint, 'hint sits before the buttons')
|
||||
|
|
@ -148,7 +148,7 @@ test('installKeyHints inserts the hint as the first child of the action row', ()
|
|||
|
||||
test('installKeyHints omits Ctrl+Enter when there is no always button', () => {
|
||||
const { doc, card } = cardWithButtons(['拒绝', '允许'])
|
||||
const dispose = installKeyHints(doc as unknown as Document, 'Win32')
|
||||
const dispose = installKeyHints(doc as unknown as Document, { platform: 'Win32' })
|
||||
const hint = card.querySelector(`[${HINT_ATTR}]`) as FakeEl
|
||||
assert.equal(textOf(hint).includes('Ctrl+Enter'), false)
|
||||
dispose()
|
||||
|
|
@ -156,7 +156,7 @@ test('installKeyHints omits Ctrl+Enter when there is no always button', () => {
|
|||
|
||||
test('installKeyHints uses Cmd on Apple platforms', () => {
|
||||
const { doc, card } = cardWithButtons(['拒绝', '允许', '始终允许'])
|
||||
const dispose = installKeyHints(doc as unknown as Document, 'MacIntel')
|
||||
const dispose = installKeyHints(doc as unknown as Document, { platform: 'MacIntel' })
|
||||
const hint = card.querySelector(`[${HINT_ATTR}]`) as FakeEl
|
||||
assert.ok(textOf(hint).includes('Cmd+Enter'))
|
||||
dispose()
|
||||
|
|
@ -164,7 +164,7 @@ test('installKeyHints uses Cmd on Apple platforms', () => {
|
|||
|
||||
test('installKeyHints removes the hint once the card is answered', () => {
|
||||
const { doc, card } = cardWithButtons(['拒绝', '允许', '始终允许'])
|
||||
const dispose = installKeyHints(doc as unknown as Document, 'Win32')
|
||||
const dispose = installKeyHints(doc as unknown as Document, { platform: 'Win32' })
|
||||
assert.ok(card.querySelector(`[${HINT_ATTR}]`))
|
||||
card.setAttribute('aria-busy', 'true')
|
||||
observerFire?.()
|
||||
|
|
|
|||
Loading…
Reference in New Issue