find and undo must center selection into view

This commit is contained in:
nightwing 2012-04-26 10:12:19 +04:00
commit 621c7c3dc8
2 changed files with 18 additions and 12 deletions

View file

@ -982,7 +982,7 @@ var Editor = function(renderer, session) {
this.renderer.animateScrolling(function() {
renderer.scrollBy(0, rows * config.lineHeight);
if (select != null)
renderer.scrollCursorIntoView();
renderer.scrollCursorIntoView(null, 0.5);
}, this);
};
@ -1262,17 +1262,23 @@ var Editor = function(renderer, session) {
this.$blockScrolling -= 1;
this.renderer.animateScrolling(function() {
this.renderer.scrollSelectionIntoView(range.start, range.end);
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
}, this);
}
};
this.undo = function() {
this.$blockScrolling++;
this.session.getUndoManager().undo();
this.$blockScrolling--;
renderer.scrollCursorIntoView(null, 0.5);
};
this.redo = function() {
this.$blockScrolling++;
this.session.getUndoManager().redo();
this.$blockScrolling--;
renderer.scrollCursorIntoView(null, 0.5);
};
this.destroy = function() {

View file

@ -678,13 +678,13 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.showCursor();
};
this.scrollSelectionIntoView = function(anchor, lead) {
this.scrollSelectionIntoView = function(anchor, lead, offset) {
// first scroll anchor into view then scroll lead into view
this.scrollCursorIntoView(anchor);
this.scrollCursorIntoView(lead);
this.scrollCursorIntoView(anchor, offset);
this.scrollCursorIntoView(lead, offset);
};
this.scrollCursorIntoView = function(cursor) {
this.scrollCursorIntoView = function(cursor, offset) {
// the editor is not visible
if (this.$size.scrollerHeight === 0)
return;
@ -695,10 +695,12 @@ var VirtualRenderer = function(container, theme) {
var top = pos.top;
if (this.scrollTop > top) {
if (offset)
top -= offset * this.$size.scrollerHeight;
this.session.setScrollTop(top);
}
if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
} else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
if (offset)
top += offset * this.$size.scrollerHeight;
this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
}
@ -708,9 +710,7 @@ var VirtualRenderer = function(container, theme) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth)
left = 0;
this.session.setScrollLeft(left);
}
if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
} else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
}
};