Skip to content

Commit b149117

Browse files
committed
微调 V2.01
1 parent f4ced17 commit b149117

2 files changed

Lines changed: 165 additions & 20 deletions

File tree

dist/index.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const Te = {
212212
tomorrow: "'tomorrow at' p",
213213
nextWeek: "eeee 'at' p",
214214
other: "P"
215-
}, Me = (r, e, t, n) => ke[r];
215+
}, Ce = (r, e, t, n) => ke[r];
216216
function D(r) {
217217
return (e, t) => {
218218
const n = t != null && t.context ? String(t.context) : "standalone";
@@ -228,7 +228,7 @@ function D(r) {
228228
return a[o];
229229
};
230230
}
231-
const Ce = {
231+
const Me = {
232232
narrow: ["B", "A"],
233233
abbreviated: ["BC", "AD"],
234234
wide: ["Before Christ", "Anno Domini"]
@@ -356,7 +356,7 @@ const Ce = {
356356
}, Fe = {
357357
ordinalNumber: Oe,
358358
era: D({
359-
values: Ce,
359+
values: Me,
360360
defaultWidth: "wide"
361361
}),
362362
quarter: D({
@@ -527,7 +527,7 @@ const qe = /^(\d+)(th|st|nd|rd)?/i, Ye = /\d+/i, Be = {
527527
code: "en-US",
528528
formatDistance: xe,
529529
formatLong: Ie,
530-
formatRelative: Me,
530+
formatRelative: Ce,
531531
localize: Fe,
532532
match: Ge,
533533
options: {
@@ -619,7 +619,7 @@ const I = {
619619
);
620620
return b(a, e.length);
621621
}
622-
}, C = {
622+
}, M = {
623623
midnight: "midnight",
624624
noon: "noon",
625625
morning: "morning",
@@ -961,7 +961,7 @@ const I = {
961961
b: function(r, e, t) {
962962
const n = r.getHours();
963963
let a;
964-
switch (n === 12 ? a = C.noon : n === 0 ? a = C.midnight : a = n / 12 >= 1 ? "pm" : "am", e) {
964+
switch (n === 12 ? a = M.noon : n === 0 ? a = M.midnight : a = n / 12 >= 1 ? "pm" : "am", e) {
965965
case "b":
966966
case "bb":
967967
return t.dayPeriod(a, {
@@ -990,7 +990,7 @@ const I = {
990990
B: function(r, e, t) {
991991
const n = r.getHours();
992992
let a;
993-
switch (n >= 17 ? a = C.evening : n >= 12 ? a = C.afternoon : n >= 4 ? a = C.morning : a = C.night, e) {
993+
switch (n >= 17 ? a = M.evening : n >= 12 ? a = M.afternoon : n >= 4 ? a = M.morning : a = M.night, e) {
994994
case "B":
995995
case "BB":
996996
case "BBB":
@@ -1055,11 +1055,11 @@ const I = {
10551055
return J(n);
10561056
case "XXXX":
10571057
case "XX":
1058-
return M(n);
1058+
return C(n);
10591059
case "XXXXX":
10601060
case "XXX":
10611061
default:
1062-
return M(n, ":");
1062+
return C(n, ":");
10631063
}
10641064
},
10651065
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
@@ -1070,11 +1070,11 @@ const I = {
10701070
return J(n);
10711071
case "xxxx":
10721072
case "xx":
1073-
return M(n);
1073+
return C(n);
10741074
case "xxxxx":
10751075
case "xxx":
10761076
default:
1077-
return M(n, ":");
1077+
return C(n, ":");
10781078
}
10791079
},
10801080
// Timezone (GMT)
@@ -1087,7 +1087,7 @@ const I = {
10871087
return "GMT" + K(n, ":");
10881088
case "OOOO":
10891089
default:
1090-
return "GMT" + M(n, ":");
1090+
return "GMT" + C(n, ":");
10911091
}
10921092
},
10931093
// Timezone (specific non-location)
@@ -1100,7 +1100,7 @@ const I = {
11001100
return "GMT" + K(n, ":");
11011101
case "zzzz":
11021102
default:
1103-
return "GMT" + M(n, ":");
1103+
return "GMT" + C(n, ":");
11041104
}
11051105
},
11061106
// Seconds timestamp
@@ -1118,9 +1118,9 @@ function K(r, e = "") {
11181118
return o === 0 ? t + String(a) : t + String(a) + e + b(o, 2);
11191119
}
11201120
function J(r, e) {
1121-
return r % 60 === 0 ? (r > 0 ? "-" : "+") + b(Math.abs(r) / 60, 2) : M(r, e);
1121+
return r % 60 === 0 ? (r > 0 ? "-" : "+") + b(Math.abs(r) / 60, 2) : C(r, e);
11221122
}
1123-
function M(r, e = "") {
1123+
function C(r, e = "") {
11241124
const t = r > 0 ? "-" : "+", n = Math.abs(r), a = b(Math.trunc(n / 60), 2), o = b(n % 60, 2);
11251125
return t + a + e + o;
11261126
}
@@ -2353,12 +2353,56 @@ class Pt {
23532353
this.firstPanelTabs = t, this.debouncedUpdateTabsUI(), this.saveFirstPanelTabs(), this.saveClosedTabs(), console.log(`🗑️ 已关闭其他 ${a} 个标签,保留了当前标签和固定标签`);
23542354
}
23552355
/**
2356-
* 重命名标签(使用Orca原生InputBox
2356+
* 重命名标签(内联编辑
23572357
*/
23582358
renameTab(e) {
23592359
if (this.currentPanelIndex !== 0) return;
23602360
const t = document.querySelector(".tab-context-menu");
2361-
t && t.remove(), this.showOrcaRenameInput(e);
2361+
t && t.remove(), this.showInlineRenameInput(e);
2362+
}
2363+
/**
2364+
* 显示内联重命名输入框
2365+
*/
2366+
showInlineRenameInput(e) {
2367+
const t = document.querySelector(`[data-tab-id="${e.blockId}"]`);
2368+
if (!t) {
2369+
console.warn("找不到对应的标签元素");
2370+
return;
2371+
}
2372+
const n = t.querySelector(".inline-rename-input");
2373+
n && n.remove();
2374+
const a = t.textContent, o = t.style.cssText, s = document.createElement("input");
2375+
s.type = "text", s.value = e.title, s.className = "inline-rename-input";
2376+
const i = orca.state.themeMode === "dark";
2377+
let c = i ? "rgba(255, 255, 255, 0.1)" : "rgba(200, 200, 200, 0.6)", d = i ? "#ffffff" : "#333";
2378+
e.color && (c = this.applyOklchFormula(e.color, "background"), d = this.applyOklchFormula(e.color, "text")), s.style.cssText = `
2379+
background: ${c};
2380+
color: ${d};
2381+
border: 2px solid #3b82f6;
2382+
border-radius: 4px;
2383+
padding: 2px 8px;
2384+
height: 20px;
2385+
line-height: 20px;
2386+
font-size: 12px;
2387+
font-weight: 600;
2388+
outline: none;
2389+
width: 100%;
2390+
max-width: 150px;
2391+
box-sizing: border-box;
2392+
-webkit-app-region: no-drag;
2393+
app-region: no-drag;
2394+
`, t.textContent = "", t.appendChild(s), t.style.padding = "2px 8px", s.focus(), s.select();
2395+
const l = () => {
2396+
const h = s.value.trim();
2397+
h && h !== e.title && this.updateTabTitle(e, h), t.textContent = a, t.style.cssText = o;
2398+
}, u = () => {
2399+
t.textContent = a, t.style.cssText = o;
2400+
};
2401+
s.addEventListener("blur", l), s.addEventListener("keydown", (h) => {
2402+
h.key === "Enter" ? (h.preventDefault(), l()) : h.key === "Escape" && (h.preventDefault(), u());
2403+
}), s.addEventListener("click", (h) => {
2404+
h.stopPropagation();
2405+
});
23622406
}
23632407
/**
23642408
* 使用Orca原生InputBox显示重命名输入框

src/main.ts

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ class OrcaTabsPlugin {
22322232
}
22332233

22342234
/**
2235-
* 重命名标签(使用Orca原生InputBox
2235+
* 重命名标签(内联编辑
22362236
*/
22372237
renameTab(tab: TabInfo) {
22382238
if (this.currentPanelIndex !== 0) return; // 只有第一个面板支持重命名功能
@@ -2243,8 +2243,109 @@ class OrcaTabsPlugin {
22432243
existingMenu.remove();
22442244
}
22452245

2246-
// 使用Orca原生InputBox进行重命名
2247-
this.showOrcaRenameInput(tab);
2246+
// 使用内联编辑进行重命名
2247+
this.showInlineRenameInput(tab);
2248+
}
2249+
2250+
/**
2251+
* 显示内联重命名输入框
2252+
*/
2253+
showInlineRenameInput(tab: TabInfo) {
2254+
// 查找对应的标签元素
2255+
const tabElement = document.querySelector(`[data-tab-id="${tab.blockId}"]`) as HTMLElement;
2256+
if (!tabElement) {
2257+
console.warn("找不到对应的标签元素");
2258+
return;
2259+
}
2260+
2261+
// 移除现有的内联输入框
2262+
const existingInput = tabElement.querySelector('.inline-rename-input');
2263+
if (existingInput) {
2264+
existingInput.remove();
2265+
}
2266+
2267+
// 保存原始内容
2268+
const originalContent = tabElement.textContent;
2269+
const originalStyle = tabElement.style.cssText;
2270+
2271+
// 创建输入框
2272+
const input = document.createElement('input');
2273+
input.type = 'text';
2274+
input.value = tab.title;
2275+
input.className = 'inline-rename-input';
2276+
2277+
// 设置输入框样式,使其与标签样式一致
2278+
const isDarkMode = orca.state.themeMode === 'dark';
2279+
let backgroundColor = isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(200, 200, 200, 0.6)';
2280+
let textColor = isDarkMode ? '#ffffff' : '#333';
2281+
2282+
// 如果有颜色,应用颜色样式
2283+
if (tab.color) {
2284+
backgroundColor = this.applyOklchFormula(tab.color, 'background');
2285+
textColor = this.applyOklchFormula(tab.color, 'text');
2286+
}
2287+
2288+
input.style.cssText = `
2289+
background: ${backgroundColor};
2290+
color: ${textColor};
2291+
border: 2px solid #3b82f6;
2292+
border-radius: 4px;
2293+
padding: 2px 8px;
2294+
height: 20px;
2295+
line-height: 20px;
2296+
font-size: 12px;
2297+
font-weight: 600;
2298+
outline: none;
2299+
width: 100%;
2300+
max-width: 150px;
2301+
box-sizing: border-box;
2302+
-webkit-app-region: no-drag;
2303+
app-region: no-drag;
2304+
`;
2305+
2306+
// 隐藏标签文本,显示输入框
2307+
tabElement.textContent = '';
2308+
tabElement.appendChild(input);
2309+
tabElement.style.padding = '2px 8px'; // 保持原有padding
2310+
2311+
// 选中输入框中的文本
2312+
input.focus();
2313+
input.select();
2314+
2315+
// 确认重命名
2316+
const confirmRename = () => {
2317+
const newTitle = input.value.trim();
2318+
if (newTitle && newTitle !== tab.title) {
2319+
this.updateTabTitle(tab, newTitle);
2320+
}
2321+
// 恢复标签显示
2322+
tabElement.textContent = originalContent;
2323+
tabElement.style.cssText = originalStyle;
2324+
};
2325+
2326+
// 取消重命名
2327+
const cancelRename = () => {
2328+
// 恢复标签显示
2329+
tabElement.textContent = originalContent;
2330+
tabElement.style.cssText = originalStyle;
2331+
};
2332+
2333+
// 添加事件监听器
2334+
input.addEventListener('blur', confirmRename);
2335+
input.addEventListener('keydown', (e) => {
2336+
if (e.key === 'Enter') {
2337+
e.preventDefault();
2338+
confirmRename();
2339+
} else if (e.key === 'Escape') {
2340+
e.preventDefault();
2341+
cancelRename();
2342+
}
2343+
});
2344+
2345+
// 防止点击事件冒泡
2346+
input.addEventListener('click', (e) => {
2347+
e.stopPropagation();
2348+
});
22482349
}
22492350

22502351
/**

0 commit comments

Comments
 (0)