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

More flexible "External viewer actions" #3262

Merged
merged 12 commits into from
May 14, 2024
Merged

More flexible "External viewer actions" #3262

merged 12 commits into from
May 14, 2024

Conversation

berekuk
Copy link
Collaborator

@berekuk berekuk commented May 11, 2024

We now pass externalViewerActions to ViewerProvider instead of an editor object, because editor.scrollTo doesn't make sense in some non-playground contexts, e.g. GUCEM.

To avoid boilerplate, there's a useExternalViewerActionsForEditor hook which converts the editor handle to the externalViewerActions.

Also, the viewer behavior regarding these actions is now more flexible and has a better support for imports, thanks to the two new methods: isFocusable and isDefaultSourceId.

Example screenshot from the modified story; the error here comes from the function defined in an import, and the line in imported file is not clickable (for now), but the top-level call location is clickable.
Screenshot 2024-05-11 at 15 00 53

I didn't commit this story to the repo, but I did implemented some basic tests.

@berekuk berekuk requested a review from OAGr as a code owner May 11, 2024 18:03
Copy link

vercel bot commented May 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
squiggle-components ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
squiggle-website ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
1 Ignored Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview May 12, 2024 1:56am

Copy link

changeset-bot bot commented May 11, 2024

🦋 Changeset detected

Latest commit: e145e93

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@quri/squiggle-components Patch
@quri/versioned-squiggle-components Patch
vscode-squiggle Patch
@quri/squiggle-lang Patch
@quri/prettier-plugin-squiggle Patch
@quri/squiggle-textmate-grammar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

type Props = PropsWithChildren<{
partialPlaygroundSettings: PartialPlaygroundSettings;
editor?: CodeEditorHandle;
externalViewerActions?: ExternalViewerActions;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The prop name is intentionally verbose. At first I tried to shorten it to actions or externalActions when it was obvious from context, but it made things less readable and greppable.

}>;

// Configure external actions for the common case of editor actions, e.g. for the playground or `<SquiggleEditor>` component.
export function useExternalViewerActionsForEditor(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to split ViewerProvider into multiple files, but didn't want to complicate the diff for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense

@vercel vercel bot temporarily deployed to Preview – squiggle-components May 12, 2024 01:42 Inactive
@berekuk
Copy link
Collaborator Author

berekuk commented May 12, 2024

show action now select the range in editor instead of just a starting position.

This seems better in most cases, e.g. long dicts that are below the current viewport in editor will scroll into range:
Screenshot 2024-05-11 at 22 42 02

One awkward corner case here is that if the dict or a function is very long, and won't fit in the viewport, Codemirror will scroll to the end of it even if this means that the beginning of the selection won't be in the viewport. This is a consequence of selection "head" (cursor position) being at the end. But this is probably fine.

await waitFor(() => screen.getByText(/simulation/));

expect(screen.getByText(/simulation/)).toHaveTextContent(
/simulation #(\d+) in (\d+)ms/
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, but I'd prefer it if /simulation and /simulation #(\d+) in (\d+)ms/ were pulled out as constants.

@OAGr
Copy link
Contributor

OAGr commented May 14, 2024

This seems very reasonable, let's go with it for now.

@berekuk berekuk merged commit 1eff76c into main May 14, 2024
6 checks passed
@berekuk berekuk deleted the viewer-improvements branch May 14, 2024 18:13
@github-actions github-actions bot mentioned this pull request Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants