Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3538 from adobe/randy/hover-preview-dismiss
Browse files Browse the repository at this point in the history
Hide Hover Preview popover when doc is edited or switched
  • Loading branch information
peterflynn committed Apr 24, 2013
2 parents b6f7563 + b7ac07a commit 0168533
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/extensions/default/HoverPreview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define(function (require, exports, module) {
// Brackets modules
var AppInit = brackets.getModule("utils/AppInit"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Menus = brackets.getModule("command/Menus"),
Expand Down Expand Up @@ -433,7 +434,19 @@ define(function (require, exports, module) {
}
}


function onActiveEditorChange(event, current, previous) {
// Hide preview when editor changes
hidePreview();

if (previous && previous.document) {
$(previous.document).off("change", hidePreview);
}

if (current && current.document) {
$(current.document).on("change", hidePreview);
}
}

// Menu command handlers
function updateMenuItemCheckmark() {
CommandManager.get(CMD_ENABLE_HOVER_PREVIEW).setChecked(enabled);
Expand All @@ -448,9 +461,19 @@ define(function (require, exports, module) {
// we auto-hide on text edit, which is probably actually a good thing.
editorHolder.addEventListener("mousemove", handleMouseMove, true);
editorHolder.addEventListener("scroll", hidePreview, true);

// Setup doc "change" listener
onActiveEditorChange(null, EditorManager.getActiveEditor(), null);
$(EditorManager).on("activeEditorChange", onActiveEditorChange);

} else {
editorHolder.removeEventListener("mousemove", handleMouseMove, true);
editorHolder.removeEventListener("scroll", hidePreview, true);

// Cleanup doc "change" listener
onActiveEditorChange(null, null, EditorManager.getActiveEditor());
$(EditorManager).off("activeEditorChange", onActiveEditorChange);

hidePreview();
}
prefs.setValue("enabled", enabled);
Expand Down

0 comments on commit 0168533

Please sign in to comment.