Skip to content

Commit 2df61d4

Browse files
committed
feat(context-menu): 添加右键菜单刷新功能并优化终端字体大小设置
- 在网页视图右键菜单中添加刷新选项,支持 CmdOrCtrl+R 快捷键 - 为 webview 上下文菜单添加刷新功能 - 优化预加载脚本中的上下文菜单触发逻辑,过滤可编辑元素和选中文本 - 添加默认终端字体大小配置项,默认值为 15 - 在终端模型中使用统一的默认字体大小常量 - 更新分隔拖拽手柄样式,改进透明度和颜色过渡效果 - 实现窗口标题与标签页名称同步功能,动态更新页面标题显示
1 parent b099994 commit 2df61d4

8 files changed

Lines changed: 84 additions & 21 deletions

File tree

emain/emain-ipc.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,30 @@ export function initIpcHandlers() {
233233
},
234234
})
235235
);
236+
menu.append(new electron.MenuItem({ type: "separator" }));
237+
menu.append(
238+
new electron.MenuItem({
239+
label: "Refresh",
240+
accelerator: "CmdOrCtrl+R",
241+
click: () => {
242+
event.sender.reload();
243+
},
244+
})
245+
);
246+
menu.popup();
247+
});
248+
249+
electron.ipcMain.on("webview-contextmenu", (event: electron.IpcMainEvent) => {
250+
const menu = new electron.Menu();
251+
menu.append(
252+
new electron.MenuItem({
253+
label: "Refresh",
254+
accelerator: "CmdOrCtrl+R",
255+
click: () => {
256+
event.sender.reload();
257+
},
258+
})
259+
);
236260
menu.popup();
237261
});
238262

emain/preload-webview.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import { ipcRenderer } from "electron";
55

