This commit is contained in:
Fabian Jakobs 2011-12-20 14:31:59 +01:00
commit ee123ab4a4
4 changed files with 146 additions and 66 deletions

File diff suppressed because one or more lines are too long

View file

@ -2500,12 +2500,12 @@ var Editor = function(renderer, session) {
this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
this.session.removeEventListener("changeScrollTop", this.$onScrollTopChange);
this.session.removeEventListener("changeLeftTop", this.$onScrollLeftChange);
var selection = this.session.getSelection();
selection.removeEventListener("changeCursor", this.$onCursorChange);
selection.removeEventListener("changeSelection", this.$onSelectionChange);
this.session.setScrollTopRow(this.renderer.getScrollTopRow());
}
this.session = session;
@ -2547,6 +2547,12 @@ var Editor = function(renderer, session) {
this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.$onScrollTopChange = this.onScrollTopChange.bind(this);
this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
this.selection = session.getSelection();
this.selection.addEventListener("changeCursor", this.$onCursorChange);
@ -2556,13 +2562,14 @@ var Editor = function(renderer, session) {
this.onChangeMode();
this.onCursorChange();
this.onScrollTopChange();
this.onScrollLeftChange();
this.onSelectionChange();
this.onChangeFrontMarker();
this.onChangeBackMarker();
this.onChangeBreakpoint();
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.scrollToRow(session.getScrollTopRow());
this.renderer.updateFull();
this._emit("changeSession", {
@ -2680,6 +2687,14 @@ var Editor = function(renderer, session) {
this.renderer.updateLines(rows.first, rows.last);
};
this.onScrollTopChange = function() {
this.renderer.scrollToY(this.session.getScrollTop());
};
this.onScrollLeftChange = function() {
this.renderer.scrollToX(this.session.getScrollLeft());
};
this.onCursorChange = function() {
this.renderer.updateCursor();
@ -5995,18 +6010,34 @@ var EditSession = function(text, mode) {
this.getMode = function() {
return this.$mode;
};
this.$scrollTop = 0;
this.setScrollTopRow = function(scrollTopRow) {
if (this.$scrollTop === scrollTopRow) return;
this.setScrollTop = function(scrollTop) {
scrollTop = Math.round(Math.max(0, scrollTop));
if (this.$scrollTop === scrollTop)
return;
this.$scrollTop = scrollTopRow;
this._emit("changeScrollTop");
this.$scrollTop = scrollTop;
this._emit("changeScrollTop", scrollTop);
};
this.getScrollTopRow = function() {
this.getScrollTop = function() {
return this.$scrollTop;
};
this.$scrollLeft = 0;
this.setScrollLeft = function(scrollLeft) {
scrollLeft = Math.round(Math.max(0, scrollLeft));
if (this.$scrollLeft === scrollLeft)
return;
this.$scrollLeft = scrollLeft;
this._emit("changeScrollLeft", scrollLeft);
};
this.getScrollLeft = function() {
return this.$scrollLeft;
};
this.getWidth = function() {
this.$computeWidth();
@ -11570,11 +11601,12 @@ exports.UndoManager = UndoManager;
*
* ***** END LICENSE BLOCK ***** */
ace.define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/useragent', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/lib/event_emitter', 'text!ace/css/editor.css'], function(require, exports, module) {
ace.define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/event', 'ace/lib/useragent', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/lib/event_emitter', 'text!ace/css/editor.css'], function(require, exports, module) {
"use strict";
var oop = require("./lib/oop");
var dom = require("./lib/dom");
var event = require("./lib/event");
var useragent = require("./lib/useragent");
var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker;
@ -11588,6 +11620,8 @@ var editorCss = require("text!./css/editor.css");
dom.importCssString(editorCss, "ace_editor");
var VirtualRenderer = function(container, theme) {
var _self = this;
this.container = container;
// TODO: this breaks rendering in Cloud9 with multiple ace instances
@ -11631,16 +11665,22 @@ var VirtualRenderer = function(container, theme) {
this.$horizScrollAlwaysVisible = true;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
this.scrollBar.addEventListener("scroll", function(e) {
_self.session.setScrollTop(e.data);
});
this.scrollTop = 0;
this.scrollLeft = 0;
event.addListener(this.scroller, "scroll", function() {
_self.session.setScrollLeft(_self.scroller.scrollLeft);
});
this.cursorPos = {
row : 0,
column : 0
};
var _self = this;
this.$textLayer.addEventListener("changeCharaterSize", function() {
_self.characterWidth = textLayer.getCharacterWidth();
_self.lineHeight = textLayer.getLineHeight();
@ -11925,10 +11965,6 @@ var VirtualRenderer = function(container, theme) {
}
};
this.onScroll = function(e) {
this.scrollToY(e.data);
};
this.$updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.layerConfig.maxHeight);
this.scrollBar.setScrollTop(this.scrollTop);
@ -12020,7 +12056,7 @@ var VirtualRenderer = function(container, theme) {
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
var maxHeight = this.session.getScreenLength() * this.lineHeight;
this.scrollTop = Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight));
this.session.setScrollTop(Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight)));
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
@ -12175,7 +12211,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollToY(top + this.lineHeight - this.$size.scrollerHeight);
}
var scrollLeft = this.scroller.scrollLeft;
var scrollLeft = this.scrollLeft;
if (scrollLeft > left) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth)
@ -12192,11 +12228,11 @@ var VirtualRenderer = function(container, theme) {
};
this.getScrollTop = function() {
return this.scrollTop;
return this.session.getScrollTop();
};
this.getScrollLeft = function() {
return this.scroller.scrollLeft;
return this.session.getScrollLop();
};
this.getScrollTopRow = function() {
@ -12227,7 +12263,6 @@ var VirtualRenderer = function(container, theme) {
this.scrollToY = function(scrollTop) {
// after calling scrollBar.setScrollTop
// scrollbar sends us event with same scrollTop. ignore it
scrollTop = Math.max(0, scrollTop);
if (this.scrollTop !== scrollTop) {
this.$loop.schedule(this.CHANGE_SCROLL);
this.scrollTop = scrollTop;
@ -12240,18 +12275,19 @@ var VirtualRenderer = function(container, theme) {
scrollLeft = 0;
this.scroller.scrollLeft = scrollLeft;
this._emit("scrollX", this.scroller.scrollLeft);
scrollLeft = this.scroller.scrollLeft;
this._emit("scrollX", scrollLeft);
};
this.scrollBy = function(deltaX, deltaY) {
deltaY && this.scrollToY(this.scrollTop + deltaY);
deltaX && this.scrollToX(this.scroller.scrollLeft + deltaX);
deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
};
this.isScrollableBy = function(deltaX, deltaY) {
if (deltaY < 0 && this.scrollTop > 0)
if (deltaY < 0 && this.session.getScrollTop() > 0)
return true;
if (deltaY > 0 && this.scrollTop + this.$size.scrollerHeight < this.layerConfig.maxHeight)
if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight < this.layerConfig.maxHeight)
return true;
// todo: handle horizontal scrolling
};
@ -12259,10 +12295,14 @@ var VirtualRenderer = function(container, theme) {
this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft())
/ this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
/ this.lineHeight);
var col = Math.round(
(pageX + this.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft())
/ this.characterWidth
);
var row = Math.floor(
(pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
/ this.lineHeight
);
return this.session.screenToDocumentPosition(row, Math.max(col, 0));
};
@ -12275,8 +12315,8 @@ var VirtualRenderer = function(container, theme) {
var y = pos.row * this.lineHeight;
return {
pageX: canvasPos.left + x - this.getScrollLeft(),
pageY: canvasPos.top + y - this.getScrollTop()
pageX: canvasPos.left + x - this.scrollLeft,
pageY: canvasPos.top + y - this.scrollTop
};
};

View file

@ -2500,12 +2500,12 @@ var Editor = function(renderer, session) {
this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
this.session.removeEventListener("changeScrollTop", this.$onScrollTopChange);
this.session.removeEventListener("changeLeftTop", this.$onScrollLeftChange);
var selection = this.session.getSelection();
selection.removeEventListener("changeCursor", this.$onCursorChange);
selection.removeEventListener("changeSelection", this.$onSelectionChange);
this.session.setScrollTopRow(this.renderer.getScrollTopRow());
}
this.session = session;
@ -2547,6 +2547,12 @@ var Editor = function(renderer, session) {
this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.$onScrollTopChange = this.onScrollTopChange.bind(this);
this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
this.selection = session.getSelection();
this.selection.addEventListener("changeCursor", this.$onCursorChange);
@ -2556,13 +2562,14 @@ var Editor = function(renderer, session) {
this.onChangeMode();
this.onCursorChange();
this.onScrollTopChange();
this.onScrollLeftChange();
this.onSelectionChange();
this.onChangeFrontMarker();
this.onChangeBackMarker();
this.onChangeBreakpoint();
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.scrollToRow(session.getScrollTopRow());
this.renderer.updateFull();
this._emit("changeSession", {
@ -2680,6 +2687,14 @@ var Editor = function(renderer, session) {
this.renderer.updateLines(rows.first, rows.last);
};
this.onScrollTopChange = function() {
this.renderer.scrollToY(this.session.getScrollTop());
};
this.onScrollLeftChange = function() {
this.renderer.scrollToX(this.session.getScrollLeft());
};
this.onCursorChange = function() {
this.renderer.updateCursor();
@ -5995,18 +6010,34 @@ var EditSession = function(text, mode) {
this.getMode = function() {
return this.$mode;
};
this.$scrollTop = 0;
this.setScrollTopRow = function(scrollTopRow) {
if (this.$scrollTop === scrollTopRow) return;
this.setScrollTop = function(scrollTop) {
scrollTop = Math.round(Math.max(0, scrollTop));
if (this.$scrollTop === scrollTop)
return;
this.$scrollTop = scrollTopRow;
this._emit("changeScrollTop");
this.$scrollTop = scrollTop;
this._emit("changeScrollTop", scrollTop);
};
this.getScrollTopRow = function() {
this.getScrollTop = function() {
return this.$scrollTop;
};
this.$scrollLeft = 0;
this.setScrollLeft = function(scrollLeft) {
scrollLeft = Math.round(Math.max(0, scrollLeft));
if (this.$scrollLeft === scrollLeft)
return;
this.$scrollLeft = scrollLeft;
this._emit("changeScrollLeft", scrollLeft);
};
this.getScrollLeft = function() {
return this.$scrollLeft;
};
this.getWidth = function() {
this.$computeWidth();
@ -11570,11 +11601,12 @@ exports.UndoManager = UndoManager;
*
* ***** END LICENSE BLOCK ***** */
define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/useragent', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/lib/event_emitter', 'text!ace/css/editor.css'], function(require, exports, module) {
define('ace/virtual_renderer', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/dom', 'ace/lib/event', 'ace/lib/useragent', 'ace/layer/gutter', 'ace/layer/marker', 'ace/layer/text', 'ace/layer/cursor', 'ace/scrollbar', 'ace/renderloop', 'ace/lib/event_emitter', 'text!ace/css/editor.css'], function(require, exports, module) {
"use strict";
var oop = require("./lib/oop");
var dom = require("./lib/dom");
var event = require("./lib/event");
var useragent = require("./lib/useragent");
var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker;
@ -11588,6 +11620,8 @@ var editorCss = require("text!./css/editor.css");
dom.importCssString(editorCss, "ace_editor");
var VirtualRenderer = function(container, theme) {
var _self = this;
this.container = container;
// TODO: this breaks rendering in Cloud9 with multiple ace instances
@ -11631,16 +11665,22 @@ var VirtualRenderer = function(container, theme) {
this.$horizScrollAlwaysVisible = true;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
this.scrollBar.addEventListener("scroll", function(e) {
_self.session.setScrollTop(e.data);
});
this.scrollTop = 0;
this.scrollLeft = 0;
event.addListener(this.scroller, "scroll", function() {
_self.session.setScrollLeft(_self.scroller.scrollLeft);
});
this.cursorPos = {
row : 0,
column : 0
};
var _self = this;
this.$textLayer.addEventListener("changeCharaterSize", function() {
_self.characterWidth = textLayer.getCharacterWidth();
_self.lineHeight = textLayer.getLineHeight();
@ -11925,10 +11965,6 @@ var VirtualRenderer = function(container, theme) {
}
};
this.onScroll = function(e) {
this.scrollToY(e.data);
};
this.$updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.layerConfig.maxHeight);
this.scrollBar.setScrollTop(this.scrollTop);
@ -12020,7 +12056,7 @@ var VirtualRenderer = function(container, theme) {
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
var maxHeight = this.session.getScreenLength() * this.lineHeight;
this.scrollTop = Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight));
this.session.setScrollTop(Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight)));
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
@ -12175,7 +12211,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollToY(top + this.lineHeight - this.$size.scrollerHeight);
}
var scrollLeft = this.scroller.scrollLeft;
var scrollLeft = this.scrollLeft;
if (scrollLeft > left) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth)
@ -12192,11 +12228,11 @@ var VirtualRenderer = function(container, theme) {
};
this.getScrollTop = function() {
return this.scrollTop;
return this.session.getScrollTop();
};
this.getScrollLeft = function() {
return this.scroller.scrollLeft;
return this.session.getScrollLop();
};
this.getScrollTopRow = function() {
@ -12227,7 +12263,6 @@ var VirtualRenderer = function(container, theme) {
this.scrollToY = function(scrollTop) {
// after calling scrollBar.setScrollTop
// scrollbar sends us event with same scrollTop. ignore it
scrollTop = Math.max(0, scrollTop);
if (this.scrollTop !== scrollTop) {
this.$loop.schedule(this.CHANGE_SCROLL);
this.scrollTop = scrollTop;
@ -12240,18 +12275,19 @@ var VirtualRenderer = function(container, theme) {
scrollLeft = 0;
this.scroller.scrollLeft = scrollLeft;
this._emit("scrollX", this.scroller.scrollLeft);
scrollLeft = this.scroller.scrollLeft;
this._emit("scrollX", scrollLeft);
};
this.scrollBy = function(deltaX, deltaY) {
deltaY && this.scrollToY(this.scrollTop + deltaY);
deltaX && this.scrollToX(this.scroller.scrollLeft + deltaX);
deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY);
deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX);
};
this.isScrollableBy = function(deltaX, deltaY) {
if (deltaY < 0 && this.scrollTop > 0)
if (deltaY < 0 && this.session.getScrollTop() > 0)
return true;
if (deltaY > 0 && this.scrollTop + this.$size.scrollerHeight < this.layerConfig.maxHeight)
if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight < this.layerConfig.maxHeight)
return true;
// todo: handle horizontal scrolling
};
@ -12259,10 +12295,14 @@ var VirtualRenderer = function(container, theme) {
this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft())
/ this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
/ this.lineHeight);
var col = Math.round(
(pageX + this.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft())
/ this.characterWidth
);
var row = Math.floor(
(pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
/ this.lineHeight
);
return this.session.screenToDocumentPosition(row, Math.max(col, 0));
};
@ -12275,8 +12315,8 @@ var VirtualRenderer = function(container, theme) {
var y = pos.row * this.lineHeight;
return {
pageX: canvasPos.left + x - this.getScrollLeft(),
pageY: canvasPos.top + y - this.getScrollTop()
pageX: canvasPos.left + x - this.scrollLeft,
pageY: canvasPos.top + y - this.scrollTop
};
};

File diff suppressed because one or more lines are too long