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

Safer focusedEditorChanged event #1877

Merged
merged 2 commits into from
Oct 18, 2012
Merged

Conversation

peterflynn
Copy link
Member

Make editor-swapping more independent from the focusedEditorChanged event, and make the event to fire more consistently.

This fixes the scrolling issue Randy reported in #1864. I think it also fixes all the cases listed in #1860, and it further improves upon #1257 to the point where it's almost fixed.

Code changes:

  • Revert main-editor-swapping codepath back to how it used to work, mostly disentangled from focus events.
    (Doing a git difftool a82cfded^ -- src/editor/EditorManager.js on this branch helps show the similarity to the original code).
  • Don't fire focusedEditorChanged on the many times focus returns to the same Editor that had it last (due to window reactivation, closing a dialog, closing a search bar, etc.). All the current use cases for this event don't care about those cases. Add more detailed docs on event cases.
  • Simplify how Editor signals focus: trigger only from "onFocus" (a superset of the other case), and remove _internalFocus flag that was guarding against the overlap.
  • Don't call resizeEditor() on every editor swap just because statusbar might have been shown/hidden: only call when statusbar actually did change (going to/from no editor). (Required to fix scrolling issue in Fix bug #1627 ("Go to Definition" prepopulated text doesn't work via menu) #1864).

* Revert main-editor-swapping codepath back to how it used to work, mostly
disentangled from focus events.
* Don't fire focusedEditorChanged on the many times focus returns to the
same Editor that had it last (due to window reactivation, closing a dialog,
closing a search bar, etc.). All the current use cases for this event don't
care about those cases. Add more detailed docs on event cases.
* Simplify how Editor signals focus: trigger only from "onFocus" (a superset
of the other case), and remove _internalFocus flag that was guarding against
the overlap.
* Don't call resizeEditor() on every editor swap just because statusbar
*might* have been shown/hidden: only call when statusbar actually did
change (going to/from no editor). Fixes scrolling issue in #1864.

#1257 still isn't 100% fixed: there are at least two cases where getFocusedEditor()
lags behind the focusedEditorChanged event: opening an inline editor; and
moving focus from open inline editor to its host editor. These same cases -
and a number of others - were broken before this change, however.
@peterflynn
Copy link
Member Author

I've added detailed notes in #1257 about the two known cases that this patch didn't fix.

@peterflynn
Copy link
Member Author

@jasonsanjose, @gruehle: I wouldn't mind a double review on this one if you're both up for giving it a once-over :-)

I've run unit tests and gone through a gauntlet of different cases, verifying that the status bar appears correct, editors get disposed properly, focusedEditorChange is fired a sane number of times & with the right arguments, etc. But with something core like this, the more testing the better too!

@@ -9,6 +9,7 @@ define(function (require, exports, module) {

var AppInit = require("utils/AppInit"),
StatusBarHTML = require("text!widgets/StatusBar.html"),
EditorManager = require("editor/EditorManager"),
Copy link
Member

Choose a reason for hiding this comment

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

The circular dependency should be ok but I thought I'd mention it in case you had any concerns.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we could address this later by refactoring the statusbar updating code out of EditorManager.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I think you're right that it's safe for now: EditorManager doesn't reference StatusBar unit APP_READY, and StatusBar doesn't reference EditorManager until someone calls show()/hide().

But ideally yeah, I'd like to fix #1869 so that EditorManager no longer has any references to StatusBar.

@ghost ghost assigned jasonsanjose Oct 18, 2012
}

$(exports).triggerHandler("focusedEditorChange", [current, previous]);
_lastFocusedEditor = current;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this happen after triggerHandler? Looks like we're firing the event passing the same editor as the current and previous arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yikes, very good point! Looks like there might even conceivably be edge cases where this could cause bugs in status bar updating. Will fix.

@jasonsanjose
Copy link
Member

Initial review complete. Thanks for helping out with this one.

@gruehle
Copy link
Member

gruehle commented Oct 18, 2012

In this comment for #1257, you mention changing getFocusedEditor() to simply return _lastFocusedEditor. Did you try that? It seems like that may be a good solution to the timing discrepancies.

@gruehle
Copy link
Member

gruehle commented Oct 18, 2012

I did some scenario testing with this branch and everything works great.

@peterflynn
Copy link
Member Author

Re making getFocusedEditor() return _lastFocusedEditor: I'd like to look at its callers first to verify that no one is expecting null whenever something other than an Editor is focused. We could try to hack it to return null in those cases to preserve the old behavior, but it'd be more useful if we changed its behavior to only return null when there's no editor open. That would actually help us solve some of our focus management problems (e.g. #301, #547). I'd rather wait till next sprint so we can take our time on that.

@jasonsanjose
Copy link
Member

Looks good. Did some scenario testing with the working set, project tree and inline editors.

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.

None yet

3 participants