Show horizontal scrollbar only when needed
This commit is contained in:
parent
4d8e4b29ab
commit
14ebde8b24
2 changed files with 25 additions and 2 deletions
|
|
@ -69,7 +69,7 @@ var ScrollBar = function(parent) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setHeight = function(height) {
|
this.setHeight = function(height) {
|
||||||
this.element.style.height = Math.max(0, height - this.width) + "px";
|
this.element.style.height = height + "px";
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setInnerHeight = function(height) {
|
this.setInnerHeight = function(height) {
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,10 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.$cursorLayer = new CursorLayer(this.content);
|
this.$cursorLayer = new CursorLayer(this.content);
|
||||||
this.$cursorPadding = 8;
|
this.$cursorPadding = 8;
|
||||||
|
|
||||||
|
// Indicates whether the horizontal scrollbar is visible
|
||||||
|
this.$horizScroll = true;
|
||||||
|
this.$horizScrollAlwaysVisible = true;
|
||||||
|
|
||||||
this.scrollBar = new ScrollBar(container);
|
this.scrollBar = new ScrollBar(container);
|
||||||
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
|
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
|
||||||
|
|
||||||
|
|
@ -199,7 +203,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.$size.height = height;
|
this.$size.height = height;
|
||||||
|
|
||||||
this.scroller.style.height = height + "px";
|
this.scroller.style.height = height + "px";
|
||||||
this.scrollBar.setHeight(height);
|
this.scrollBar.setHeight(this.scroller.clientHeight);
|
||||||
|
|
||||||
if (this.session) {
|
if (this.session) {
|
||||||
this.scrollToY(this.getScrollTop());
|
this.scrollToY(this.getScrollTop());
|
||||||
|
|
@ -361,6 +365,14 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.$updatePrintMargin();
|
this.$updatePrintMargin();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
|
||||||
|
if (this.$horizScrollAlwaysVisible != alwaysVisible) {
|
||||||
|
this.$horizScrollAlwaysVisible = alwaysVisible;
|
||||||
|
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
|
||||||
|
this.$loop.schedule(this.CHANGE_SCROLL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.onScroll = function(e) {
|
this.onScroll = function(e) {
|
||||||
this.scrollToY(e.data);
|
this.scrollToY(e.data);
|
||||||
};
|
};
|
||||||
|
|
@ -446,6 +458,12 @@ var VirtualRenderer = function(container, theme) {
|
||||||
var longestLine = this.$getLongestLine();
|
var longestLine = this.$getLongestLine();
|
||||||
var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine);
|
var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine);
|
||||||
|
|
||||||
|
var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
|
||||||
|
var horizScrollChanged = this.$horizScroll !== horizScroll;
|
||||||
|
this.$horizScroll = horizScroll;
|
||||||
|
if (horizScrollChanged)
|
||||||
|
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
|
||||||
|
|
||||||
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
|
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
|
||||||
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
|
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
|
||||||
var lastRow = firstRow + lineCount;
|
var lastRow = firstRow + lineCount;
|
||||||
|
|
@ -480,6 +498,11 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.content.style.marginTop = (-offset) + "px";
|
this.content.style.marginTop = (-offset) + "px";
|
||||||
this.content.style.width = longestLine + "px";
|
this.content.style.width = longestLine + "px";
|
||||||
this.content.style.height = minHeight + "px";
|
this.content.style.height = minHeight + "px";
|
||||||
|
|
||||||
|
// Horizontal scrollbar visibility may have changed, which changes
|
||||||
|
// the client height of the scroller
|
||||||
|
if (horizScrollChanged)
|
||||||
|
this.onResize(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$updateLines = function() {
|
this.$updateLines = function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue