Merge pull request #8444 from adobe/pflynn/language-switcher-improvements

Language switcher: connect to prefs & clean up some code
This commit is contained in:
Jeff Booher committed 2014-08-06 14:38:24 -07:00
commit 90398b4f60
13 files changed
+190 -137

No files matched your search

@@ -1129,9 +1129,9 @@ define(function (require, exports, module) {
/**
* Do the work to initialize a code hinting session.
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document the editor has changed to
* @param {Document} previousDocument - the document the editor has changed from
* @param {Session} session - the active hinting session (TODO: currently unused)
* @param {!Document} document - the document the editor has changed to
* @param {?Document} previousDocument - the document the editor has changed from
*/
function doEditorChange(session, document, previousDocument) {
var file = document.file,
@@ -1229,9 +1229,9 @@ define(function (require, exports, module) {
/**
* Called each time a new editor becomes active.
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document of the editor that has changed
* @param {Document} previousDocument - the document of the editor is changing from
* @param {Session} session - the active hinting session (TODO: currently unused by doEditorChange())
* @param {!Document} document - the document of the editor that has changed
* @param {?Document} previousDocument - the document of the editor is changing from
*/
function handleEditorChange(session, document, previousDocument) {
if (addFilesPromise === null) {
@@ -1469,7 +1469,7 @@ define(function (require, exports, module) {
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document of the editor that has changed
* @param {Document} previousDocument - the document of the editor is changing from
* @param {?Document} previousDocument - the document of the editor is changing from
*/
function handleEditorChange(session, document, previousDocument) {
@@ -585,8 +585,8 @@ define(function (require, exports, module) {
* When the editor is changed, reset the hinting session and cached
* information, and reject any pending deferred requests.
*
* @param {Editor} editor - editor context to be initialized.
* @param {Editor} previousEditor - the previous editor.
* @param {!Editor} editor - editor context to be initialized.
* @param {?Editor} previousEditor - the previous editor.
*/
function initializeSession(editor, previousEditor) {
session = new Session(editor);
@@ -597,11 +597,11 @@ define(function (require, exports, module) {
}
/*
* Install editor change listeners
* Connects to the given editor, creating a new Session & adding listeners
*
* @param {Editor} editor - editor context on which to listen for
* changes
* @param {Editor} previousEditor - the previous editor
* @param {?Editor} editor - editor context on which to listen for
* changes. If null, 'session' is cleared.
* @param {?Editor} previousEditor - the previous editor
*/
function installEditorListeners(editor, previousEditor) {
// always clean up cached scope and hint info
@@ -650,18 +650,21 @@ define(function (require, exports, module) {
* @param {Editor} previous - the previous editor context
*/
function handleActiveEditorChange(event, current, previous) {
// Uninstall "languageChanged" event listeners on the previous editor's document
if (previous && previous !== current) {
// Uninstall "languageChanged" event listeners on previous editor's document & put them on current editor's doc
if (previous) {
$(previous.document)
.off(HintUtils.eventName("languageChanged"));
}
if (current && current.document !== DocumentManager.getCurrentDocument()) {
if (current) {
$(current.document)
.on(HintUtils.eventName("languageChanged"), function () {
// If current doc's language changed, reset our state by treating it as if the user switched to a
// different document altogether
uninstallEditorListeners(current);
installEditorListeners(current);
});
}
uninstallEditorListeners(previous);
installEditorListeners(current, previous);
}
@@ -829,13 +832,6 @@ define(function (require, exports, module) {
.on(HintUtils.eventName("activeEditorChange"),
handleActiveEditorChange);
$(DocumentManager)
.on("currentDocumentLanguageChanged", function (e) {
var activeEditor = EditorManager.getActiveEditor();
uninstallEditorListeners(activeEditor);
installEditorListeners(activeEditor);
});
$(ProjectManager).on("beforeProjectClose", function () {
ScopeManager.handleProjectClose();
});