allow to change document of session
This commit is contained in:
parent
3f8aa00d23
commit
58ac58ee34
1 changed files with 22 additions and 16 deletions
|
|
@ -148,17 +148,14 @@ var SearchHighlight = require("./search_highlight").SearchHighlight;
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var EditSession = function(text, mode) {
|
var EditSession = function(text, mode) {
|
||||||
this.$modified = true;
|
|
||||||
this.$breakpoints = [];
|
this.$breakpoints = [];
|
||||||
this.$decorations = [];
|
this.$decorations = [];
|
||||||
this.$frontMarkers = {};
|
this.$frontMarkers = {};
|
||||||
this.$backMarkers = {};
|
this.$backMarkers = {};
|
||||||
this.$markerId = 1;
|
this.$markerId = 1;
|
||||||
this.$resetRowCache(0);
|
|
||||||
this.$wrapData = [];
|
|
||||||
this.$foldData = [];
|
|
||||||
this.$rowLengthCache = [];
|
|
||||||
this.$undoSelect = true;
|
this.$undoSelect = true;
|
||||||
|
|
||||||
|
this.$foldData = [];
|
||||||
this.$foldData.toString = function() {
|
this.$foldData.toString = function() {
|
||||||
var str = "";
|
var str = "";
|
||||||
this.forEach(function(foldLine) {
|
this.forEach(function(foldLine) {
|
||||||
|
|
@ -166,12 +163,13 @@ var EditSession = function(text, mode) {
|
||||||
});
|
});
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
this.on("changeFold", this.onChangeFold.bind(this));
|
||||||
|
this.$onChange = this.onChange.bind(this);
|
||||||
|
|
||||||
if (typeof text == "object" && text.getLine) {
|
if (typeof text != "object" || !text.getLine)
|
||||||
this.setDocument(text);
|
text = new Document(text);
|
||||||
} else {
|
|
||||||
this.setDocument(new Document(text));
|
this.setDocument(text);
|
||||||
}
|
|
||||||
|
|
||||||
this.selection = new Selection(this);
|
this.selection = new Selection(this);
|
||||||
this.setMode(mode);
|
this.setMode(mode);
|
||||||
|
|
@ -191,16 +189,15 @@ var EditSession = function(text, mode) {
|
||||||
**/
|
**/
|
||||||
this.setDocument = function(doc) {
|
this.setDocument = function(doc) {
|
||||||
if (this.doc)
|
if (this.doc)
|
||||||
throw new Error("Document is already set");
|
this.doc.removeListener("change", this.$onChange);
|
||||||
|
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.on("change", this.onChange.bind(this));
|
doc.on("change", this.$onChange);
|
||||||
this.on("changeFold", this.onChangeFold.bind(this));
|
|
||||||
|
|
||||||
if (this.bgTokenizer) {
|
if (this.bgTokenizer)
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
this.bgTokenizer.setDocument(this.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
|
||||||
}
|
this.resetCaches();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,6 +250,15 @@ var EditSession = function(text, mode) {
|
||||||
return low && low -1;
|
return low && low -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.resetCaches = function() {
|
||||||
|
this.$modified = true;
|
||||||
|
this.$wrapData = [];
|
||||||
|
this.$rowLengthCache = [];
|
||||||
|
this.$resetRowCache(0);
|
||||||
|
if (this.bgTokenizer)
|
||||||
|
this.bgTokenizer.start(0);
|
||||||
|
};
|
||||||
|
|
||||||
this.onChangeFold = function(e) {
|
this.onChangeFold = function(e) {
|
||||||
var fold = e.data;
|
var fold = e.data;
|
||||||
this.$resetRowCache(fold.start.row);
|
this.$resetRowCache(fold.start.row);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue