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

Hide popover when doc is edited or changes #3538

Merged
merged 6 commits into from
Apr 24, 2013

Conversation

redmunds
Copy link
Contributor

This is for #3484 and #3513.

@ghost ghost assigned RaymondLim Apr 22, 2013
@@ -305,6 +307,21 @@ define(function (require, exports, module) {
return lastPreviewedImagePath;
}

function onActiveEditorChange(event, current, previous) {
if (currentDocument) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comment here since we're referring to the old document in this if block and currentDocument is updated after this if block.

Or maybe you should use previous param to distinguish the old one from a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we used previous.document, then the first time this method is called, we will call releaseRef() for a doc that we did not call addRef().

Keeping track of the doc ourself assures that we keep references (and event listening) accurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in other places we cheat a little and don't bother to addRef() for listeners that are exactly tracking the current document (or active/focused editor) -- since as long as there's an editor we can be certain the Document isn't going away. If we did that here it would simplify the code a bit. But the way it is here seems fine too... your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all for cleaner code. So, you think it's ok to stop listening to previous.document and start listening to current.document? Doesn't seem as reliable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not add/RemoveRef()'ing anymore then that should work fine. Lots of stuff relies on activeEditorChange, so I think we can trust the event to fire reliably. That said, the code as written here should work fine too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: we repeat this pattern enough that I've been wondering if we should eventually factor this out into some sort of proxy object that's easier to listen to. Will definitely keep pondering that...

@ghost ghost assigned peterflynn Apr 22, 2013

if (currentDocument) {
currentDocument.addRef();
$(currentDocument).on("change", hidePreview);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can hover over an editor without it being active/focused, so you may wind up listening to the wrong editor here. But, I think it may be ok anyway.

For practical purposes, you can't modify an editor that's not focused without moving the mouse at all, so we won't miss any changes that would invalidate the popover. We could get a false positive -- hiding a popover in one editor when a change happens in a different, focused editor. But that doesn't seem too bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just dismiss on any edit. I think this is good enough.

@redmunds
Copy link
Contributor Author

@peterflynn waiting for responses to 2 questions about your comments.

@peterflynn
Copy link
Member

@redmunds just posted responses back

@redmunds
Copy link
Contributor Author

Code Review changes pushed.

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

// Cleanup doc "change" listener
onActiveEditorChange(null, null, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to get changed now so the last arg is EditorManager.getActiveEditor() -- otherwise the last-used listener won't get removed when it's toggled off.

@peterflynn
Copy link
Member

I've pushed up a fix for that one last issue since Randy is busy with #3540. Good to merge now!

peterflynn added a commit that referenced this pull request Apr 24, 2013
Hide Hover Preview popover when doc is edited or switched
@peterflynn peterflynn merged commit 0168533 into master Apr 24, 2013
@peterflynn peterflynn deleted the randy/hover-preview-dismiss branch April 24, 2013 01:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants