-
Notifications
You must be signed in to change notification settings - Fork 7.6k
focusedEditorChange does not work as documented #1257
Comments
In addition, EditorManager.getInlineEditors(EditorManager.getCurrentFullEditor()) returns an empty array when opening the first inline editor (when called in the focusedEditorChange handler). |
Reviewed - assigning to Jason |
Nominating sprint 15 |
@DennisKehrig Can you confirm and close? Thanks. |
I was happy to see that...
However, I also saw a couple of issues:
Potentially there are some more edge cases that don't work as I would expect, but I think that's enough for now. |
I've filed #1860 to capture these new bugs. @DennisKehrig let me know if this looks good and go ahead and close this issue. Thanks! |
@jasonsanjose: Thanks for keeping me posted! The second argument (the new editor with focus) of the event is always correct. If that is all we need, the event's documentation in However, a call to
A call to
Calling Sorry! |
* 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.
After pull #1877 I think there are only two cases of this where getFocusedEditor() still lags behind the focusedEditorChange event: opening an inline editor; and moving focus from an inline editor to its host editor. In both cases, the event args give a correct picture of which editors lost/gained focus, so the workaround is for clients of this API just to use those events. Here's an analysis of why those cases are still wrong:
The simplest fix for both cases might be to just have getFocusedEditor() return the value of _lastFocusedEditor directly. (This would move the disconnect: from getFE() disagreeing with focusedEditorChange, to the both of them together disagreeing with Editor.hasFocus() -- which seems like a safer discrepancy). |
@peterflynn: I like your proposed fix. If I needed access to the focused editor consistent with the event, I would store the last reference gotten from the event in some variable and use that instead of getFocusedEditor(). Seems like your suggestion basically amounts to the same thing. |
Moving remainder of this out to Sprint 16. This may dovetail pretty well with the focus management fixes that are coming up on our backlog soon anyway. |
Looking good, very happy about all the changes! Thanks everybody, especially @jasonsanjose! |
@gruehle, we might just be able to call this one closed once your changes land (now that we've decided not to try to "fix" getFocusedEditor(), and we've added a viable alternative API that does track to the event 100% reliably). |
Marking fixed. The getActiveEditor() function tracks the event reliably. (plus, there are the arguments to the event, which are also correct). |
FBNC to @DennisKehrig |
This won't be regressed before the end of the sprint, so I'm going to consider this an exception. @DennisKehrig, please let us know ASAP if you see a problem with it. Thanks. |
Works perfectly! Outstanding work, guys, thanks a lot! |
Closed |
In EditorManager.js, it says: "focusedEditorChange -- When the focused editor (full or inline) changes and size/visibility are complete"
In the same file, function createInlineEditorForDocument is documented as "Creates a new inline Editor instance for the given Document. [...] The editor is not yet visible or attached to a host editor." Yet, this function triggers the focusedEditorChange event.
Consequently, if a handler then calls getFocusedEditor() it will get the editor that is about to lose focus, not the one that just got focus. Since the focusedEditorChange event does not pass along the editor it replaces, this behavior could be relied upon to determine which editor previously had focus. But depending on which part of the documentation is correct, this behavior could change.
Also, an event handler for focusedEditorChange might call a function that is otherwise independent of the event and therefore needs to call getFocusedEditor(). It would then not get the editor that now has focus.
In my opinion focusedEditorChange should only be triggered when the new editor is visible and actually has the focus - as documented. getFocusedEditor() would then return the same editor as passed on by the event.
In addition, I would pass the previously focused editor to the handler function as well.
The text was updated successfully, but these errors were encountered: