move gutterDecorations to session

This commit is contained in:
nightwing 2012-07-28 17:38:04 +04:00
commit 599c540c20
3 changed files with 42 additions and 21 deletions

View file

@ -72,6 +72,7 @@ var SearchHighlight = require("./search_highlight").SearchHighlight;
var EditSession = function(text, mode) { var EditSession = function(text, mode) {
this.$modified = true; this.$modified = true;
this.$breakpoints = []; this.$breakpoints = [];
this.$decorations = [];
this.$frontMarkers = {}; this.$frontMarkers = {};
this.$backMarkers = {}; this.$backMarkers = {};
this.$markerId = 1; this.$markerId = 1;
@ -489,7 +490,33 @@ var EditSession = function(text, mode) {
this.toggleOverwrite = function() { this.toggleOverwrite = function() {
this.setOverwrite(!this.$overwrite); this.setOverwrite(!this.$overwrite);
}; };
/**
* EditSession.addGutterDecoration(row, className) -> Void
* - row (Number): The row number
* - className (String): The class to add
*
* Adds `className` to the `row`, to be used for CSS stylings and whatnot.
**/
this.addGutterDecoration = function(row, className) {
if (!this.$decorations[row])
this.$decorations[row] = "";
this.$decorations[row] += " " + className;
this._emit("changeBreakpoint", {});
};
/**
* EditSession.removeGutterDecoration(row, className)-> Void
* - row (Number): The row number
* - className (String): The class to add
*
* Removes `className` from the `row`.
**/
this.removeGutterDecoration = function(row, className) {
this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, "");
this._emit("changeBreakpoint", {});
};
/** /**
* EditSession.getBreakpoints() -> Array * EditSession.getBreakpoints() -> Array
* *

View file

@ -52,9 +52,7 @@ var Gutter = function(parentEl) {
this.gutterWidth = 0; this.gutterWidth = 0;
this.$breakpoints = [];
this.$annotations = []; this.$annotations = [];
this.$decorations = [];
}; };
(function() { (function() {
@ -66,13 +64,15 @@ var Gutter = function(parentEl) {
}; };
this.addGutterDecoration = function(row, className){ this.addGutterDecoration = function(row, className){
if (!this.$decorations[row]) if (window.console)
this.$decorations[row] = ""; console.warn && console.warn("deprecated use session.addGutterDecoration");
this.$decorations[row] += " " + className; this.session.addGutterDecoration(row, className);
}; };
this.removeGutterDecoration = function(row, className){ this.removeGutterDecoration = function(row, className){
this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, ""); if (window.console)
console.warn && console.warn("deprecated use session.removeGutterDecoration");
this.session.removeGutterDecoration(row, className);
}; };
this.setAnnotations = function(annotations) { this.setAnnotations = function(annotations) {
@ -103,8 +103,6 @@ var Gutter = function(parentEl) {
}; };
this.update = function(config) { this.update = function(config) {
this.$config = config;
var emptyAnno = {className: "", text: []}; var emptyAnno = {className: "", text: []};
var html = []; var html = [];
var i = config.firstRow; var i = config.firstRow;
@ -113,6 +111,7 @@ var Gutter = function(parentEl) {
var foldStart = fold ? fold.start.row : Infinity; var foldStart = fold ? fold.start.row : Infinity;
var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets; var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets;
var breakpoints = this.session.$breakpoints; var breakpoints = this.session.$breakpoints;
var decorations = this.session.$decorations;
while (true) { while (true) {
if(i > foldStart) { if(i > foldStart) {
@ -124,12 +123,13 @@ var Gutter = function(parentEl) {
break; break;
var annotation = this.$annotations[i] || emptyAnno; var annotation = this.$annotations[i] || emptyAnno;
html.push("<div class='ace_gutter-cell", html.push(
this.$decorations[i] || "", "<div class='ace_gutter-cell ",
breakpoints[i] ? " ace_breakpoint " : " ", breakpoints[i] || "", decorations[i] || "", annotation.className,
annotation.className,
"' title='", annotation.text.join("\n"), "' title='", annotation.text.join("\n"),
"' style='height:", this.session.getRowLength(i) * config.lineHeight, "px;'>", (i)); "' style='height:", this.session.getRowLength(i) * config.lineHeight, "px;'>",
i + 1
);
if (foldWidgets) { if (foldWidgets) {
var c = foldWidgets[i]; var c = foldWidgets[i];

View file

@ -875,26 +875,20 @@ var VirtualRenderer = function(container, theme) {
/** /**
* VirtualRenderer.addGutterDecoration(row, className) -> Void * VirtualRenderer.addGutterDecoration(row, className) -> Void
* - row (Number): The row number
* - className (String): The class to add
* *
* Adds `className` to the `row`, to be used for CSS stylings and whatnot. * Deprecated (moved to EditSession)
**/ **/
this.addGutterDecoration = function(row, className){ this.addGutterDecoration = function(row, className){
this.$gutterLayer.addGutterDecoration(row, className); this.$gutterLayer.addGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
}; };
/** /**
* VirtualRenderer.removeGutterDecoration(row, className)-> Void * VirtualRenderer.removeGutterDecoration(row, className)-> Void
* - row (Number): The row number
* - className (String): The class to add
* *
* Removes `className` from the `row`. * Deprecated (moved to EditSession)
**/ **/
this.removeGutterDecoration = function(row, className){ this.removeGutterDecoration = function(row, className){
this.$gutterLayer.removeGutterDecoration(row, className); this.$gutterLayer.removeGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
}; };
/** /**