зеркало из https://github.com/mozilla/ace.git
Show horizontal scrollbar only when needed
This commit is contained in:
Родитель
4d8e4b29ab
Коммит
14ebde8b24
|
@ -69,7 +69,7 @@ var ScrollBar = function(parent) {
|
|||
};
|
||||
|
||||
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) {
|
||||
|
|
|
@ -88,6 +88,10 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.$cursorLayer = new CursorLayer(this.content);
|
||||
this.$cursorPadding = 8;
|
||||
|
||||
// Indicates whether the horizontal scrollbar is visible
|
||||
this.$horizScroll = true;
|
||||
this.$horizScrollAlwaysVisible = true;
|
||||
|
||||
this.scrollBar = new ScrollBar(container);
|
||||
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
|
||||
|
||||
|
@ -199,7 +203,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.$size.height = height;
|
||||
|
||||
this.scroller.style.height = height + "px";
|
||||
this.scrollBar.setHeight(height);
|
||||
this.scrollBar.setHeight(this.scroller.clientHeight);
|
||||
|
||||
if (this.session) {
|
||||
this.scrollToY(this.getScrollTop());
|
||||
|
@ -361,6 +365,14 @@ var VirtualRenderer = function(container, theme) {
|
|||
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.scrollToY(e.data);
|
||||
};
|
||||
|
@ -446,6 +458,12 @@ var VirtualRenderer = function(container, theme) {
|
|||
var longestLine = this.$getLongestLine();
|
||||
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 firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
|
||||
var lastRow = firstRow + lineCount;
|
||||
|
@ -480,6 +498,11 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.content.style.marginTop = (-offset) + "px";
|
||||
this.content.style.width = longestLine + "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() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче