Skip to content

Commit d453368

Browse files
authored
updates to match xtermjs's height calcuation. there was discrepancy when devicePixelRatio was not an integer leading to mis-sized terminal windows and cut off lines #302 (#305)
1 parent 0f030ff commit d453368

13 files changed

Lines changed: 137 additions & 21 deletions

File tree

src/app/common/modals/modals.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type OV<V> = mobx.IObservableValue<V>;
4949
type OArr<V> = mobx.IObservableArray<V>;
5050

5151
const RemotePtyRows = 9;
52+
const RemotePtyTotalRows = 25;
5253
const RemotePtyCols = 80;
5354
const NumOfLines = 50;
5455
const PasswordUnchangedSentinel = "--unchanged--";
@@ -1184,7 +1185,11 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
11841185
ref={this.termRef}
11851186
data-remoteid={remote.remoteid}
11861187
style={{
1187-
height: textmeasure.termHeightFromRows(RemotePtyRows, termFontSize),
1188+
height: textmeasure.termHeightFromRows(
1189+
RemotePtyRows,
1190+
termFontSize,
1191+
RemotePtyTotalRows
1192+
),
11881193
width: termWidth,
11891194
}}
11901195
></div>

src/app/common/modals/viewremoteconndetail.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as textmeasure from "../../../util/textmeasure";
1616
import "./viewremoteconndetail.less";
1717

1818
const RemotePtyRows = 9;
19+
const RemotePtyTotalRows = 25;
1920
const RemotePtyCols = 80;
2021

2122
@mobxReact.observer
@@ -371,7 +372,11 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
371372
ref={this.termRef}
372373
data-remoteid={remote.remoteid}
373374
style={{
374-
height: textmeasure.termHeightFromRows(RemotePtyRows, termFontSize),
375+
height: textmeasure.termHeightFromRows(
376+
RemotePtyRows,
377+
termFontSize,
378+
RemotePtyTotalRows
379+
),
375380
width: termWidth,
376381
}}
377382
></div>

src/app/connections_deprecated/connections.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type OArr<V> = mobx.IObservableArray<V>;
2929
type OMap<K, V> = mobx.ObservableMap<K, V>;
3030

3131
const RemotePtyRows = 8;
32+
const RemotePtyTotalRows = 25;
3233
const RemotePtyCols = 80;
3334
const PasswordUnchangedSentinel = "--unchanged--";
3435

@@ -1049,7 +1050,7 @@ class RemoteDetailView extends React.Component<{ model: RemotesModalModel; remot
10491050
ref={this.termRef}
10501051
data-remoteid={remote.remoteid}
10511052
style={{
1052-
height: textmeasure.termHeightFromRows(RemotePtyRows, termFontSize),
1053+
height: textmeasure.termHeightFromRows(RemotePtyRows, termFontSize, RemotePtyTotalRows),
10531054
width: termWidth,
10541055
}}
10551056
></div>

src/app/line/linecomps.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class LineCmd extends React.Component<
399399
let height = 45 + 24; // height of zero height terminal
400400
const usedRows = screen.getUsedRows(lineutil.getRendererContext(line), line, cmd, width);
401401
if (usedRows > 0) {
402-
height = 48 + 24 + termHeightFromRows(usedRows, GlobalModel.termFontSize.get());
402+
height = 48 + 24 + termHeightFromRows(usedRows, GlobalModel.termFontSize.get(), cmd.getTermMaxRows());
403403
}
404404
return height;
405405
}

src/app/line/lines.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
padding: 0 0 10px 0;
465465
flex-grow: 1;
466466
position: relative;
467+
overflow-x: hidden;
467468

