Skip to content

Commit b4f3591

Browse files
committed
改进了标签创建逻辑
#v2.1.3
1 parent cf9f224 commit b4f3591

2 files changed

Lines changed: 66 additions & 19 deletions

File tree

dist/index.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ function O(r, e) {
3535
const t = q(), n = (e == null ? void 0 : e.weekStartsOn) ?? ((c = (i = e == null ? void 0 : e.locale) == null ? void 0 : i.options) == null ? void 0 : c.weekStartsOn) ?? t.weekStartsOn ?? ((l = (d = t.locale) == null ? void 0 : d.options) == null ? void 0 : l.weekStartsOn) ?? 0, a = v(r, e == null ? void 0 : e.in), o = a.getDay(), s = (o < n ? 7 : 0) + o - n;
3636
return a.setDate(a.getDate() - s), a.setHours(0, 0, 0, 0), a;
3737
}
38-
function A(r, e) {
38+
function W(r, e) {
3939
return O(r, { ...e, weekStartsOn: 1 });
4040
}
4141
function ae(r, e) {
4242
const t = v(r, e == null ? void 0 : e.in), n = t.getFullYear(), a = P(t, 0);
4343
a.setFullYear(n + 1, 0, 4), a.setHours(0, 0, 0, 0);
44-
const o = A(a), s = P(t, 0);
44+
const o = W(a), s = P(t, 0);
4545
s.setFullYear(n, 0, 4), s.setHours(0, 0, 0, 0);
46-
const i = A(s);
46+
const i = W(s);
4747
return t.getTime() >= o.getTime() ? n + 1 : t.getTime() >= i.getTime() ? n : n - 1;
4848
}
4949
function X(r) {
@@ -81,7 +81,7 @@ function ge(r, e, t) {
8181
}
8282
function me(r, e) {
8383
const t = ae(r, e), n = P(r, 0);
84-
return n.setFullYear(t, 0, 4), n.setHours(0, 0, 0, 0), A(n);
84+
return n.setFullYear(t, 0, 4), n.setHours(0, 0, 0, 0), W(n);
8585
}
8686
function _(r) {
8787
return P(r, Date.now());
@@ -384,9 +384,9 @@ function L(r) {
384384
const n = t.width, a = n && r.matchPatterns[n] || r.matchPatterns[r.defaultMatchWidth], o = e.match(a);
385385
if (!o)
386386
return null;
387-
const s = o[0], i = n && r.parsePatterns[n] || r.parsePatterns[r.defaultParseWidth], c = Array.isArray(i) ? Ae(i, (u) => u.test(s)) : (
387+
const s = o[0], i = n && r.parsePatterns[n] || r.parsePatterns[r.defaultParseWidth], c = Array.isArray(i) ? We(i, (u) => u.test(s)) : (
388388
// [TODO] -- I challenge you to fix the type
389-
We(i, (u) => u.test(s))
389+
Ae(i, (u) => u.test(s))
390390
);
391391
let d;
392392
d = r.valueCallback ? r.valueCallback(c) : c, d = t.valueCallback ? (
@@ -397,12 +397,12 @@ function L(r) {
397397
return { value: d, rest: l };
398398
};
399399
}
400-
function We(r, e) {
400+
function Ae(r, e) {
401401
for (const t in r)
402402
if (Object.prototype.hasOwnProperty.call(r, t) && e(r[t]))
403403
return t;
404404
}
405-
function Ae(r, e) {
405+
function We(r, e) {
406406
for (let t = 0; t < r.length; t++)
407407
if (e(r[t]))
408408
return t;
@@ -540,7 +540,7 @@ function Ve(r, e) {
540540
return ge(t, ye(t)) + 1;
541541
}
542542
function Ze(r, e) {
543-
const t = v(r, e == null ? void 0 : e.in), n = +A(t) - +me(t);
543+
const t = v(r, e == null ? void 0 : e.in), n = +W(t) - +me(t);
544544
return Math.round(n / te) + 1;
545545
}
546546
function oe(r, e) {
@@ -1261,7 +1261,7 @@ const V = {
12611261
JSON: 0,
12621262
Text: 1
12631263
};
1264-
let W;
1264+
let A;
12651265
class Pt {
12661266
constructor() {
12671267
m(this, "firstPanelTabs", []);
@@ -2301,6 +2301,17 @@ class Pt {
23012301
const a = n.getAttribute("data-block-id");
23022302
return a && this.firstPanelTabs.find((o) => o.blockId === a) || null;
23032303
}
2304+
/**
2305+
* 获取智能插入位置(在当前激活标签后面)
2306+
*/
2307+
getSmartInsertPosition() {
2308+
if (this.currentPanelIndex !== 0 || this.firstPanelTabs.length === 0) return -1;
2309+
const e = this.getCurrentActiveTab();
2310+
if (!e)
2311+
return -1;
2312+
const t = this.firstPanelTabs.findIndex((n) => n.blockId === e.blockId);
2313+
return t === -1 ? -1 : t;
2314+
}
23042315
/**
23052316
* 获取相邻标签(用于关闭当前标签后自动切换)
23062317
*/
@@ -2893,8 +2904,10 @@ class Pt {
28932904
console.log(`⚠️ 所有标签都是固定的,无法添加新标签: "${s.title}"`);
28942905
return;
28952906
}
2896-
} else
2897-
this.firstPanelTabs.push(s), console.log(`➕ 添加新标签: ${s.title} (ID: ${a})`);
2907+
} else {
2908+
const i = this.getSmartInsertPosition();
2909+
i >= 0 && i < this.firstPanelTabs.length ? (this.firstPanelTabs.splice(i + 1, 0, s), console.log(`➕ 在位置 ${i + 1} 插入新标签: ${s.title} (ID: ${a})`)) : (this.firstPanelTabs.push(s), console.log(`➕ 添加新标签到末尾: ${s.title} (ID: ${a})`));
2910+
}
28982911
this.closedTabs.has(a) && (this.closedTabs.delete(a), this.saveClosedTabs(), console.log(`🔄 标签 "${s.title}" 重新显示,从已关闭列表中移除`)), this.saveFirstPanelTabs(), this.debouncedUpdateTabsUI();
28992912
} else
29002913
console.log("无法获取激活页面的标签信息");
@@ -3050,20 +3063,20 @@ class Pt {
30503063
}
30513064
let T = null;
30523065
async function It(r) {
3053-
W = r, de(orca.state.locale, { "zh-CN": ue }), T = new Pt(), document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
3066+
A = r, de(orca.state.locale, { "zh-CN": ue }), T = new Pt(), document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
30543067
setTimeout(() => T == null ? void 0 : T.init(), 500);
30553068
}) : setTimeout(() => T == null ? void 0 : T.init(), 500), orca.commands.registerCommand(
3056-
`${W}.resetCache`,
3069+
`${A}.resetCache`,
30573070
async () => {
30583071
T && (await T.resetCache(), orca.notify("success", "插件缓存已重置", {
30593072
title: "Orca Tabs Plugin"
30603073
}));
30613074
},
30623075
"重置插件缓存"
3063-
), console.log(F("标签页插件已启动")), console.log(`${W} loaded.`);
3076+
), console.log(F("标签页插件已启动")), console.log(`${A} loaded.`);
30643077
}
30653078
async function kt() {
3066-
T && (T.destroy(), T = null), orca.commands.unregisterCommand(`${W}.resetCache`);
3079+
T && (T.destroy(), T = null), orca.commands.unregisterCommand(`${A}.resetCache`);
30673080
}
30683081
export {
30693082
It as load,

src/main.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,32 @@ class OrcaTabsPlugin {
20942094
return this.firstPanelTabs.find(tab => tab.blockId === blockId) || null;
20952095
}
20962096

2097+
/**
2098+
* 获取智能插入位置(在当前激活标签后面)
2099+
*/
2100+
getSmartInsertPosition(): number {
2101+
if (this.currentPanelIndex !== 0) return -1; // 只有第一个面板支持
2102+
2103+
if (this.firstPanelTabs.length === 0) return -1;
2104+
2105+
// 获取当前激活的标签
2106+
const currentActiveTab = this.getCurrentActiveTab();
2107+
if (!currentActiveTab) {
2108+
// 如果没有找到当前激活的标签,返回-1表示添加到末尾
2109+
return -1;
2110+
}
2111+
2112+
// 找到当前激活标签的索引
2113+
const currentIndex = this.firstPanelTabs.findIndex(tab => tab.blockId === currentActiveTab.blockId);
2114+
if (currentIndex === -1) {
2115+
// 如果没有找到索引,返回-1表示添加到末尾
2116+
return -1;
2117+
}
2118+
2119+
// 返回当前标签的索引,新标签将插入到其后面(索引+1的位置)
2120+
return currentIndex;
2121+
}
2122+
20972123
/**
20982124
* 获取相邻标签(用于关闭当前标签后自动切换)
20992125
*/
@@ -3213,9 +3239,17 @@ class OrcaTabsPlugin {
32133239
return;
32143240
}
32153241
} else {
3216-
// 未达到上限,直接添加
3217-
this.firstPanelTabs.push(tabInfo);
3218-
console.log(`➕ 添加新标签: ${tabInfo.title} (ID: ${blockId})`);
3242+
// 未达到上限,智能插入新标签
3243+
const insertPosition = this.getSmartInsertPosition();
3244+
if (insertPosition >= 0 && insertPosition < this.firstPanelTabs.length) {
3245+
// 插入到指定位置
3246+
this.firstPanelTabs.splice(insertPosition + 1, 0, tabInfo);
3247+
console.log(`➕ 在位置 ${insertPosition + 1} 插入新标签: ${tabInfo.title} (ID: ${blockId})`);
3248+
} else {
3249+
// 如果无法确定位置,添加到末尾
3250+
this.firstPanelTabs.push(tabInfo);
3251+
console.log(`➕ 添加新标签到末尾: ${tabInfo.title} (ID: ${blockId})`);
3252+
}
32193253
}
32203254

32213255
// 如果标签页重新显示,从已关闭列表中移除

0 commit comments

Comments
 (0)