Skip to content

Commit

Permalink
fix: don't resize terminal when hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Aug 3, 2020
1 parent c2a3dcb commit 5d993a7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class XTerminalElementImpl extends HTMLElement {
// An element resize detector is used to check when this element is
// resized due to the pane resizing or due to the entire window
// resizing.
this.mainDivResizeObserver = new ResizeObserver((entries, observer) => {
this.mainDivResizeObserver = new ResizeObserver(entries => {
const lastEntry = entries.pop()
this.mainDivContentRect = lastEntry.contentRect
this.refitTerminal()
})
this.mainDivResizeObserver.observe(this.mainDiv)
Expand All @@ -99,11 +101,9 @@ class XTerminalElementImpl extends HTMLElement {
}))
// Add an IntersectionObserver in order to apply new options and
// refit as soon as the terminal is visible.
this.terminalDivIntersectionObserver = new IntersectionObserver((entries, observer) => {
// NOTE: Only the terminal div should be observed therefore there
// should only be one entry.
const visible = entries.some(e => e.intersectionRatio === 1.0)
if (visible) {
this.terminalDivIntersectionObserver = new IntersectionObserver(entries => {
const lastEntry = entries.pop()
if (lastEntry.intersectionRatio === 1.0) {
this.terminalDivInitiallyVisible = true
this.applyPendingTerminalProfileOptions()
// Remove observer once visible
Expand Down Expand Up @@ -678,7 +678,12 @@ class XTerminalElementImpl extends HTMLElement {

refitTerminal () {
// Only refit the terminal when it is completely visible.
if (this.terminalDivInitiallyVisible) {
if (
this.terminalDivInitiallyVisible &&
this.mainDivContentRect &&
this.mainDivContentRect.width > 0 &&
this.mainDivContentRect.height > 0
) {
this.fitAddon.fit()
const geometry = this.fitAddon.proposeDimensions()
if (geometry && this.isPtyProcessRunning()) {
Expand Down

0 comments on commit 5d993a7

Please sign in to comment.