Skip to content

Commit eae60c1

Browse files
committed
fix mobile jumping #914
1 parent 9b00793 commit eae60c1

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

css/jquery.terminal-src.css

+7-3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ body.terminal, body.full-screen-terminal {
101101
body.full-screen-terminal .terminal {
102102
height: 100%;
103103
}
104+
body.full-screen-terminal {
105+
height: 100%;
106+
height: 100dvh;
107+
height: calc(var(--terminal-force-height) * 1px);
108+
}
104109
.terminal > div.terminal-fill {
105110
min-height: 100%;
106111
height: 100%;
@@ -1115,17 +1120,16 @@ terminal .terminal-output > div {
11151120
display: inline-block;
11161121
}
11171122
.cmd-editable {
1118-
position: absolute;
1123+
position: fixed;
11191124
top: 0;
1120-
top: calc(var(--terminal-y, var(--cmd-y, 0)) + var(--terminal-scroll, 0) * 1px);
11211125
right: 0;
11221126
left: 0;
11231127
bottom: 0;
1124-
bottom: calc(var(--terminal-scroll, 0) * -1px);
11251128
z-index: 500;
11261129
color: transparent;
11271130
background: transparent;
11281131
opacity: 0.01;
1132+
outline: 0px solid transparent;
11291133
}
11301134
/* Scrollbar */
11311135
.terminal-scroller::-webkit-scrollbar {

js/jquery.terminal-src.js

+34-5
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,9 @@
23682368
}
23692369
var tmp = command;
23702370
// fix scroll the page where there is no scrollbar
2371-
clip.$node.blur();
2371+
if (!is_mobile) {
2372+
clip.$node.blur();
2373+
}
23722374
history.reset();
23732375

23742376
// for next input event on firefox/android with google keyboard
@@ -2388,7 +2390,9 @@
23882390
}
23892391
self.set('');
23902392
clip.val('');
2391-
clip.$node.focus();
2393+
if (!is_mobile) {
2394+
clip.$node.focus();
2395+
}
23922396
return false;
23932397
},
23942398
'SHIFT+ENTER': function() {
@@ -5284,6 +5288,21 @@
52845288
}
52855289
}
52865290
// -------------------------------------------------------------------------
5291+
// :: handler to trigger when window change size. The most important
5292+
// :: is that it's triggers when virtual keyboard is toggled
5293+
// -------------------------------------------------------------------------
5294+
function on_height_change(callback) {
5295+
var height = window.visualViewport.height;
5296+
callback(height);
5297+
window.visualViewport.addEventListener('resize', function() {
5298+
var newHeight = window.visualViewport.height;
5299+
if (height !== newHeight) {
5300+
height = newHeight;
5301+
callback(height);
5302+
}
5303+
});
5304+
}
5305+
// -------------------------------------------------------------------------
52875306
$.terminal = {
52885307
version: '{{VER}}',
52895308
date: '{{DATE}}',
@@ -10630,9 +10649,9 @@
1063010649
'--terminal-height': self.height(),
1063110650
'--terminal-x': offset.left - self_offset.left,
1063210651
'--terminal-y': offset.top - self_offset.top,
10633-
'--terminal-scroll': self.prop('scrollTop')
10652+
'--terminal-scroll': scroller.prop('scrollTop')
1063410653
});
10635-
if (enabled) {
10654+
if (enabled && !is_mobile) {
1063610655
// Firefox won't reflow the cursor automatically, so
1063710656
// hide it briefly then reshow it
1063810657
cmd_cursor.hide();
@@ -12021,6 +12040,9 @@
1202112040
if (!enabled) {
1202212041
clip.focus();
1202312042
self.focus();
12043+
setTimeout(function() {
12044+
self.scroll_to_bottom();
12045+
}, 100);
1202412046
} else {
1202512047
clip.blur();
1202612048
self.disable();
@@ -12031,6 +12053,13 @@
1203112053
start = null;
1203212054
});
1203312055
})();
12056+
if ('visualViewport' in window) {
12057+
on_height_change(function(height) {
12058+
css(document.documentElement, {
12059+
'--terminal-force-height': height
12060+
});
12061+
});
12062+
}
1203412063
} else {
1203512064
// work weird on mobile
1203612065
$win.on('focus.terminal_' + self.id(), focus_terminal).
@@ -12536,7 +12565,7 @@
1253612565
ret = settings.touchscroll(event, delta, self);
1253712566
}
1253812567
css(self[0], {
12539-
'--terminal-scroll': self.prop('scrollTop')
12568+
'--terminal-scroll': scroller.prop('scrollTop')
1254012569
});
1254112570
if (ret === true) {
1254212571
return;

0 commit comments

Comments
 (0)