treat horizontal scrolling just like vertical scrolling

This commit is contained in:
Fabian Jakobs 2011-07-27 18:39:14 +02:00
commit 421e19ed78
2 changed files with 17 additions and 8 deletions

View file

@ -120,8 +120,7 @@ var Window = exports.Window = function(theme) {
var position = this.buffer.selection.getCursor();
var pos = this.buffer.documentToScreenPosition(position);
var cursorLeft = Math.round(
this.padding
+ pos.column * this.characterSize.width
this.padding + pos.column * this.characterSize.width
);
var cursorTop = (pos.row - (onScreen ? this.layerConfig.firstRowScreen : 0))
* this.characterSize.height;

View file

@ -91,10 +91,16 @@ var WindowView = function(windowModel, container) {
this.$cursorLayer = new CursorLayer(windowModel, this.content);
this.$horizScroll = true;
this.scrollTop = 0;
this.scrollLeft = 0;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
var _self = this;
event.addListener(this.scroller, "scroll", function() {
_self.scrollToX(_self.scroller.scrollLeft);
});
this.scrollTop = 0;
event.addListener(this.$gutter, "click", this.$onGutterClick.bind(this));
event.addListener(this.$gutter, "dblclick", this.$onGutterClick.bind(this));
@ -548,7 +554,7 @@ var WindowView = function(windowModel, container) {
var pos = this.model.getCursorPixelPosition();
var left = pos.left + this.model.padding;
var left = pos.left;
var top = pos.top;
if (this.scrollTop > top) {
@ -559,7 +565,7 @@ var WindowView = function(windowModel, container) {
this.scrollToY(top + this.lineHeight - this.model.size.scrollerHeight);
}
var scrollLeft = this.scroller.scrollLeft;
var scrollLeft = this.scrollLeft;
if (scrollLeft > left) {
this.scrollToX(left);
@ -578,7 +584,7 @@ var WindowView = function(windowModel, container) {
};
this.getScrollLeft = function() {
return this.scroller.scrollLeft;
return this.scrollLeft;
};
this.getScrollTopRow = function() {
@ -620,18 +626,22 @@ var WindowView = function(windowModel, container) {
if (scrollLeft <= this.model.padding)
scrollLeft = 0;
if (this.scrollLeft === scrollLeft)
return;
this.scrollLeft = scrollLeft;
this.scroller.scrollLeft = scrollLeft;
};
this.scrollBy = function(deltaX, deltaY) {
deltaY && this.scrollToY(this.scrollTop + deltaY);
deltaX && this.scrollToX(this.scroller.scrollLeft + deltaX);
deltaX && this.scrollToX(this.scrollLeft + deltaX);
};
this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.model.padding - dom.getPageScrollLeft())
var col = Math.round((pageX + this.scrollLeft - canvasPos.left - this.model.padding - dom.getPageScrollLeft())
/ this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
/ this.lineHeight);