Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/pages/options/routes/ScriptEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,18 @@ export default function ScriptEditor() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loadingList, params.uuid]);

// 激活标签 → 同步 URL + 标题
const activeTab = useMemo(() => state.tabs.find((x) => x.uuid === state.activeUuid), [state.tabs, state.activeUuid]);
const activeTabScriptName = activeTab?.script && i18nName(activeTab.script);

Comment on lines +151 to +153

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18nName不可能为空

// 激活标签或其脚本数据变化(如保存后改名) → 同步 URL + 标题
useEffect(() => {
if (!state.activeUuid) return;
if (params.uuid !== state.activeUuid) {
void navigate(`/script/editor/${state.activeUuid}`, { replace: true });
}
const tab = state.tabs.find((x) => x.uuid === state.activeUuid);
if (tab) document.title = `${i18nName(tab.script)} - Script Editor`;
if (activeTabScriptName) document.title = `${activeTabScriptName} - Script Editor`;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.activeUuid]);
}, [state.activeUuid, activeTabScriptName]);
Comment on lines +154 to +162

// 切换标签后把焦点恢复到对应编辑器(各标签实例常驻,仅丢失键盘焦点)
useActiveEditorFocus(state.activeUuid, editorsRef);
Expand All @@ -175,7 +177,6 @@ export default function ScriptEditor() {
return () => window.removeEventListener("beforeunload", onBeforeUnload);
}, [anyChanged]);

const activeTab = useMemo(() => state.tabs.find((x) => x.uuid === state.activeUuid), [state.tabs, state.activeUuid]);
const subView = activeTab?.subView ?? "code";
// 仅后台/定时脚本可运行;普通脚本隐藏「运行」入口(与脚本列表/弹窗一致)
const canRun = !!activeTab && activeTab.script.type !== SCRIPT_TYPE_NORMAL;
Expand Down
Loading