add option to show the print margin

This commit is contained in:
Fabian Jakobs 2010-05-05 10:49:41 +02:00
commit 5955289793
4 changed files with 74 additions and 11 deletions

View file

@ -14,6 +14,7 @@
position: absolute; position: absolute;
overflow-x: scroll; overflow-x: scroll;
overflow-y: hidden; overflow-y: hidden;
height: 100%;
} }
.editor .sb { .editor .sb {
@ -29,11 +30,17 @@
left: 0px; left: 0px;
} }
.editor .printMargin {
position: absolute;
height: 100%;
}
.layer { .layer {
z-index: 0; z-index: 0;
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
height: 100%;
} }
.text-layer { .text-layer {

View file

@ -15,6 +15,11 @@
font-size: 12px; font-size: 12px;
} }
.editor .printMargin {
width: 1px;
background: rgb(191, 191, 191);
}
.gutter-layer { .gutter-layer {
right: 10px; right: 10px;
text-align: right; text-align: right;

View file

@ -360,18 +360,32 @@ ace.Editor = function(renderer, doc) {
return this.$highlightActiveLine; return this.$highlightActiveLine;
}; };
this.$showInvisibles = true;
this.setShowInvisibles = function(showInvisibles) { this.setShowInvisibles = function(showInvisibles) {
showInvisibles = !!showInvisibles; if (this.getShowInvisibles() == showInvisibles)
if (this.$showInvisibles == showInvisibles) return; return;
this.$showInvisibles = showInvisibles;
this.renderer.setShowInvisibles(showInvisibles); this.renderer.setShowInvisibles(showInvisibles);
this.renderer.draw(); this.renderer.draw();
}; };
this.getShowInvisibles = function() { this.getShowInvisibles = function() {
return this.showInvisibles; return this.renderer.getShowInvisibles();
};
this.setShowPrintMargin = function(showPrintMargin) {
this.renderer.setShowPrintMargin(showPrintMargin);
};
this.getShowPrintMargin = function() {
return this.renderer.getShowPrintMargin();
};
this.setPrintMarginColumn = function(showPrintMargin) {
this.renderer.setPrintMarginColumn(showPrintMargin);
};
this.getPrintMarginColumn = function() {
return this.renderer.getPrintMarginColumn();
}; };
this.$readOnly = false; this.$readOnly = false;

View file

@ -13,7 +13,7 @@ ace.VirtualRenderer = function(container) {
this.container.appendChild(this.gutter); this.container.appendChild(this.gutter);
this.content = document.createElement("div"); this.content = document.createElement("div");
this.scroller.appendChild(this.content) this.scroller.appendChild(this.content);
this.gutterLayer = new ace.layer.Gutter(this.gutter); this.gutterLayer = new ace.layer.Gutter(this.gutter);
this.markerLayer = new ace.layer.Marker(this.content); this.markerLayer = new ace.layer.Marker(this.content);
@ -38,6 +38,7 @@ ace.VirtualRenderer = function(container) {
column : 0 column : 0
}; };
this.$updatePrintMargin();
this.onResize(); this.onResize();
}; };
@ -60,6 +61,45 @@ ace.VirtualRenderer = function(container) {
this.textLayer.setShowInvisibles(showInvisibles); this.textLayer.setShowInvisibles(showInvisibles);
}; };
this.getShowInvisibles = function() {
return this.showInvisibles;
};
this.$showPrintMargin = true;
this.setShowPrintMargin = function(showPrintMargin) {
this.$showPrintMargin = showPrintMargin;
this.$updatePrintMargin();
};
this.getShowPrintMargin = function() {
return this.$showPrintMargin;
};
this.$printMarginColumn = 80;
this.setPrintMarginColumn = function(showPrintMargin) {
this.$printMarginColumn = showPrintMargin;
this.$updatePrintMargin();
};
this.getPrintMarginColumn = function() {
return this.$printMarginColumn;
};
this.$updatePrintMargin = function() {
if (!this.$showPrintMargin && !this.$printMarginEl)
return;
if (!this.$printMarginEl) {
this.$printMarginEl = document.createElement("div");
this.$printMarginEl.className = "printMargin";
this.content.insertBefore(this.$printMarginEl, this.gutter.element);
}
var style = this.$printMarginEl.style;
style.left = (this.characterWidth * this.$printMarginColumn) + "px";
style.visibility = this.$showPrintMargin ? "visible" : "hidden";
};
this.getContainerElement = function() { this.getContainerElement = function() {
return this.container; return this.container;
}; };
@ -79,7 +119,6 @@ ace.VirtualRenderer = function(container) {
this.onResize = function() this.onResize = function()
{ {
var height = ace.getInnerHeight(this.container); var height = ace.getInnerHeight(this.container);
this.gutter.style.height = height + "px";
this.scroller.style.height = height + "px"; this.scroller.style.height = height + "px";
this.scrollBar.setHeight(height); this.scrollBar.setHeight(height);
@ -150,14 +189,12 @@ ace.VirtualRenderer = function(container) {
var layer = this.layers[i]; var layer = this.layers[i];
var style = layer.element.style; var style = layer.element.style;
style.height = minHeight + "px";
style.width = longestLine + "px"; style.width = longestLine + "px";
layer.update(layerConfig); layer.update(layerConfig);
}; };
this.gutterLayer.element.style.marginTop = (-offset) + "px"; this.gutterLayer.element.style.marginTop = (-offset) + "px";
this.gutterLayer.element.style.height = minHeight + "px";
this.gutterLayer.update(layerConfig); this.gutterLayer.update(layerConfig);
this.$updateScrollBar(); this.$updateScrollBar();