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) {
|
||||
this.$modified = true;
|
||||
this.$breakpoints = [];
|
||||
this.$decorations = [];
|
||||
this.$frontMarkers = {};
|
||||
this.$backMarkers = {};
|
||||
this.$markerId = 1;
|
||||
this.$resetRowCache(0);
|
||||
this.$wrapData = [];
|
||||
this.$foldData = [];
|
||||
this.$rowLengthCache = [];
|
||||
this.$undoSelect = true;
|
||||
|
||||
this.$foldData = [];
|
||||
this.$foldData.toString = function() {
|
||||
var str = "";
|
||||
this.forEach(function(foldLine) {
|
||||
|
|
@ -166,12 +163,13 @@ var EditSession = function(text, mode) {
|
|||
});
|
||||
return str;
|
||||
}
|
||||
this.on("changeFold", this.onChangeFold.bind(this));
|
||||
this.$onChange = this.onChange.bind(this);
|
||||
|
||||
if (typeof text != "object" || !text.getLine)
|
||||
text = new Document(text);
|
||||
|
||||
if (typeof text == "object" && text.getLine) {
|
||||
this.setDocument(text);
|
||||
} else {
|
||||
this.setDocument(new Document(text));
|
||||
}
|
||||
this.setDocument(text);
|
||||
|
||||
this.selection = new Selection(this);
|
||||
this.setMode(mode);
|
||||
|
|
@ -191,16 +189,15 @@ var EditSession = function(text, mode) {
|
|||
**/
|
||||
this.setDocument = function(doc) {
|
||||
if (this.doc)
|
||||
throw new Error("Document is already set");
|
||||
this.doc.removeListener("change", this.$onChange);
|
||||
|
||||
this.doc = doc;
|
||||
doc.on("change", this.onChange.bind(this));
|
||||
this.on("changeFold", this.onChangeFold.bind(this));
|
||||
doc.on("change", this.$onChange);
|
||||
|
||||
if (this.bgTokenizer) {
|
||||
if (this.bgTokenizer)
|
||||
this.bgTokenizer.setDocument(this.getDocument());
|
||||
this.bgTokenizer.start(0);
|
||||
}
|
||||
|
||||
this.resetCaches();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -253,6 +250,15 @@ var EditSession = function(text, mode) {
|
|||
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) {
|
||||
var fold = e.data;
|
||||
this.$resetRowCache(fold.start.row);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue