Skip to content

Commit b7a5dea

Browse files
authored
Fix Term Widget not registering pointer events (#1614)
This is a bit janky. The problem is that we were placing the `xterm-viewport` div, which contains the scroll observer for the xterm contents, at a higher z-index than the xterm contents, meaning that the contents couldn't register any pointer events. If we don't put a z-index, though, the scroll bar can't accept pointer events. To get around this, I've added two observer divs, which control whether the contents or the viewport have pointer event priority. The first div, the `term-scrollbar-show-observer`, sits above where the scrollbar will be rendered. When the user hovers over it, it will cause the viewport div to move to a z-index above the contents. It will also enable a second div, the `term-scrollbar-hide-observer`, which sits above the viewport and the term contents, but not blocking the scrollbar. When the user hovers over this div (indicating their mouse has left the scrollbar), the viewport div is moved back to its original z-index and the hide observer is set to `display: none`. This gives pointer event priority back to the contents div. This resolves an issue where the user could not click links in the terminal output. Resolves #1357
1 parent b778417 commit b7a5dea

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

frontend/app/view/term/term.scss

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@
3636
overflow: hidden;
3737
}
3838

39-
.term-cmd-toolbar {
40-
display: flex;
41-
flex-direction: row;
42-
height: 24px;
43-
border-bottom: 1px solid var(--border-color);
44-
overflow: hidden;
45-
align-items: center;
46-
47-
.term-cmd-toolbar-text {
48-
font: var(--fixed-font);
49-
flex-grow: 1;
50-
overflow: hidden;
51-
text-overflow: ellipsis;
52-
white-space: nowrap;
53-
padding: 0 5px;
54-
}
55-
}
39+
.term-cmd-toolbar {
40+
display: flex;
41+
flex-direction: row;
42+
height: 24px;
43+
border-bottom: 1px solid var(--border-color);
44+
overflow: hidden;
45+
align-items: center;
46+
47+
.term-cmd-toolbar-text {
48+
font: var(--fixed-font);
49+
flex-grow: 1;
50+
overflow: hidden;
51+
text-overflow: ellipsis;
52+
white-space: nowrap;
53+
padding: 0 5px;
54+
}
55+
}
5656

5757
.term-connectelem {
5858
flex-grow: 1;
@@ -126,10 +126,27 @@
126126
}
127127
}
128128

129+
.term-scrollbar-show-observer {
130+
z-index: calc(var(--zindex-xterm-viewport-overlay) - 1);
131+
position: absolute;
132+
top: 0;
133+
right: 0;
134+
height: 100%;
135+
width: 12px;
136+
}
137+
138+
.term-scrollbar-hide-observer {
139+
z-index: calc(var(--zindex-xterm-viewport-overlay) + 1);
140+
display: none;
141+
position: absolute;
142+
top: 0;
143+
left: 0;
144+
height: 100%;
145+
width: calc(100% - 12px);
146+
}
147+
129148
.terminal {
130149
.xterm-viewport {
131-
z-index: var(--zindex-xterm-viewport-overlay);
132-
133150
&::-webkit-scrollbar {
134151
width: 6px;
135152
height: 6px;

frontend/app/view/term/term.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,19 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
848848
termModeRef.current = termMode;
849849
}, [termMode]);
850850

851-
let stickerConfig = {
851+
const scrollbarHideObserverRef = React.useRef<HTMLDivElement>(null);
852+
const onScrollbarShowObserver = React.useCallback(() => {
853+
const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement;
854+
termViewport.style.zIndex = "var(--zindex-xterm-viewport-overlay)";
855+
scrollbarHideObserverRef.current.style.display = "block";
856+
}, []);
857+
const onScrollbarHideObserver = React.useCallback(() => {
858+
const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement;
859+
termViewport.style.zIndex = "auto";
860+
scrollbarHideObserverRef.current.style.display = "none";
861+
}, []);
862+
863+
const stickerConfig = {
852864
charWidth: 8,
853865
charHeight: 16,
854866
rows: model.termRef.current?.terminal.rows ?? 24,
@@ -862,7 +874,14 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
862874
<TermStickers config={stickerConfig} />
863875
<TermToolbarVDomNode key="vdom-toolbar" blockId={blockId} model={model} />
864876
<TermVDomNode key="vdom" blockId={blockId} model={model} />
865-
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}></div>
877+
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}>
878+
<div className="term-scrollbar-show-observer" onPointerOver={onScrollbarShowObserver} />
879+
<div
880+
ref={scrollbarHideObserverRef}
881+
className="term-scrollbar-hide-observer"
882+
onPointerOver={onScrollbarHideObserver}
883+
/>
884+
</div>
866885
</div>
867886
);
868887
};

0 commit comments

Comments
 (0)