468469
&::-webkit-scrollbar-thumb {
469470
background-color: transparent !important;

src/app/magiclayout.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ let MagicLayout = {
1818
ScreenMinContentSize: 100,
1919
ScreenMaxContentSize: 5000,
2020

21-
// the 3 is for descenders, which get cut off in the terminal without this
22-
TermDescendersHeight: 3,
2321
TermWidthBuffer: 15,
2422

2523
TabWidth: 154,

src/app/workspace/screen/screenview.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ import { If, For } from "tsx-control-statements/components";
1010
import cn from "classnames";
1111
import { debounce } from "throttle-debounce";
1212
import dayjs from "dayjs";
13-
import { GlobalCommandRunner, TabColors, TabIcons, ForwardLineContainer, GlobalModel, ScreenLines, Screen, Session } from "../../../model/model";
13+
import {
14+
GlobalCommandRunner,
15+
TabColors,
16+
TabIcons,
17+
ForwardLineContainer,
18+
GlobalModel,
19+
ScreenLines,
20+
Screen,
21+
Session,
22+
} from "../../../model/model";
1423
import type { LineType, RenderModeType, LineFactoryProps } from "../../../types/types";
1524
import * as T from "../../../types/types";
1625
import localizedFormat from "dayjs/plugin/localizedFormat";
@@ -114,6 +123,7 @@ class ScreenView extends React.Component<{ session: Session; screen: Screen }, {
114123
return <div className="screen-view" ref={this.screenViewRef}></div>;
115124
}
116125
let fontSize = GlobalModel.termFontSize.get();
126+
let dprStr = sprintf("%0.3f", GlobalModel.devicePixelRatio.get());
117127
let viewOpts = screen.viewOpts.get();
118128
let hasSidebar = viewOpts?.sidebar?.open;
119129
let winWidth = "100%";
@@ -150,7 +160,7 @@ class ScreenView extends React.Component<{ session: Session; screen: Screen }, {
150160
return (
151161
<div className="screen-view" data-screenid={screen.screenId} ref={this.screenViewRef}>
152162
<ScreenWindowView
153-
key={screen.screenId + ":" + fontSize}
163+
key={screen.screenId + ":" + fontSize + ":" + dprStr}
154164
session={session}
155165
screen={screen}
156166
width={winWidth}

src/electron/emain.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function readAuthKey() {
170170
return authKeyStr.trim();
171171
}
172172

173+
let cmdOrAlt = process.platform === "darwin" ? "Cmd" : "Alt";
173174
let menuTemplate = [
174175
{
175176
role: "appMenu",
@@ -198,9 +199,41 @@ let menuTemplate = [
198199
{ role: "reload", accelerator: "Option+R" },
199200
{ role: "toggleDevTools" },
200201
{ type: "separator" },
201-
{ role: "resetZoom" },
202-
{ role: "zoomIn" },
203-
{ role: "zoomOut" },
202+
{
203+
label: "Actual Size",
204+
accelerator: cmdOrAlt + "+0",
205+
click: () => {
206+
if (MainWindow == null) {
207+
return;
208+
}
209+
MainWindow.webContents.setZoomFactor(1);
210+
MainWindow.webContents.send("zoom-changed");
211+
},
212+
},
213+
{
214+
label: "Zoom In",
215+
accelerator: cmdOrAlt + "+Plus",
216+
click: () => {
217+
if (MainWindow == null) {
218+
return;
219+
}
220+
const zoomFactor = MainWindow.webContents.getZoomFactor();
221+
MainWindow.webContents.setZoomFactor(zoomFactor * 1.1);
222+
MainWindow.webContents.send("zoom-changed");
223+
},
224+
},
225+
{
226+
label: "Zoom Out",
227+
accelerator: cmdOrAlt + "+-",
228+
click: () => {
229+
if (MainWindow == null) {
230+
return;
231+
}
232+
const zoomFactor = MainWindow.webContents.getZoomFactor();
233+
MainWindow.webContents.setZoomFactor(zoomFactor / 1.1);
234+
MainWindow.webContents.send("zoom-changed");
235+
},
236+
},
204237
{ type: "separator" },
205238
{ role: "togglefullscreen" },
206239
],
@@ -367,6 +400,9 @@ function createMainWindow(clientData) {
367400
win.on("close", () => {
368401
MainWindow = null;
369402
});
403+
win.webContents.on("zoom-changed", (e) => {
404+
win.webContents.send("zoom-changed");
405+
});
370406
win.webContents.setWindowOpenHandler(({ url, frameName }) => {
371407
if (url.startsWith("https://docs.waveterm.dev/")) {
372408
console.log("openExternal docs", url);

src/electron/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ contextBridge.exposeInMainWorld("api", {
2020
onWCmd: (callback) => ipcRenderer.on("w-cmd", callback),
2121
onPCmd: (callback) => ipcRenderer.on("p-cmd", callback),
2222
onRCmd: (callback) => ipcRenderer.on("r-cmd", callback),
23+
onZoomChanged: (callback) => ipcRenderer.on("zoom-changed", callback),
2324
onMetaArrowUp: (callback) => ipcRenderer.on("meta-arrowup", callback),
2425
onMetaArrowDown: (callback) => ipcRenderer.on("meta-arrowdown", callback),
2526
onMetaPageUp: (callback) => ipcRenderer.on("meta-pageup", callback),

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { sprintf } from "sprintf-js";
88
import { App } from "./app/app";
99
import * as DOMPurify from "dompurify";
1010
import { loadFonts } from "./util/util";
11+
import * as textmeasure from "./util/textmeasure";
1112

1213
// @ts-ignore
1314
let VERSION = __WAVETERM_VERSION__;
@@ -28,5 +29,6 @@ document.addEventListener("DOMContentLoaded", () => {
2829
(window as any).mobx = mobx;
2930
(window as any).sprintf = sprintf;
3031
(window as any).DOMPurify = DOMPurify;
32+
(window as any).textmeasure = textmeasure;
3133

3234
console.log("WaveTerm", VERSION, BUILD);

0 commit comments

Comments
 (0)