diff --git a/gui/src/components/markdown/CodeBlockToolbar.tsx b/gui/src/components/markdown/CodeBlockToolbar.tsx index 64b06ff47..0dd1fa4c2 100644 --- a/gui/src/components/markdown/CodeBlockToolbar.tsx +++ b/gui/src/components/markdown/CodeBlockToolbar.tsx @@ -3,6 +3,7 @@ import { useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, vscEditorBackground } from ".."; import { isJetBrains, postToIde } from "../../util/ide"; +import { WebviewIde } from "../../util/webviewIde"; import HeaderButtonWithText from "../HeaderButtonWithText"; import { CopyButton } from "./CopyButton"; @@ -18,10 +19,12 @@ const TopDiv = styled.div` const SecondDiv = styled.div<{ bottom: boolean }>` position: absolute; - ${(props) => (props.bottom ? "bottom: 5px;" : "top: -10px;")} - right: 4px; + ${(props) => (props.bottom ? "bottom: 3px;" : "top: -11px;")} + right: 10px; display: flex; + padding: 1px 2px; gap: 4px; + border: 0.5px solid #8888; border-radius: ${defaultBorderRadius}; background-color: ${vscEditorBackground}; `; @@ -29,8 +32,11 @@ const SecondDiv = styled.div<{ bottom: boolean }>` interface CodeBlockToolBarProps { text: string; bottom: boolean; + language: string | undefined; } +const terminalLanguages = ["bash", "sh"]; + function CodeBlockToolBar(props: CodeBlockToolBarProps) { const [copied, setCopied] = useState(false); const [applying, setApplying] = useState(false); @@ -40,10 +46,24 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { {isJetBrains() || ( { + if (terminalLanguages.includes(props.language)) { + let text = props.text; + if (text.startsWith("$ ")) { + text = text.slice(2); + } + new WebviewIde().runCommand(text); + } + if (applying) return; postToIde("applyToCurrentFile", { text: props.text }); setApplying(true); diff --git a/gui/src/components/markdown/PreWithToolbar.tsx b/gui/src/components/markdown/PreWithToolbar.tsx index 08be4c643..a5df415f1 100644 --- a/gui/src/components/markdown/PreWithToolbar.tsx +++ b/gui/src/components/markdown/PreWithToolbar.tsx @@ -19,9 +19,12 @@ function childrenToText(children: any) { return children.map((child: any) => childToText(child)).join(""); } -function PreWithToolbar(props: { children: any }) { - const uiConfig = useUIConfig() - const toolbarBottom = uiConfig?.codeBlockToolbarPosition == 'bottom'; +function PreWithToolbar(props: { + children: any; + language: string | undefined; +}) { + const uiConfig = useUIConfig(); + const toolbarBottom = uiConfig?.codeBlockToolbarPosition == "bottom"; const [hovering, setHovering] = useState(false); @@ -46,9 +49,21 @@ function PreWithToolbar(props: { children: any }) { onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)} > - {!toolbarBottom && hovering && } + {!toolbarBottom && hovering && ( + + )} {props.children} - {toolbarBottom && hovering && } + {toolbarBottom && hovering && ( + + )} ); } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index dea1c331a..de2c3c4ae 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -110,7 +110,7 @@ const FadeInWords: React.FC = (props: any) => { }; const StyledMarkdownPreview = memo(function StyledMarkdownPreview( - props: StyledMarkdownPreviewProps + props: StyledMarkdownPreviewProps, ) { const [reactContent, setMarkdownSource] = useRemark({ // remarkPlugins: [remarkMath], @@ -139,8 +139,12 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( ); }, pre: ({ node, ...preProps }) => { + const language = preProps?.children?.[0]?.props?.className + ?.split(" ") + .find((word) => word.startsWith("language-")) + ?.split("-")[1]; return props.showCodeBorder ? ( - + ) : (