Skip to content

Commit 2e4f477

Browse files
author
OpenShift Bot
authored
Merge pull request #1176 from jwforres/retry-terminal-size
Merged by openshift-bot
2 parents 361d629 + 9c4332f commit 2e4f477

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

app/scripts/controllers/pod.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,33 @@ angular.module('openshiftConsole')
113113

114114
var characterBoundingBox = calculateCharacterBoundingBox();
115115
var win = $( window );
116-
var calculateTerminalSize = function(){
117-
if (!characterBoundingBox.height || !characterBoundingBox.width) {
116+
var calculateTerminalSize = function(retries){
117+
if (!retries) {
118+
retries = 0;
119+
}
120+
121+
if (!characterBoundingBox.height || !characterBoundingBox.width || !$scope.selectedTab.terminal || retries > 10) {
118122
return;
119123
}
120124
$scope.$apply(function() {
121125
var terminalWrapper = $('.container-terminal-wrapper').get(0);
122-
// `terminalWrapper` won't exist until the user selects the terminal tab.
126+
// `terminalWrapper` may not exist yet, we should retry
123127
if (!terminalWrapper) {
128+
$timeout(function(){
129+
calculateTerminalSize(retries + 1);
130+
}, 50);
124131
return;
125132
}
126133

127134
var r = terminalWrapper.getBoundingClientRect();
135+
// Check if the content under the terminal tab isnt fully appended to the DOM yet, in that case
136+
// there is no bounding box yet so we can't calculate the right width / height. Retry.
137+
if (r.left === 0 && r.top === 0 && r.width === 0 && r.height === 0) {
138+
$timeout(function(){
139+
calculateTerminalSize(retries + 1);
140+
}, 50);
141+
return;
142+
}
128143
var windowWidth = win.width();
129144
var windowHeight = win.height();
130145
var termWidth = windowWidth - r.left - 40; // we want 40px right padding, includes 20px padding within the container terminal

dist/scripts/scripts.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -4406,13 +4406,18 @@ width:a.width() / 10,
44064406
height:a.height()
44074407
};
44084408
return a.remove(), b;
4409-
}, r = q(), s = $(window), t = function() {
4410-
r.height && r.width && a.$apply(function() {
4411-
var b = $(".container-terminal-wrapper").get(0);
4412-
if (b) {
4413-
var c = b.getBoundingClientRect(), d = s.width(), e = s.height(), f = d - c.left - 40, g = e - c.top - 50;
4414-
a.terminalCols = Math.max(_.floor(f / r.width), 80), a.terminalRows = Math.max(_.floor(g / r.height), 24);
4415-
}
4409+
}, r = q(), s = $(window), t = function(b) {
4410+
b || (b = 0), r.height && r.width && a.selectedTab.terminal && !(b > 10) && a.$apply(function() {
4411+
var c = $(".container-terminal-wrapper").get(0);
4412+
if (!c) return void d(function() {
4413+
t(b + 1);
4414+
}, 50);
4415+
var e = c.getBoundingClientRect();
4416+
if (0 === e.left && 0 === e.top && 0 === e.width && 0 === e.height) return void d(function() {
4417+
t(b + 1);
4418+
}, 50);
4419+
var f = s.width(), g = s.height(), h = f - e.left - 40, i = g - e.top - 50;
4420+
a.terminalCols = Math.max(_.floor(h / r.width), 80), a.terminalRows = Math.max(_.floor(i / r.height), 24);
44164421
});
44174422
};
44184423
a.$watch("selectedTab.terminal", function(a) {

0 commit comments

Comments
 (0)