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

Click to copy/exec shell code in markdown preview #234981

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yelirekim
Copy link

Requested in #209876

Introduces a CodeBlockManager class that wraps every code block with a container and overlays either one or two buttons:

  • A copy button that copies the code to the clipboard
  • An execute button that executes the code in the active terminal, or creates a new terminal if none is active

The execute button is only shown if the markdown file is in the workspace that the preview is running in, and if workspace.isTrusted.

Minimal changes to dependencies and esbuild-preview.js were introduced to support Codicons in the preview web view.

Testing:

Made a markdown file with a few code blocks of various sizes and an image. Opened this markdown file from within both trusted and untrusted workspaces. Ensured that all of the following worked as expected in both cases:

  • Vertical scrolling synchronization
  • Active line indicators
  • Image rendering
  • Presence or absence of the "Run in Terminal" button
  • Running code in the terminal
  • Copying text
  • Horizontal scrolling of code blocks that overflow, ensuring that the copy/exec buttons stay visible
  • Resizing the markdown window

30 Second Loom Demo:

Markdown Preview Run in Terminal Buttons - 2 December 2024

@yelirekim
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Terminal parts lgtm

@Tyriar Tyriar assigned mjbvz and unassigned Tyriar Dec 2, 2024
@yelirekim yelirekim force-pushed the markdown-run-shell-code-in-terminal branch from 9610923 to 6cee380 Compare December 12, 2024 22:02
@yelirekim
Copy link
Author

Rebased/retested today after the latest release.

@yelirekim
Copy link
Author

@mjbvz can I get some attention here? Anything I can do to make this easier to review?

I had thought about separating out just the "copy" part and getting that through review first in order to segment discussion of any security concerns from the UI addition, would that help?

@yelirekim yelirekim force-pushed the markdown-run-shell-code-in-terminal branch from 6cee380 to 3b45308 Compare January 13, 2025 18:43
@yelirekim
Copy link
Author

rebased/retested

Introduces a `CodeBlockManager` class that wraps every code block with a container and overlays either one or two buttons:

- A copy button that copies the code to the clipboard
- An execute button that executes the code in the active terminal, or creates a new terminal if none is active

The execute button is only shown if the markdown file is in the workspace that the preview is running in, and if the user trusts that workspace.

Minimal changes to dependencies and `esbuild-preview.js` were introduced to support Codicons in the preview web view.
@yelirekim yelirekim force-pushed the markdown-run-shell-code-in-terminal branch from 3b45308 to 9855e95 Compare January 23, 2025 05:33
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.

3 participants