Skip to content

Commit d02c4dd

Browse files
committed
chore: move resize xterm to util
1 parent 350125b commit d02c4dd

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/components/v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/terminal/Terminal.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CLUSTER_STATUS, SocketConnectionType } from '../../../../../../ClusterN
1010
import { TERMINAL_STATUS } from './constants'
1111
import './terminal.scss'
1212
import { TerminalViewType } from './terminal.type'
13+
import { restrictXtermAccessibilityWidth } from './terminal.utils'
1314

1415
let clusterTimeOut
1516

@@ -43,18 +44,6 @@ export default function TerminalView({
4344

4445
const [myDivRef] = useHeightObserver(resizeSocket)
4546

46-
// To fix the scrollbar issue with Xterm in edit mode, we need to restrict the width and height of the xterm-accessibility div as same as xterm-screen div
47-
// CON: In case of resize, we need to call this function again
48-
const restrictXtermAccessibilityWidth = () => {
49-
const xtermScreen = document.querySelector('.xterm-screen') as HTMLElement
50-
const xtermAccessibility = document.querySelector('.xterm-accessibility') as HTMLElement
51-
52-
if (xtermScreen && xtermAccessibility) {
53-
xtermAccessibility.style.width = xtermScreen.clientWidth + 'px'
54-
xtermAccessibility.style.height = xtermScreen.clientHeight + 'px'
55-
}
56-
}
57-
5847
useEffect(() => {
5948
if (!terminalRef.current) {
6049
elementDidMount('#terminal-id').then(() => {

src/components/v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/terminal/terminal.utils.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,15 @@ export default function terminalStripTypeData(elementData) {
320320
return null
321321
}
322322
}
323+
324+
// To fix the scrollbar issue with Xterm in edit mode, we need to restrict the width and height of the xterm-accessibility div as same as xterm-screen div
325+
// CON: In case of resize, we need to call this function again
326+
export const restrictXtermAccessibilityWidth = () => {
327+
const xtermScreen = document.querySelector('.xterm-screen') as HTMLElement
328+
const xtermAccessibility = document.querySelector('.xterm-accessibility') as HTMLElement
329+
330+
if (xtermScreen && xtermAccessibility) {
331+
xtermAccessibility.style.width = xtermScreen.clientWidth + 'px'
332+
xtermAccessibility.style.height = xtermScreen.clientHeight + 'px'
333+
}
334+
}

0 commit comments

Comments
 (0)