66
document.addEventListener("contextmenu", (event) => {
77
console.log("contextmenu event", event);
8-
if (event.target == null) {
8+
if (!event.isTrusted || event.target == null) {
99
return;
1010
}
1111
const targetElement = event.target as HTMLElement;
12+
const selection = document.getSelection()?.toString().trim();
13+
const isEditable =
14+
targetElement.isContentEditable || targetElement.tagName === "INPUT" || targetElement.tagName === "TEXTAREA";
15+
if (selection || isEditable) {
16+
return;
17+
}
1218
// Check if the right-click is on an image
1319
if (targetElement.tagName === "IMG") {
1420
setTimeout(() => {
@@ -22,7 +28,13 @@ document.addEventListener("contextmenu", (event) => {
2228
}, 50);
2329
return;
2430
}
25-
// do nothing
31+
setTimeout(() => {
32+
if (event.defaultPrevented) {
33+
return;
34+
}
35+
event.preventDefault();
36+
ipcRenderer.send("webview-contextmenu");
37+
}, 50);
2638
});
2739

2840
document.addEventListener("mouseup", (event) => {

frontend/app/view/term/term-model.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import { getBlockingCommand } from "./shellblocking";
4343
import { computeTheme, DefaultTermTheme } from "./termutil";
4444
import { TermWrap, WebGLSupported } from "./termwrap";
4545

46+
const DefaultTermFontSize = 15;
47+
4648
export class TermViewModel implements ViewModel {
4749
viewType: string;
4850
nodeModel: BlockNodeModel;
@@ -270,9 +272,10 @@ export class TermViewModel implements ViewModel {
270272
const connName = blockData?.meta?.connection;
271273
const fullConfig = get(atoms.fullConfigAtom);
272274
const connFontSize = fullConfig?.connections?.[connName]?.["term:fontsize"];
273-
const rtnFontSize = blockData?.meta?.["term:fontsize"] ?? connFontSize ?? settingsFontSize ?? 12;
275+
const rtnFontSize =
276+
blockData?.meta?.["term:fontsize"] ?? connFontSize ?? settingsFontSize ?? DefaultTermFontSize;
274277
if (typeof rtnFontSize != "number" || isNaN(rtnFontSize) || rtnFontSize < 4 || rtnFontSize > 64) {
275-
return 12;
278+
return DefaultTermFontSize;
276279
}
277280
return rtnFontSize;
278281
});
@@ -912,7 +915,7 @@ export class TermViewModel implements ViewModel {
912915
const termThemes = fullConfig?.termthemes ?? {};
913916
const termThemeKeys = Object.keys(termThemes);
914917
const curThemeName = globalStore.get(getBlockMetaKeyAtom(this.blockId, "term:theme"));
915-
const defaultFontSize = globalStore.get(getSettingsKeyAtom("term:fontsize")) ?? 12;
918+
const defaultFontSize = globalStore.get(getSettingsKeyAtom("term:fontsize")) ?? DefaultTermFontSize;
916919
const defaultAllowBracketedPaste = globalStore.get(getSettingsKeyAtom("term:allowbracketedpaste")) ?? true;
917920
const transparencyMeta = globalStore.get(getBlockMetaKeyAtom(this.blockId, "term:transparency"));
918921
const blockData = globalStore.get(this.blockAtom);

frontend/app/view/term/termwrap.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ export class TermWrap {
319319
if (event.defaultPrevented || this.terminal.modes.mouseTrackingMode !== "none") {
320320
return;
321321
}
322-
const target = event.target;
323-
if (target instanceof Element && target.closest(".xterm-viewport") != null) {
324-
return;
325-
}
326322
// This relies on xterm.js private internals (`_core._renderService`) because
327323
// there is no public API for measured cell height yet; fall back to 16px
328324
// (a conservative default line height) so wheel deltas still map to lines,

frontend/app/workspace/workspace.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ const WorkspaceElem = memo(() => {
103103
}, []);
104104

105105
const innerHandleVisible = showLeftTabBar && aiPanelVisible;
106-
const innerHandleClass = `bg-transparent hover:bg-zinc-500/20 transition-colors ${innerHandleVisible ? "w-0.5" : "w-0 pointer-events-none"}`;
106+
const innerHandleClass = `transition-colors ${innerHandleVisible ? "w-[3px] cursor-col-resize bg-border/45 hover:bg-accent/45 active:bg-accent/60" : "w-0 pointer-events-none"}`;
107107
const outerHandleVisible = showLeftTabBar || aiPanelVisible;
108-
const outerHandleClass = `bg-transparent hover:bg-zinc-500/20 transition-colors ${outerHandleVisible ? "w-0.5" : "w-0 pointer-events-none"}`;
108+
const outerHandleClass = `transition-colors ${outerHandleVisible ? "w-[3px] cursor-col-resize bg-border/45 hover:bg-accent/45 active:bg-accent/60" : "w-0 pointer-events-none"}`;
109109

110110
return (
111111
<div className="flex flex-col w-full flex-grow overflow-hidden">

frontend/layout/lib/tilelayout.scss

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,34 @@
4343
z-index: var(--zindex-layout-resize-handle);
4444

4545
.line {
46-
visibility: hidden;
46+
opacity: 0.75;
47+
transition:
48+
opacity var(--animation-time-xs) ease,
49+
border-color var(--animation-time-xs) ease;
4750
}
4851
&.flex-row {
4952
cursor: ew-resize;
5053
.line {
5154
height: 100%;
5255
width: calc(50% + 1px);
53-
border-right: 2px solid var(--accent-color);
56+
border-right: 2px solid rgb(from var(--border-color) r g b / 0.95);
5457
}
5558
}
5659
&.flex-column {
5760
cursor: ns-resize;
5861
.line {
5962
height: calc(50% + 1px);
60-
border-bottom: 2px solid var(--accent-color);
63+
border-bottom: 2px solid rgb(from var(--border-color) r g b / 0.95);
6164
}
6265
}
6366
&:hover .line {
64-
visibility: visible;
65-
66-
// Ignore the prefers-reduced-motion override, since we are not applying a true animation here, just a delay.
67-
transition-property: visibility !important;
68-
transition-delay: var(--animation-time-s) !important;
67+
opacity: 1;
68+
}
69+
&.flex-row:hover .line {
70+
border-right-color: var(--accent-color);
71+
}
72+
&.flex-column:hover .line {
73+
border-bottom-color: var(--accent-color);
6974
}
7075
}
7176

frontend/wave.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { createRoot } from "react-dom/client";
3939
const platform = getApi().getPlatform();
4040
document.title = `Wave Terminal`;
4141
let savedInitOpts: WaveInitOpts = null;
42+
let tabTitleUnsub: (() => void) | null = null;
4243

4344
(window as any).WOS = WOS;
4445
(window as any).globalStore = globalStore;
@@ -56,6 +57,27 @@ function updateZoomFactor(zoomFactor: number) {
5657
document.documentElement.style.setProperty("--zoomfactor-inv", String(1 / zoomFactor));
5758
}
5859

60+
function formatWaveWindowTitle(tabName?: string | null) {
61+
const trimmedTabName = tabName?.trim();
62+
return trimmedTabName ? `Wave Terminal - ${trimmedTabName}` : "Wave Terminal";
63+
}
64+
65+
function installWaveWindowTitleSync(tabId: string) {
66+
tabTitleUnsub?.();
67+
tabTitleUnsub = null;
68+
if (!tabId) {
69+
document.title = formatWaveWindowTitle();
70+
return;
71+
}
72+
const tabAtom = WOS.getWaveObjectAtom<Tab>(WOS.makeORef("tab", tabId));
73+
const updateTitle = () => {
74+
const tab = globalStore.get(tabAtom);
75+
document.title = formatWaveWindowTitle(tab?.name);
76+
};
77+
updateTitle();
78+
tabTitleUnsub = globalStore.sub(tabAtom, updateTitle);
79+
}
80+
5981
async function initBare() {
6082
getApi().sendLog("Init Bare");
6183
document.body.style.visibility = "hidden";
@@ -113,7 +135,7 @@ async function reinitWave() {
113135
const initialTab = await WOS.reloadWaveObject<Tab>(WOS.makeORef("tab", savedInitOpts.tabId));
114136
await WOS.reloadWaveObject<LayoutState>(WOS.makeORef("layout", initialTab.layoutstate));
115137
reloadAllWorkspaceTabs(ws);
116-
document.title = `Wave Terminal - ${initialTab.name}`; // TODO update with tab name change
138+
installWaveWindowTitleSync(initialTab.oid);
117139
getApi().setWindowInitStatus("wave-ready");
118140
globalStore.set(atoms.reinitVersion, globalStore.get(atoms.reinitVersion) + 1);
119141
globalStore.set(atoms.updaterStatusAtom, getApi().getUpdaterStatus());
@@ -182,7 +204,7 @@ async function initWave(initOpts: WaveInitOpts) {
182204
]);
183205
loadAllWorkspaceTabs(ws);
184206
WOS.wpsSubscribeToObject(WOS.makeORef("workspace", waveWindow.workspaceid));
185-
document.title = `Wave Terminal - ${initialTab.name}`; // TODO update with tab name change
207+
installWaveWindowTitleSync(initialTab.oid);
186208
} catch (e) {
187209
console.error("Failed initialization error", e);
188210
getApi().sendLog("Error in initialization (wave.ts, loading required objects) " + e.message + "\n" + e.stack);

pkg/wconfig/defaultconfig/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"telemetry:enabled": true,
3333
"term:bellsound": false,
3434
"term:bellindicator": true,
35+
"term:fontsize": 15,
3536
"term:osc52": "always",
3637
"term:cursor": "block",
3738
"term:cursorblink": false,

0 commit comments

Comments
 (0)