allow setting editor session to null

This commit is contained in:
nightwing 2014-02-15 14:07:31 +04:00
commit 9c80485d91

View file

@ -289,14 +289,13 @@ var Editor = function(renderer, session) {
* Sets a new editsession to use. This method also emits the `'changeSession'` event. * Sets a new editsession to use. This method also emits the `'changeSession'` event.
* @param {EditSession} session The new session to use * @param {EditSession} session The new session to use
* *
*
**/ **/
this.setSession = function(session) { this.setSession = function(session) {
if (this.session == session) if (this.session == session)
return; return;
if (this.session) {
var oldSession = this.session; var oldSession = this.session;
if (oldSession) {
this.session.removeEventListener("change", this.$onDocumentChange); this.session.removeEventListener("change", this.$onDocumentChange);
this.session.removeEventListener("changeMode", this.$onChangeMode); this.session.removeEventListener("changeMode", this.$onChangeMode);
this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate); this.session.removeEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
@ -318,7 +317,7 @@ var Editor = function(renderer, session) {
} }
this.session = session; this.session = session;
if (session) {
this.$onDocumentChange = this.onDocumentChange.bind(this); this.$onDocumentChange = this.onDocumentChange.bind(this);
session.addEventListener("change", this.$onDocumentChange); session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session); this.renderer.setSession(session);
@ -383,11 +382,15 @@ var Editor = function(renderer, session) {
this.onChangeAnnotation(); this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit(); this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.renderer.updateFull(); this.renderer.updateFull();
}
this._signal("changeSession", { this._signal("changeSession", {
session: session, session: session,
oldSession: oldSession oldSession: oldSession
}); });
oldSession && oldSession._signal("changeEditor", {oldEditor: this});
session && session._signal("changeEditor", {editor: this});
}; };
/** /**