Skip to content

Commit 7203ef6

Browse files
committed
fix issue with terminal jumping #486
1 parent 72e1ee1 commit 7203ef6

8 files changed

+63
-56
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
### Bugfix
33
* show terminal content after it's resized when initially not visible (fix jumping of text)
44
* fix pipe when using read + echo in first command and read in next
5+
* fix issue with jumping of terminal on keypress [#486](https://github.com/jcubic/jquery.terminal/issues/486)
56

67
## 2.4.0
78
### Features

js/jquery.terminal-2.4.0.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* emoji regex v7.0.1 by Mathias Bynens
4040
* MIT license
4141
*
42-
* Date: Mon, 15 Apr 2019 17:10:21 +0000
42+
* Date: Tue, 16 Apr 2019 11:32:16 +0000
4343
*/
4444
/* global location, setTimeout, window, global, sprintf, setImmediate,
4545
IntersectionObserver, ResizeObserver, module, require, define,
@@ -1000,7 +1000,7 @@
10001000
var node = this[0];
10011001
var defer = jQuery.Deferred();
10021002
var item_observer = new window.IntersectionObserver(function(entries) {
1003-
defer.resolve(entries[0].isIntersecting);
1003+
defer.resolve(entries[0].isIntersecting && entries[0].ratio === 1);
10041004
item_observer.unobserve(node);
10051005
}, {
10061006
root: container[0]
@@ -3756,7 +3756,7 @@
37563756
// -------------------------------------------------------------------------
37573757
$.terminal = {
37583758
version: 'DEV',
3759-
date: 'Mon, 15 Apr 2019 17:10:21 +0000',
3759+
date: 'Tue, 16 Apr 2019 11:32:16 +0000',
37603760
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
37613761
color_names: [
37623762
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
@@ -6596,10 +6596,7 @@
65966596
if (!visible) {
65976597
// try catch for Node.js unit tests
65986598
try {
6599-
var cursor = self.find('.cursor');
6600-
var offset = cursor.offset();
6601-
var term_offset = self.offset();
6602-
self.scrollTop(offset.top - term_offset.top - 5);
6599+
self.scroll_to(self.find('.cursor'));
66036600
return true;
66046601
} catch (e) {
66056602
return true;
@@ -6619,8 +6616,8 @@
66196616
});
66206617
})();
66216618
// ---------------------------------------------------------------------
6622-
function move_cursor_visible() {
6623-
var cursor = self.find('.cursor');
6619+
function make_cursor_visible() {
6620+
var cursor = self.find('.cursor-line');
66246621
return cursor.is_fully_in_viewport(self).then(scroll_to_view);
66256622
}
66266623
// ---------------------------------------------------------------------
@@ -8462,6 +8459,14 @@
84628459
return self;
84638460
},
84648461
// -------------------------------------------------------------
8462+
// :: ref: https://stackoverflow.com/a/18927969/387194
8463+
// -------------------------------------------------------------
8464+
scroll_to: function(elem) {
8465+
var scroll = self.scrollTop() - self.offset().top + $(elem).offset().top;
8466+
self.scrollTop(scroll);
8467+
return self;
8468+
},
8469+
// -------------------------------------------------------------
84658470
scroll_to_bottom: function() {
84668471
var scrollHeight;
84678472
if (self.prop) {
@@ -8761,7 +8766,7 @@
87618766
tabs: settings.tabs,
87628767
onPositionChange: function() {
87638768
var args = [].slice.call(arguments);
8764-
move_cursor_visible();
8769+
make_cursor_visible();
87658770
fire_event('onPositionChange', args);
87668771
},
87678772
onCommandChange: function(command) {
@@ -8772,12 +8777,7 @@
87728777
self.resizer();
87738778
}
87748779
fire_event('onCommandChange', [command]);
8775-
var visible = move_cursor_visible();
8776-
visible.then(function(visible) {
8777-
if (!visible) {
8778-
self.scroll_to_bottom();
8779-
}
8780-
});
8780+
make_cursor_visible();
87818781
},
87828782
commands: commands
87838783
});

js/jquery.terminal-2.4.0.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/jquery.terminal-src.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@
10001000
var node = this[0];
10011001
var defer = jQuery.Deferred();
10021002
var item_observer = new window.IntersectionObserver(function(entries) {
1003-
defer.resolve(entries[0].isIntersecting);
1003+
defer.resolve(entries[0].isIntersecting && entries[0].ratio === 1);
10041004
item_observer.unobserve(node);
10051005
}, {
10061006
root: container[0]
@@ -6596,10 +6596,7 @@
65966596
if (!visible) {
65976597
// try catch for Node.js unit tests
65986598
try {
6599-
var cursor = self.find('.cursor');
6600-
var offset = cursor.offset();
6601-
var term_offset = self.offset();
6602-
self.scrollTop(offset.top - term_offset.top - 5);
6599+
self.scroll_to(self.find('.cursor'));
66036600
return true;
66046601
} catch (e) {
66056602
return true;
@@ -6619,8 +6616,8 @@
66196616
});
66206617
})();
66216618
// ---------------------------------------------------------------------
6622-
function move_cursor_visible() {
6623-
var cursor = self.find('.cursor');
6619+
function make_cursor_visible() {
6620+
var cursor = self.find('.cursor-line');
66246621
return cursor.is_fully_in_viewport(self).then(scroll_to_view);
66256622
}
66266623
// ---------------------------------------------------------------------
@@ -8462,6 +8459,14 @@
84628459
return self;
84638460
},
84648461
// -------------------------------------------------------------
8462+
// :: ref: https://stackoverflow.com/a/18927969/387194
8463+
// -------------------------------------------------------------
8464+
scroll_to: function(elem) {
8465+
var scroll = self.scrollTop() - self.offset().top + $(elem).offset().top;
8466+
self.scrollTop(scroll);
8467+
return self;
8468+
},
8469+
// -------------------------------------------------------------
84658470
scroll_to_bottom: function() {
84668471
var scrollHeight;
84678472
if (self.prop) {
@@ -8761,7 +8766,7 @@
87618766
tabs: settings.tabs,
87628767
onPositionChange: function() {
87638768
var args = [].slice.call(arguments);
8764-
move_cursor_visible();
8769+
make_cursor_visible();
87658770
fire_event('onPositionChange', args);
87668771
},
87678772
onCommandChange: function(command) {
@@ -8772,12 +8777,7 @@
87728777
self.resizer();
87738778
}
87748779
fire_event('onCommandChange', [command]);
8775-
var visible = move_cursor_visible();
8776-
visible.then(function(visible) {
8777-
if (!visible) {
8778-
self.scroll_to_bottom();
8779-
}
8780-
});
8780+
make_cursor_visible();
87818781
},
87828782
commands: commands
87838783
});

js/jquery.terminal.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* emoji regex v7.0.1 by Mathias Bynens
4040
* MIT license
4141
*
42-
* Date: Mon, 15 Apr 2019 17:10:21 +0000
42+
* Date: Tue, 16 Apr 2019 11:32:16 +0000
4343
*/
4444
/* global location, setTimeout, window, global, sprintf, setImmediate,
4545
IntersectionObserver, ResizeObserver, module, require, define,
@@ -1000,7 +1000,7 @@
10001000
var node = this[0];
10011001
var defer = jQuery.Deferred();
10021002
var item_observer = new window.IntersectionObserver(function(entries) {
1003-
defer.resolve(entries[0].isIntersecting);
1003+
defer.resolve(entries[0].isIntersecting && entries[0].ratio === 1);
10041004
item_observer.unobserve(node);
10051005
}, {
10061006
root: container[0]
@@ -3756,7 +3756,7 @@
37563756
// -------------------------------------------------------------------------
37573757
$.terminal = {
37583758
version: 'DEV',
3759-
date: 'Mon, 15 Apr 2019 17:10:21 +0000',
3759+
date: 'Tue, 16 Apr 2019 11:32:16 +0000',
37603760
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
37613761
color_names: [
37623762
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
@@ -6596,10 +6596,7 @@
65966596
if (!visible) {
65976597
// try catch for Node.js unit tests
65986598
try {
6599-
var cursor = self.find('.cursor');
6600-
var offset = cursor.offset();
6601-
var term_offset = self.offset();
6602-
self.scrollTop(offset.top - term_offset.top - 5);
6599+
self.scroll_to(self.find('.cursor'));
66036600
return true;
66046601
} catch (e) {
66056602
return true;
@@ -6619,8 +6616,8 @@
66196616
});
66206617
})();
66216618
// ---------------------------------------------------------------------
6622-
function move_cursor_visible() {
6623-
var cursor = self.find('.cursor');
6619+
function make_cursor_visible() {
6620+
var cursor = self.find('.cursor-line');
66246621
return cursor.is_fully_in_viewport(self).then(scroll_to_view);
66256622
}
66266623
// ---------------------------------------------------------------------
@@ -8462,6 +8459,14 @@
84628459
return self;
84638460
},
84648461
// -------------------------------------------------------------
8462+
// :: ref: https://stackoverflow.com/a/18927969/387194
8463+
// -------------------------------------------------------------
8464+
scroll_to: function(elem) {
8465+
var scroll = self.scrollTop() - self.offset().top + $(elem).offset().top;
8466+
self.scrollTop(scroll);
8467+
return self;
8468+
},
8469+
// -------------------------------------------------------------
84658470
scroll_to_bottom: function() {
84668471
var scrollHeight;
84678472
if (self.prop) {
@@ -8761,7 +8766,7 @@
87618766
tabs: settings.tabs,
87628767
onPositionChange: function() {
87638768
var args = [].slice.call(arguments);
8764-
move_cursor_visible();
8769+
make_cursor_visible();
87658770
fire_event('onPositionChange', args);
87668771
},
87678772
onCommandChange: function(command) {
@@ -8772,12 +8777,7 @@
87728777
self.resizer();
87738778
}
87748779
fire_event('onCommandChange', [command]);
8775-
var visible = move_cursor_visible();
8776-
visible.then(function(visible) {
8777-
if (!visible) {
8778-
self.scroll_to_bottom();
8779-
}
8780-
});
8780+
make_cursor_visible();
87818781
},
87828782
commands: commands
87838783
});

js/jquery.terminal.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/jquery.terminal.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+11-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)