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

Allow saving Monaco viewstates so they can be restored on re-open. #42

Merged
merged 9 commits into from
Mar 26, 2023

Conversation

EddieAbbondanzio
Copy link
Owner

  • deepUpdate now handles objects with circular references pointing to parents, and also can ignore specific paths.
  • Introduced new cache in the front end store that lets us save data without triggering re-renders.
  • Reduced number of times we call setModel() on Monaco to improve performance.
  • Moved Monaco model and view states to live in the store instead of in the Editor component.
  • View states are saved to file so on the next load we can restore an editor to exactly how the user left it.

Comment on lines +86 to +90
if (appStateFile == null) {
return;
}

await appStateFile.update(appState);
Copy link
Owner Author

Choose a reason for hiding this comment

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

No logic changed here. Just doing some cleanup.

Comment on lines +48 to +58
useEffect(() => {
store.on("editor.boldSelectedText", boldSelectedText);
store.on("editor.italicSelectedText", italicSelectedText);
store.on("editor.setModelViewState", setModelViewState);

return () => {
store.off("editor.boldSelectedText", boldSelectedText);
store.off("editor.italicSelectedText", italicSelectedText);
store.off("editor.setModelViewState", setModelViewState);
};
}, [store]);
Copy link
Owner Author

Choose a reason for hiding this comment

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

This breaks our pattern of subscribing to events at the bottom of the component but I'm not sure of a better way forward.

Depending on the situation we may trigger setModelViewState on the first render so if we set up the listener at the bottom of the component the store throws an error due to not finding the listener.

Maybe we just leave as-is for now? I don't think it's worth changing the pattern yet.

Comment on lines +148 to +157
// dragenter and dragover have to be cancelled in order for the drop event
// to work on a div.
const dragEnter = (ev: DragEvent) => {
ev.stopPropagation();
ev.preventDefault();
};
const dragOver = (ev: DragEvent) => {
ev.stopPropagation();
ev.preventDefault();
};
Copy link
Owner Author

Choose a reason for hiding this comment

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

These were pulled into the useEffect hook to avoid regenerating them each render.

@EddieAbbondanzio EddieAbbondanzio merged commit 143a0c7 into master Mar 26, 2023
@EddieAbbondanzio EddieAbbondanzio deleted the pull-monaco-model-cache-to-store branch March 26, 2023 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant