fix: find doesn't change horizontal scroll

fixes #638
This commit is contained in:
Fabian Jakobs 2012-04-06 14:10:40 +02:00
commit 4084931f19
2 changed files with 30 additions and 20 deletions

View file

@ -62,7 +62,7 @@ var Editor = function(renderer, session) {
var container = renderer.getContainerElement(); var container = renderer.getContainerElement();
this.container = container; this.container = container;
this.renderer = renderer; this.renderer = renderer;
this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
this.keyBinding = new KeyBinding(this); this.keyBinding = new KeyBinding(this);
@ -311,12 +311,16 @@ var Editor = function(renderer, session) {
this.onScrollLeftChange = function() { this.onScrollLeftChange = function() {
this.renderer.scrollToX(this.session.getScrollLeft()); this.renderer.scrollToX(this.session.getScrollLeft());
}; };
this.onCursorChange = function() { this.onCursorChange = function() {
this.renderer.updateCursor(); this.renderer.updateCursor();
if (!this.$blockScrolling) { if (!this.$blockScrolling) {
this.renderer.scrollCursorIntoView(); var selection = this.getSelection();
if (selection.isEmpty())
this.renderer.scrollCursorIntoView(selection.getCursor());
else
this.renderer.scrollSelectionIntoView(selection.getSelectionLead(), selection.getSelectionAnchor());
} }
// move text input over the cursor // move text input over the cursor
@ -652,7 +656,7 @@ var Editor = function(renderer, session) {
this.$showFoldWidgets = show; this.$showFoldWidgets = show;
this.renderer.updateFull(); this.renderer.updateFull();
}; };
this.getShowFoldWidgets = function() { this.getShowFoldWidgets = function() {
return this.renderer.$gutterLayer.getShowFoldWidgets(); return this.renderer.$gutterLayer.getShowFoldWidgets();
}; };
@ -869,7 +873,7 @@ var Editor = function(renderer, session) {
range.start.row += linesMoved; range.start.row += linesMoved;
range.end.row += linesMoved; range.end.row += linesMoved;
selection.setSelectionRange(range, reverse); selection.setSelectionRange(range, reverse);
} }
else { else {
selection.setSelectionAnchor(rows.last+linesMoved+1, 0); selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
selection.$moveSelection(function() { selection.$moveSelection(function() {
@ -1033,13 +1037,13 @@ var Editor = function(renderer, session) {
cursor.column -= 2; cursor.column -= 2;
pos = this.session.findMatchingBracket(cursor); pos = this.session.findMatchingBracket(cursor);
} }
if (pos) { if (pos) {
this.clearSelection(); this.clearSelection();
this.moveCursorTo(pos.row, pos.column); this.moveCursorTo(pos.row, pos.column);
} }
}; };
this.gotoLine = function(lineNumber, column) { this.gotoLine = function(lineNumber, column) {
this.selection.clearSelection(); this.selection.clearSelection();
this.session.unfold({row: lineNumber - 1, column: column || 0}); this.session.unfold({row: lineNumber - 1, column: column || 0});

View file

@ -60,13 +60,13 @@ dom.importCssString(editorCss, "ace_editor");
var VirtualRenderer = function(container, theme) { var VirtualRenderer = function(container, theme) {
var _self = this; var _self = this;
this.container = container; this.container = container;
// TODO: this breaks rendering in Cloud9 with multiple ace instances // TODO: this breaks rendering in Cloud9 with multiple ace instances
// // Imports CSS once per DOM document ('ace_editor' serves as an identifier). // // Imports CSS once per DOM document ('ace_editor' serves as an identifier).
// dom.importCssString(editorCss, "ace_editor", container.ownerDocument); // dom.importCssString(editorCss, "ace_editor", container.ownerDocument);
dom.addCssClass(container, "ace_editor"); dom.addCssClass(container, "ace_editor");
this.setTheme(theme); this.setTheme(theme);
@ -84,8 +84,8 @@ var VirtualRenderer = function(container, theme) {
this.scroller.appendChild(this.content); this.scroller.appendChild(this.content);
this.$gutterLayer = new GutterLayer(this.$gutter); this.$gutterLayer = new GutterLayer(this.$gutter);
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true)); this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
this.$markerBack = new MarkerLayer(this.content); this.$markerBack = new MarkerLayer(this.content);
var textLayer = this.$textLayer = new TextLayer(this.content); var textLayer = this.$textLayer = new TextLayer(this.content);
@ -110,7 +110,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollTop = 0; this.scrollTop = 0;
this.scrollLeft = 0; this.scrollLeft = 0;
event.addListener(this.scroller, "scroll", function() { event.addListener(this.scroller, "scroll", function() {
var scrollLeft = _self.scroller.scrollLeft; var scrollLeft = _self.scroller.scrollLeft;
_self.scrollLeft = scrollLeft; _self.scrollLeft = scrollLeft;
@ -352,7 +352,7 @@ var VirtualRenderer = function(container, theme) {
// this persists in IE9 // this persists in IE9
if (useragent.isIE) if (useragent.isIE)
return; return;
if (this.layerConfig.lastRow === 0) if (this.layerConfig.lastRow === 0)
return; return;
@ -428,13 +428,13 @@ var VirtualRenderer = function(container, theme) {
// horizontal scrolling // horizontal scrolling
if (changes & this.CHANGE_H_SCROLL) { if (changes & this.CHANGE_H_SCROLL) {
this.scroller.scrollLeft = this.scrollLeft; this.scroller.scrollLeft = this.scrollLeft;
// read the value after writing it since the value might get clipped // read the value after writing it since the value might get clipped
var scrollLeft = this.scroller.scrollLeft; var scrollLeft = this.scroller.scrollLeft;
this.scrollLeft = scrollLeft; this.scrollLeft = scrollLeft;
this.session.setScrollLeft(scrollLeft); this.session.setScrollLeft(scrollLeft);
} }
// full // full
if (changes & this.CHANGE_FULL) { if (changes & this.CHANGE_FULL) {
this.$textLayer.checkForSizeChanges(); this.$textLayer.checkForSizeChanges();
@ -647,12 +647,18 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.showCursor(); this.$cursorLayer.showCursor();
}; };
this.scrollCursorIntoView = function() { this.scrollSelectionIntoView = function(anchor, lead) {
// first scroll anchor into view then scroll lead into view
this.scrollCursorIntoView(anchor);
this.scrollCursorIntoView(lead);
};
this.scrollCursorIntoView = function(cursor) {
// the editor is not visible // the editor is not visible
if (this.$size.scrollerHeight === 0) if (this.$size.scrollerHeight === 0)
return; return;
var pos = this.$cursorLayer.getPixelPosition(); var pos = this.$cursorLayer.getPixelPosition(cursor);
var left = pos.left; var left = pos.left;
var top = pos.top; var top = pos.top;
@ -808,7 +814,7 @@ var VirtualRenderer = function(container, theme) {
this._loadTheme = function(name, callback) { this._loadTheme = function(name, callback) {
if (!config.get("packaged")) if (!config.get("packaged"))
return callback(); return callback();
var base = name.split("/").pop(); var base = name.split("/").pop();
var filename = config.get("themePath") + "/theme-" + base + config.get("suffix"); var filename = config.get("themePath") + "/theme-" + base + config.get("suffix");
net.loadScript(filename, callback); net.loadScript(filename, callback);
@ -820,14 +826,14 @@ var VirtualRenderer = function(container, theme) {
this.$themeValue = theme; this.$themeValue = theme;
if (!theme || typeof theme == "string") { if (!theme || typeof theme == "string") {
var moduleName = theme || "ace/theme/textmate"; var moduleName = theme || "ace/theme/textmate";
var module; var module;
try { try {
module = require(moduleName); module = require(moduleName);
} catch (e) {}; } catch (e) {};
if (module) if (module)
return afterLoad(module); return afterLoad(module);
_self._loadTheme(moduleName, function() { _self._loadTheme(moduleName, function() {
require([theme], function(module) { require([theme], function(module) {
if (_self.$themeValue !== theme) if (_self.$themeValue !== theme)