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,76 +317,80 @@ var Editor = function(renderer, session) {
} }
this.session = session; this.session = session;
if (session) {
this.$onDocumentChange = this.onDocumentChange.bind(this);
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onDocumentChange = this.onDocumentChange.bind(this); this.$onChangeMode = this.onChangeMode.bind(this);
session.addEventListener("change", this.$onDocumentChange); session.addEventListener("changeMode", this.$onChangeMode);
this.renderer.setSession(session);
this.$onChangeMode = this.onChangeMode.bind(this); this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this);
session.addEventListener("changeMode", this.$onChangeMode); session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate);
this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this); this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer);
session.addEventListener("tokenizerUpdate", this.$onTokenizerUpdate); session.addEventListener("changeTabSize", this.$onChangeTabSize);
this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer); this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
session.addEventListener("changeTabSize", this.$onChangeTabSize); session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this); this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit); session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this); this.$onChangeFold = this.onChangeFold.bind(this);
session.addEventListener("changeWrapMode", this.$onChangeWrapMode); session.addEventListener("changeFold", this.$onChangeFold);
this.$onChangeFold = this.onChangeFold.bind(this); this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
session.addEventListener("changeFold", this.$onChangeFold); this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this); this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker); this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this); this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker); this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this); this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint); this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this); this.$onCursorChange = this.onCursorChange.bind(this);
this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation); this.session.addEventListener("changeOverwrite", this.$onCursorChange);
this.$onCursorChange = this.onCursorChange.bind(this); this.$onScrollTopChange = this.onScrollTopChange.bind(this);
this.session.addEventListener("changeOverwrite", this.$onCursorChange); this.session.addEventListener("changeScrollTop", this.$onScrollTopChange);
this.$onScrollTopChange = this.onScrollTopChange.bind(this); this.$onScrollLeftChange = this.onScrollLeftChange.bind(this);
this.session.addEventListener("changeScrollTop", this.$onScrollTopChange); this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange);
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this); this.selection = session.getSelection();
this.session.addEventListener("changeScrollLeft", this.$onScrollLeftChange); this.selection.addEventListener("changeCursor", this.$onCursorChange);
this.selection = session.getSelection(); this.$onSelectionChange = this.onSelectionChange.bind(this);
this.selection.addEventListener("changeCursor", this.$onCursorChange); this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.$onSelectionChange = this.onSelectionChange.bind(this); this.onChangeMode();
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onChangeMode(); this.$blockScrolling += 1;
this.onCursorChange();
this.$blockScrolling -= 1;
this.$blockScrolling += 1; this.onScrollTopChange();
this.onCursorChange(); this.onScrollLeftChange();
this.$blockScrolling -= 1; this.onSelectionChange();
this.onChangeFrontMarker();
this.onScrollTopChange(); this.onChangeBackMarker();
this.onScrollLeftChange(); this.onChangeBreakpoint();
this.onSelectionChange(); this.onChangeAnnotation();
this.onChangeFrontMarker(); this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
this.onChangeBackMarker(); this.renderer.updateFull();
this.onChangeBreakpoint(); }
this.onChangeAnnotation();
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit();
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});
}; };
/** /**