-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix Live Preview for Docs not in Working Set #8605
Conversation
@redmunds can you try this with the jeff/splitview-1x2 branch to get an idea if anything will break? I have a feeling that some of the functionality is not going to work. |
Ooops. I meant to remove that line about having the feeling that it not working. I reviewed the code at a cursory level and it look like it shouldn't be a problem with splitivew but you wanna give it a try? |
@JeffryBooher Good point -- using the jeff/splitview-1x2 branch, there are new scenarios that are not possible in master. When both the HTML and CSS files are open in different views, and the HTML doc is not in the "Working Set" (or whatever new terminology is). The bug doesn't happen when focus switches to the CSS doc such that the HTML doc is still displayed in the other view because both the Editor and Document objects are maintained for the HTML doc until it gets focus back. But, when documents and focus changes are arranged such that the HTML doc is no longer displayed in either view, and it is then reselected, then the issue remains. |
@redmunds I think in the splitview case you need to listen to the new editor event |
var self = this; | ||
this.editor = editor; | ||
|
||
if (this.editor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this check from all the the ctor to here because it seemed safer to always do it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you still don't need it. attachEditor
is only called when it has an editor and the docs for the ctor say that the editor argument is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
done with review |
I see the |
Pushed changes. Ready for another review. |
ah, right |
self._onChange(event, editor, change); | ||
}); | ||
|
||
// Experimental code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is still experimental since it's been in there and working for quite some time now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is still experimental code. The LiveDevelopment experimental highlighting is different from Live Preview Highlighting -- I think that's the code that allows you to click in browser and highlight in brackets.
With that said, all of the LiveDevelopment experimental code is so old that it probably no longer works and should be ripped out.
Done with review. Just a few final cleanup items to consider and this is ready to merge. |
Ready for another review. |
LGTM. Merging. |
Fix Live Preview for Docs not in Working Set
The simple recipe in #7886 uncovers a big design flaw in live preview where docs not in the working set don't work. I suspect that many reported problems and open issues are related to this subtle difference.
The issue is that live preview caches HTMLDocument objects, but the Document and Editor objects that it references are only maintained when doc is in the working set. When doc is not in the working set, a new Document and Editor object is created every time it is selected in project tree.
This PR makes 2 changes:
this.doc
Document so it persists while Live Preview is connected.activeEditorChange
event to handle Editor changes. This includes proper updating of event listeners and HTMLInstrumentation.