Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferences - Responsive Scope Changes #7936

Conversation

colin-grant-work
Copy link
Contributor

Signed-off-by: Colin Grant colin.grant@ericsson.com

What it does

Fixes #7887 by limiting the regeneration of the tree to cases when the visibility of elements is affected (search, preference schema change, or scope change from User/Workspace <---> Folder). If tree is not regenerated, only displayed values are changed. If tree is regenerated, a check is made to see whether the formerly selected element is still visible, and if it is, it is scrolled into view.

In reviewing some of the widget code, I've also added a bit of handling for errors that shouldn't occur, but could conceivably occur.

How to test

  1. Open preferences in User scope
  2. Select some element in the ToC
  3. Make a preference change in the visible field.
  4. Change to Workspace scope.
  5. Observe that the value is updated, but that the refresh is nearly instantaneous.
  6. Open a multi-root workspace, open preferences, and select a folder scope.
  7. Do 2-5
  8. Observe that after the scope change, a moment passes and then the tree is scrolled to the appropriate item.
  9. Do the reverse (Workspace -> folder scope) and observe that, if the item is available in folder scope, it is scrolled to. Otherwise, the editor scrolls to top.

Review checklist

Reminder for reviewers

Signed-off-by: Colin Grant <colin.grant@ericsson.com>
@akosyakov akosyakov added the preferences issues related to preferences label Jun 2, 2020
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@colin-grant-work I tested the behavior described from #7887 and it works correctly 👍

One improvement I noticed (possibly in a separate pull-request) is to also handle when switching between an editor and the preferences widget. For example:

  1. open the preferences-widget and scroll down to a preference value (ex: output.maxChannelHistory)
  2. open an editor (ex: readme.md)
  3. navigate back to the preferences-widget
  4. notice how the preferences-widget is reset (does not preserve the location) and is re-rendered back to the top

Copy link
Contributor

@lmcbout lmcbout left a comment

Choose a reason for hiding this comment

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

Works as expected
Thanks @colin-grant-work

@colin-grant-work
Copy link
Contributor Author

@vince-fugnitto, I had hoped that this would do better at addressing the concerns you mention and move towards fixing #7746, but it seems the mechanisms are different. As I understand it (which may well be quite wrong 😄), one of two things is happening: (A) when the user leaves the preferences widget and returns, a signal is being sent that triggers a complete rerender. That should be easy to fix, since it would just mean changing how the widget responds to that particular signal. Alternatively, (B) when the user switches back and forth, the widget is temporarily deactivated, and in order to keep its state on its next activation, it would need to implement the logic to turn it into a stateful widget (which is probably desirable anyway). I think window switching is A, and closing and opening the preferences widget would be B - is that correct?

@vince-fugnitto
Copy link
Member

...it would need to implement the logic to turn it into a stateful widget...

@colin-grant-work as a reference, I have already tracked an issue on improving the statefulness of the preferences-widget (#7746) which will help in restoring the widget upon reloading the application. Implementing the stateful interface for a widget is generally used for reloading purposes since the state is stored and retrieved from the browser's local-storage. In this particular case I'm thinking that the stateful interface will not help as this seems to be a bug when the application is already reloaded and we are switching active widgets. For this reason I believe the preferences-widget might be re-rendering prematurely or is listening to an incorrect event.

The pull-request is however already an improvement and we could tackle this issue separately if you wish.

@colin-grant-work
Copy link
Contributor Author

colin-grant-work commented Jun 2, 2020

So it sounds like the current problem is in what I described as scenario (A), where the widget's state doesn't need to be saved anywhere, it just needs to respond better to incoming events? If that's the case, I think it's worth taking a stab at as part of this PR, because it shouldn't be too much extra to change a listener - I'll give it a try later today.

@vince-fugnitto
Copy link
Member

So it sounds like the current problem is in what I described as scenario (A), where the widget's state doesn't need to be saved anywhere, it just needs to respond better to incoming events? If that's the case, I think it's worth taking a stab at as part of this PR, because it shouldn't be too much extra to change a listener - I'll take a stab at it later today.

Sounds good! :) Please ping me whenever you're ready for a re-review.

@colin-grant-work
Copy link
Contributor Author

@vince-fugnitto , it took me a couple of days to circle back around to this. I've done some looking around, and it seems that the behavior is inconsistent. In the browser, just changing windows doesn't cause a scroll to top, but in Electron it does.

Here's the browser during a show-hide sequence:

browser-hide-show

And here's Electron with the same code:

electron-hide-show

You can see that somewhere between onBeforeShow and onAfterShow, the browser has restored the scroll state, but Electron has not. I'm not really sure why, but I don't think it has to do with the particular methods implemented on these widgets. If you have any suggestions, I'm happy to follow it up, but I think I'm inclined to let it me a matter for another PR.

Apart from the behavior on hide and show, they both show somewhat odd behavior onAfterAttach. In both, doing something that fires onAfterAttach will cause a scroll to top, but without actually triggering a scroll event. I suspect that that behavior has to do with the way the default Widget implementation of onAfterAttach changes scroll behavior:

protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
if (this.scrollOptions) {
(async () => {
const container = await this.getScrollContainer();
container.style.overflow = 'hidden';
this.scrollBar = new PerfectScrollbar(container, this.scrollOptions);
this.disableScrollBarFocus(container);
this.toDisposeOnDetach.push(addEventListener(container, <any>'ps-y-reach-end', () => { this.onScrollYReachEndEmitter.fire(undefined); }));
this.toDisposeOnDetach.push(addEventListener(container, <any>'ps-scroll-up', () => { this.onScrollUpEmitter.fire(undefined); }));
this.toDisposeOnDetach.push(Disposable.create(() => {
if (this.scrollBar) {
this.scrollBar.destroy();
this.scrollBar = undefined;
}
container.style.overflow = 'initial';
}));
})();
}
}

@vince-fugnitto
Copy link
Member

@colin-grant-work thank you for taking the time to debug and investigate what is happening. Based on you findings I think the pull-request should be merged and we can fix the issue mentioned in a separate pr.

If possible, can you open an issue so we can track the buggy behaviour?

@tsmaeder
Copy link
Contributor

@vince-fugnitto what are we waiting for to merge this?

@vince-fugnitto
Copy link
Member

@vince-fugnitto what are we waiting for to merge this?

Thank you for reminding me, I'll merge shortly :)

@vince-fugnitto vince-fugnitto merged commit 79ee2c7 into eclipse-theia:master Jun 23, 2020
@colin-grant-work colin-grant-work deleted the preferences/responsive-scope-change branch April 29, 2021 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preferences issues related to preferences
Projects
None yet
Development

Successfully merging this pull request may close these issues.

preference UI does not preserve selection while switching between scopes
5 participants