@inst/vscode-bin-darwin
Version:
BINARY ONLY - VSCode binary deployment for macOS
91 lines (89 loc) • 3.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Viewport = (function () {
function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
var _this = this;
this.terminal = terminal;
this.viewportElement = viewportElement;
this.scrollArea = scrollArea;
this.charMeasure = charMeasure;
this.currentRowHeight = 0;
this.lastRecordedBufferLength = 0;
this.lastRecordedViewportHeight = 0;
this.lastRecordedBufferHeight = 0;
this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
setTimeout(function () { return _this.syncScrollArea(); }, 0);
}
Viewport.prototype.onThemeChanged = function (colors) {
this.viewportElement.style.backgroundColor = colors.background;
};
Viewport.prototype.refresh = function () {
if (this.charMeasure.height > 0) {
this.currentRowHeight = this.terminal.renderer.dimensions.scaledLineHeight / window.devicePixelRatio;
if (this.lastRecordedViewportHeight !== this.terminal.renderer.dimensions.canvasHeight) {
this.lastRecordedViewportHeight = this.terminal.renderer.dimensions.canvasHeight;
this.viewportElement.style.height = this.lastRecordedViewportHeight + 'px';
}
var newBufferHeight = Math.round(this.currentRowHeight * this.lastRecordedBufferLength);
if (this.lastRecordedBufferHeight !== newBufferHeight) {
this.lastRecordedBufferHeight = newBufferHeight;
this.scrollArea.style.height = this.lastRecordedBufferHeight + 'px';
}
}
};
Viewport.prototype.syncScrollArea = function () {
if (this.lastRecordedBufferLength !== this.terminal.buffer.lines.length) {
this.lastRecordedBufferLength = this.terminal.buffer.lines.length;
this.refresh();
}
else if (this.lastRecordedViewportHeight !== this.terminal.renderer.dimensions.canvasHeight) {
this.refresh();
}
else {
if (this.terminal.renderer.dimensions.scaledLineHeight / window.devicePixelRatio !== this.currentRowHeight) {
this.refresh();
}
}
var scrollTop = this.terminal.buffer.ydisp * this.currentRowHeight;
if (this.viewportElement.scrollTop !== scrollTop) {
this.viewportElement.scrollTop = scrollTop;
}
};
Viewport.prototype.onScroll = function (ev) {
var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
var diff = newRow - this.terminal.buffer.ydisp;
this.terminal.scrollDisp(diff, true);
};
Viewport.prototype.onWheel = function (ev) {
if (ev.deltaY === 0) {
return;
}
var multiplier = 1;
if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
multiplier = this.currentRowHeight;
}
else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
multiplier = this.currentRowHeight * this.terminal.rows;
}
this.viewportElement.scrollTop += ev.deltaY * multiplier;
ev.preventDefault();
};
;
Viewport.prototype.onTouchStart = function (ev) {
this.lastTouchY = ev.touches[0].pageY;
};
;
Viewport.prototype.onTouchMove = function (ev) {
var deltaY = this.lastTouchY - ev.touches[0].pageY;
this.lastTouchY = ev.touches[0].pageY;
if (deltaY === 0) {
return;
}
this.viewportElement.scrollTop += deltaY;
ev.preventDefault();
};
;
return Viewport;
}());
exports.Viewport = Viewport;
//# sourceMappingURL=Viewport.js.map