Skip to content

Commit c5afeb8

Browse files
authored
simplify scrollbar code in terminal, simplify fit code (#2944)
1 parent f1e06c7 commit c5afeb8

File tree

5 files changed

+21
-61
lines changed

5 files changed

+21
-61
lines changed

frontend/app/theme.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
--accent-color: rgb(88, 193, 66);
1515
--panel-bg-color: rgba(31, 33, 31, 0.5);
1616
--highlight-bg-color: rgba(255, 255, 255, 0.2);
17-
--markdown-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif,
18-
"Apple Color Emoji", "Segoe UI Emoji";
17+
--markdown-font-family:
18+
-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji",
19+
"Segoe UI Emoji";
1920
--markdown-font-size: 14px;
2021
--markdown-fixed-font-size: 12px;
2122
--error-color: rgb(229, 77, 46);
@@ -66,7 +67,6 @@
6667
--zindex-layout-ephemeral-node: 9;
6768
--zindex-block-mask-inner: 10;
6869
--zindex-app-background: -1;
69-
7070
// z-indexes in xterm.css
7171
// xterm-helpers: 5
7272
// xterm-helper-textarea: -5
@@ -76,7 +76,6 @@
7676
// xterm-decoration-top-layer: 7
7777
// xterm-decoration-overview-ruler: 8
7878
// xterm-decoration-top: 2
79-
--zindex-xterm-viewport-overlay: 5; // Viewport contains the scrollbar
8079

8180
// modal colors
8281
--modal-bg-color: #232323;

frontend/app/view/term/fitaddon.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const MINIMUM_ROWS = 1;
2727

2828
export class FitAddon implements ITerminalAddon, IFitApi {
2929
private _terminal: Terminal | undefined;
30-
public noScrollbar: boolean = false;
30+
public scrollbarWidth: number | null = null;
3131

3232
public activate(terminal: Terminal): void {
3333
this._terminal = terminal;
@@ -68,12 +68,12 @@ export class FitAddon implements ITerminalAddon, IFitApi {
6868
return undefined;
6969
}
7070

71-
// UPDATED CODE (removed reliance on FALLBACK_SCROLL_BAR_WIDTH in viewport)
72-
const measuredScrollBarWidth =
73-
core.viewport._viewportElement.offsetWidth - core.viewport._scrollArea.offsetWidth;
74-
let scrollbarWidth = this._terminal.options.scrollback === 0 ? 0 : measuredScrollBarWidth;
75-
if (this.noScrollbar) {
76-
scrollbarWidth = 0;
71+
// UPDATED CODE (removed reliance on FALLBACK_SCROLL_BAR_WIDTH in viewport, allow just setting the scrollbar width when known)
72+
let scrollbarWidth: number;
73+
if (this.scrollbarWidth != null) {
74+
scrollbarWidth = this.scrollbarWidth;
75+
} else {
76+
scrollbarWidth = core.viewport._viewportElement.offsetWidth - core.viewport._scrollArea.offsetWidth;
7777
}
7878
// END UPDATED CODE
7979

frontend/app/view/term/term.scss

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
min-height: 0;
6060
overflow: hidden;
6161
line-height: 1;
62-
margin: 5px;
63-
margin-left: 4px;
62+
margin: 5px 1px 5px 4px;
6463
}
6564

6665
.term-htmlelem {
@@ -126,30 +125,12 @@
126125
}
127126
}
128127

129-
// The 18px width is the width of the scrollbar plus the margin
130-
.term-scrollbar-show-observer {
131-
z-index: calc(var(--zindex-xterm-viewport-overlay) - 1);
132-
position: absolute;
133-
top: 0;
134-
right: 0;
135-
height: 100%;
136-
width: 18px;
137-
}
138-
139-
.term-scrollbar-hide-observer {
140-
z-index: calc(var(--zindex-xterm-viewport-overlay) + 1);
141-
display: none;
142-
position: absolute;
143-
top: 0;
144-
left: 0;
145-
height: 100%;
146-
width: calc(100% - 18px);
147-
}
148-
149128
.terminal {
129+
width: 100%;
130+
150131
.xterm-viewport {
151132
&::-webkit-scrollbar {
152-
width: 6px;
133+
width: 6px; /* this needs to match fitAddon.scrollbarWidth in termwrap.ts */
153134
height: 6px;
154135
}
155136

@@ -158,24 +139,23 @@
158139
}
159140

160141
&::-webkit-scrollbar-thumb {
161-
display: none;
162-
background-color: var(--scrollbar-thumb-color);
142+
background-color: transparent;
163143
border-radius: 4px;
164144
margin: 0 1px 0 1px;
165145

166146
&:hover {
167-
background-color: var(--scrollbar-thumb-hover-color);
147+
background-color: var(--scrollbar-thumb-hover-color) !important;
168148
}
169149

170150
&:active {
171-
background-color: var(--scrollbar-thumb-active-color);
151+
background-color: var(--scrollbar-thumb-active-color) !important;
172152
}
173153
}
174154
}
175155

176156
&:hover {
177157
.xterm-viewport::-webkit-scrollbar-thumb {
178-
display: block;
158+
background-color: var(--scrollbar-thumb-color);
179159
}
180160
}
181161
}

frontend/app/view/term/term.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,6 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
354354
}
355355
}, [isMI, isBasicTerm, isFocused]);
356356

