Merge pull request #602 from nightwing/pullreq

bugfix
This commit is contained in:
Fabian Jakobs 2012-01-02 10:04:49 -08:00
commit c1a8d2a1dc
7 changed files with 34 additions and 33 deletions

View file

@ -263,6 +263,11 @@ exports.commands = [{
bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"), bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
exec: function(editor) { editor.commands.replay(editor); }, exec: function(editor) { editor.commands.replay(editor); },
readOnly: true readOnly: true
}, {
name: "jumptomatching",
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
exec: function(editor) { editor.jumpToMatching(); },
readOnly: true
}, },
// commands disabled in readOnly mode // commands disabled in readOnly mode
@ -381,10 +386,6 @@ exports.commands = [{
name: "tolowercase", name: "tolowercase",
bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"), bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
exec: function(editor) { editor.toLowerCase(); } exec: function(editor) { editor.toLowerCase(); }
}, {
name: "jumptomatching",
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
exec: function(editor) { editor.jumpToMatching(); }
}]; }];
}); });

View file

@ -625,7 +625,7 @@ function Folding() {
this.foldAll = function(startRow, endRow) { this.foldAll = function(startRow, endRow) {
var foldWidgets = this.foldWidgets; var foldWidgets = this.foldWidgets;
endRow = endRow || foldWidgets.length; endRow = endRow || this.getLength();
for (var row = startRow || 0; row < endRow; row++) { for (var row = startRow || 0; row < endRow; row++) {
if (foldWidgets[row] == null) if (foldWidgets[row] == null)
foldWidgets[row] = this.getFoldWidget(row); foldWidgets[row] = this.getFoldWidget(row);

View file

@ -221,6 +221,7 @@ var Editor = function(renderer, session) {
this.setFontSize = function(size) { this.setFontSize = function(size) {
this.container.style.fontSize = size; this.container.style.fontSize = size;
this.renderer.updateFontSize();
}; };
this.$highlightBrackets = function() { this.$highlightBrackets = function() {
@ -1205,8 +1206,7 @@ var Editor = function(renderer, session) {
var range = this.$search.find(this.session); var range = this.$search.find(this.session);
if (range) { if (range) {
this.session.unfold(range); this.session.unfold(range);
this.gotoLine(range.end.row+1, range.end.column); this.selection.setSelectionRange(range); // this scrolls selection into view
this.selection.setSelectionRange(range);
} }
}; };

View file

@ -93,7 +93,7 @@ var Cursor = function(parentEl) {
}, 1000); }, 1000);
}; };
this.getPixelPosition = function(onScreen) { this.getPixelPosition = function(position, onScreen) {
if (!this.config || !this.session) { if (!this.config || !this.session) {
return { return {
left : 0, left : 0,
@ -101,7 +101,8 @@ var Cursor = function(parentEl) {
}; };
} }
var position = this.session.selection.getCursor(); if (!position)
position = this.session.selection.getCursor();
var pos = this.session.documentToScreenPosition(position); var pos = this.session.documentToScreenPosition(position);
var cursorLeft = Math.round(this.$padding + var cursorLeft = Math.round(this.$padding +
pos.column * this.config.characterWidth); pos.column * this.config.characterWidth);
@ -117,7 +118,7 @@ var Cursor = function(parentEl) {
this.update = function(config) { this.update = function(config) {
this.config = config; this.config = config;
this.pixelPos = this.getPixelPosition(true); this.pixelPos = this.getPixelPosition(null, true);
this.cursor.style.left = this.pixelPos.left + "px"; this.cursor.style.left = this.pixelPos.left + "px";
this.cursor.style.top = this.pixelPos.top + "px"; this.cursor.style.top = this.pixelPos.top + "px";

View file

@ -84,7 +84,7 @@ var Text = function(parentEl) {
var size = this.$measureSizes(); var size = this.$measureSizes();
if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) { if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) {
this.$characterSize = size; this.$characterSize = size;
this._emit("changeCharaterSize", {data: size}); this._emit("changeCharacterSize", {data: size});
} }
}; };

View file

@ -117,6 +117,8 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
var range = delta.range; var range = delta.range;
if(range.start.row !== range.end.row) return; if(range.start.row !== range.end.row) return;
if(range.start.row !== this.pos.row) return; if(range.start.row !== this.pos.row) return;
if (this.$updating) return;
this.$updating = true;
var lengthDiff = delta.action === "insertText" ? range.end.column - range.start.column : range.start.column - range.end.column; var lengthDiff = delta.action === "insertText" ? range.end.column - range.start.column : range.start.column - range.end.column;
if(range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1) { if(range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1) {
@ -169,9 +171,11 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
this.others[i]._emit("change", {value: this.others[i]}); this.others[i]._emit("change", {value: this.others[i]});
} }
} }
this.$updating = false;
}; };
this.onCursorChange = function(event) { this.onCursorChange = function(event) {
if (this.$updating) return;
var pos = this.session.selection.getCursor(); var pos = this.session.selection.getCursor();
if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) { if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
this.showOtherMarkers(); this.showOtherMarkers();

View file

@ -118,7 +118,7 @@ var VirtualRenderer = function(container, theme) {
column : 0 column : 0
}; };
this.$textLayer.addEventListener("changeCharaterSize", function() { this.$textLayer.addEventListener("changeCharacterSize", function() {
_self.characterWidth = textLayer.getCharacterWidth(); _self.characterWidth = textLayer.getCharacterWidth();
_self.lineHeight = textLayer.getLineHeight(); _self.lineHeight = textLayer.getLineHeight();
_self.$updatePrintMargin(); _self.$updatePrintMargin();
@ -171,6 +171,7 @@ var VirtualRenderer = function(container, theme) {
this.CHANGE_MARKER_BACK = 128; this.CHANGE_MARKER_BACK = 128;
this.CHANGE_MARKER_FRONT = 256; this.CHANGE_MARKER_FRONT = 256;
this.CHANGE_FULL = 512; this.CHANGE_FULL = 512;
this.CHANGE_H_SCROLL = 1024;
oop.implement(this, EventEmitter); oop.implement(this, EventEmitter);
@ -476,6 +477,11 @@ var VirtualRenderer = function(container, theme) {
if (changes & this.CHANGE_SIZE) if (changes & this.CHANGE_SIZE)
this.$updateScrollBar(); this.$updateScrollBar();
if (changes & this.CHANGE_H_SCROLL) {
//this.content.style.left = -this.scrollLeft + "px";
this.scroller.scrollLeft = this.scrollLeft
}
}; };
this.$computeLayerConfig = function() { this.$computeLayerConfig = function() {
@ -542,12 +548,6 @@ var VirtualRenderer = function(container, theme) {
this.content.style.width = longestLine + 2 * this.$padding + "px"; this.content.style.width = longestLine + 2 * this.$padding + "px";
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
// scroller.scrollWidth was smaller than scrollLeft we needed
if (this.$desiredScrollLeft) {
this.scrollToX(this.$desiredScrollLeft);
this.$desiredScrollLeft = 0;
}
// Horizontal scrollbar visibility may have changed, which changes // Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller // the client height of the scroller
if (horizScrollChanged) if (horizScrollChanged)
@ -653,14 +653,11 @@ var VirtualRenderer = function(container, theme) {
if (scrollLeft > left) { if (scrollLeft > left) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth) if (left < this.$padding + 2 * this.layerConfig.characterWidth)
left = 0; left = 0;
this.scrollToX(left); this.session.setScrollLeft(left);
} }
if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) { if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
if (left > this.layerConfig.width + 2 * this.$padding) this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
this.$desiredScrollLeft = left;
else
this.scrollToX(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
} }
}; };
@ -685,15 +682,11 @@ var VirtualRenderer = function(container, theme) {
}; };
this.scrollToLine = function(line, center) { this.scrollToLine = function(line, center) {
var lineHeight = { lineHeight: this.lineHeight }; var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = 0; var offset = pos.top;
for (var l = 1; l < line; l++) { if (center)
offset += this.session.getRowHeight(lineHeight, l-1);
}
if (center) {
offset -= this.$size.scrollerHeight / 2; offset -= this.$size.scrollerHeight / 2;
}
this.session.setScrollTop(offset); this.session.setScrollTop(offset);
}; };
@ -710,8 +703,10 @@ var VirtualRenderer = function(container, theme) {
if (scrollLeft <= this.$padding) if (scrollLeft <= this.$padding)
scrollLeft = 0; scrollLeft = 0;
this.scroller.scrollLeft = scrollLeft; if (this.scrollLeft !== scrollLeft) {
scrollLeft = this.scroller.scrollLeft; this.$loop.schedule(this.CHANGE_H_SCROLL);
this.scrollLeft = scrollLeft;
}
}; };
this.scrollBy = function(deltaX, deltaY) { this.scrollBy = function(deltaX, deltaY) {