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) {
this.$modified = true;
this.$breakpoints = [];
this.$decorations = [];
this.$frontMarkers = {};
this.$backMarkers = {};
this.$markerId = 1;
@ -489,7 +490,33 @@ var EditSession = function(text, mode) {
this.toggleOverwrite = function() {
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
*

View file

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

View file

@ -875,26 +875,20 @@ var VirtualRenderer = function(container, theme) {
/**
* 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.$gutterLayer.addGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**
* 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.$gutterLayer.removeGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER);
};
/**