357-
const scrollbarHideObserverRef = React.useRef<HTMLDivElement>(null);
358-
const onScrollbarShowObserver = React.useCallback(() => {
359-
const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement;
360-
termViewport.style.zIndex = "var(--zindex-xterm-viewport-overlay)";
361-
scrollbarHideObserverRef.current.style.display = "block";
362-
}, []);
363-
const onScrollbarHideObserver = React.useCallback(() => {
364-
const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement;
365-
termViewport.style.zIndex = "auto";
366-
scrollbarHideObserverRef.current.style.display = "none";
367-
}, []);
368-
369357
const stickerConfig = {
370358
charWidth: 8,
371359
charHeight: 16,
@@ -388,20 +376,13 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
388376

389377
return (
390378
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef} onContextMenu={handleContextMenu}>
391-
{termBg && <div className="absolute inset-0 z-0 pointer-events-none" style={termBg} />}
379+
{termBg && <div key="term-bg" className="absolute inset-0 z-0 pointer-events-none" style={termBg} />}
392380
<TermResyncHandler blockId={blockId} model={model} />
393381
<TermThemeUpdater blockId={blockId} model={model} termRef={model.termRef} />
394382
<TermStickers config={stickerConfig} />
395383
<TermToolbarVDomNode key="vdom-toolbar" blockId={blockId} model={model} />
396384
<TermVDomNode key="vdom" blockId={blockId} model={model} />
397-
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}>
398-
<div className="term-scrollbar-show-observer" onPointerOver={onScrollbarShowObserver} />
399-
<div
400-
ref={scrollbarHideObserverRef}
401-
className="term-scrollbar-hide-observer"
402-
onPointerOver={onScrollbarHideObserver}
403-
/>
404-
</div>
385+
<div key="connect-elem" className="term-connectelem" ref={connectElemRef} />
405386
<NullErrorBoundary debugName="TermLinkTooltip">
406387
<TermLinkTooltip termWrap={termWrapInst} />
407388
</NullErrorBoundary>

frontend/app/view/term/termwrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class TermWrap {
129129
this.lastCommandAtom = jotai.atom(null) as jotai.PrimitiveAtom<string | null>;
130130
this.terminal = new Terminal(options);
131131
this.fitAddon = new FitAddon();
132-
this.fitAddon.noScrollbar = PLATFORM === PlatformMacOS;
132+
this.fitAddon.scrollbarWidth = 6; // this needs to match scrollbar width in term.scss
133133
this.serializeAddon = new SerializeAddon();
134134
this.searchAddon = new SearchAddon();
135135
this.terminal.loadAddon(this.searchAddon);

0 commit comments

Comments
 (0)