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

Copy only commands in command snippets #352

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

ptgott
Copy link
Contributor

@ptgott ptgott commented Jul 28, 2023

Fixes #121

The CodeLine component represents a string within a code snippet that is not a command. This is often an example of a command's output.

However, for code snippets consisting of, say, example YAML, CodeLines represent the value we want a user to copy. This use case enables example values to include Var components, and we'll likely deprecate it once we enable support for Vars in syntax-highlighted code blocks.

Since a CodeLine can show up in both of these use cases, we need to make sure that they are copied when there are no commands in a code snippet and not copied when there are commands. This is because, when there are commands in a snippet, the intention is for a reader to copy only the commands--the output would be what the reader sees when they enter the commands into their terminal.

This change adds branching in the Pre component, which handles the copy/paste logic for Snippet, to copy CodeLines only when there are no CommandLines in the snippet.

@vercel
Copy link

vercel bot commented Jul 28, 2023

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

Name Status Preview Comments Updated (UTC)
docs ❌ Failed (Inspect) Jul 31, 2023 10:31pm

@ptgott
Copy link
Contributor Author

ptgott commented Jul 28, 2023

Reviewer note: This PR is based on top of #348 so yarn test-storybook passes.

avatus
avatus previously approved these changes Jul 31, 2023
@ptgott ptgott changed the base branch from paul.gottschling/2023-07-24-fix-tests to main July 31, 2023 16:24
@ptgott ptgott dismissed avatus’s stale review July 31, 2023 16:24

The base branch was changed.

@ptgott
Copy link
Contributor Author

ptgott commented Jul 31, 2023

@avatus Changing the branch's base to main canceled your approval 🤦 . Would you mind stamping it again? Thanks!

Copy link
Contributor

@avatus avatus left a comment

Choose a reason for hiding this comment

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

You always have my stamp of approval @ptgott <3

Fixes #121

The `CodeLine` component represents a string within a `code` snippet
that is not a command. This is often an example of a command's output.

However, for code snippets consisting of, say, example YAML, `CodeLines`
represent the value we want a user to copy. This use case enables
example values to include `Var` components, and we'll likely deprecate
it once we enable support for `Var`s in syntax-highlighted code blocks.

Since a `CodeLine` can show up in both of these use cases, we need to
make sure that they are copied when there are no commands in a `code`
snippet and _not_ copied when there are commands. This is because, when
there are commands in a snippet, the intention is for a reader to copy
only the commands--the output would be what the reader sees when they
enter the commands into their terminal.

This change adds branching in the `Pre` component, which handles the
copy/paste logic for `Snippet`, to copy `CodeLine`s only when there are
no `CommandLine`s in the snippet.
@ptgott ptgott force-pushed the paul.gottschling/121-code-copy branch from d3b442f to 91115f4 Compare July 31, 2023 22:25
@ptgott ptgott merged commit 25d8562 into main Aug 1, 2023
6 checks passed
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.

Example terminal output copied along with commands in code snippets
2 participants