Skip to content

Commit 6a4dab0

Browse files
authored
Remove language selection and word wrap toggle from CodeBlock (#8208)
1 parent ceb9d2b commit 6a4dab0

File tree

20 files changed

+5
-151
lines changed

20 files changed

+5
-151
lines changed

webview-ui/src/components/common/CodeBlock.tsx

Lines changed: 5 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { memo, useEffect, useRef, useCallback, useState } from "react"
22
import styled from "styled-components"
33
import { useCopyToClipboard } from "@src/utils/clipboard"
4-
import { getHighlighter, isLanguageLoaded, normalizeLanguage, ExtendedLanguage } from "@src/utils/highlighter"
5-
import { bundledLanguages } from "shiki"
4+
import { getHighlighter, isLanguageLoaded, normalizeLanguage } from "@src/utils/highlighter"
65
import type { ShikiTransformer } from "shiki"
76
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
87
import { Fragment, jsx, jsxs } from "react/jsx-runtime"
9-
import { ChevronDown, ChevronUp, WrapText, AlignJustify, Copy, Check } from "lucide-react"
8+
import { ChevronDown, ChevronUp, Copy, Check } from "lucide-react"
109
import { useAppTranslation } from "@src/i18n/TranslationContext"
1110
import { StandardTooltip } from "@/components/ui"
1211

@@ -38,7 +37,6 @@ interface CodeBlockProps {
3837
initialWordWrap?: boolean
3938
collapsedHeight?: number
4039
initialWindowShade?: boolean
41-
onLanguageChange?: (language: string) => void
4240
}
4341

4442
const CodeBlockButton = styled.button`
@@ -167,52 +165,6 @@ export const StyledPre = styled.div<{
167165
}
168166
`
169167

170-
const LanguageSelect = styled.select`
171-
font-size: 12px;
172-
color: var(--vscode-foreground);
173-
opacity: 0.4;
174-
font-family: monospace;
175-
appearance: none;
176-
background: transparent;
177-
border: none;
178-
cursor: pointer;
179-
padding: 4px;
180-
margin: 0;
181-
vertical-align: middle;
182-
height: 24px;
183-
184-
& option {
185-
background: var(--vscode-editor-background);
186-
color: var(--vscode-foreground);
187-
padding: 0;
188-
margin: 0;
189-
}
190-
191-
&::-webkit-scrollbar {
192-
width: 6px;
193-
}
194-
195-
&::-webkit-scrollbar-thumb {
196-
background: var(--vscode-scrollbarSlider-background);
197-
}
198-
199-
&::-webkit-scrollbar-track {
200-
background: var(--vscode-editor-background);
201-
}
202-
203-
&:hover {
204-
opacity: 1;
205-
background: var(--vscode-toolbar-hoverBackground);
206-
border-radius: 3px;
207-
}
208-
209-
&:focus {
210-
opacity: 1;
211-
outline: none;
212-
border-radius: 3px;
213-
}
214-
`
215-
216168
const CodeBlock = memo(
217169
({
218170
source,
@@ -222,12 +174,11 @@ const CodeBlock = memo(
222174
initialWordWrap = true,
223175
initialWindowShade = true,
224176
collapsedHeight,
225-
onLanguageChange,
226177
}: CodeBlockProps) => {
227-
const [wordWrap, setWordWrap] = useState(initialWordWrap)
178+
// Use word wrap from props, default to true
179+
const wordWrap = initialWordWrap
228180
const [windowShade, setWindowShade] = useState(initialWindowShade)
229-
const [currentLanguage, setCurrentLanguage] = useState<ExtendedLanguage>(() => normalizeLanguage(language))
230-
const userChangedLanguageRef = useRef(false)
181+
const currentLanguage = normalizeLanguage(language)
231182
const [highlightedCode, setHighlightedCode] = useState<React.ReactNode>(null)
232183
const [showCollapseButton, setShowCollapseButton] = useState(true)
233184
const codeBlockRef = useRef<HTMLDivElement>(null)
@@ -240,16 +191,6 @@ const CodeBlock = memo(
240191
const collapseTimeout1Ref = useRef<NodeJS.Timeout | null>(null)
241192
const collapseTimeout2Ref = useRef<NodeJS.Timeout | null>(null)
242193

243-
// Update current language when prop changes, but only if user hasn't
244-
// made a selection.
245-
useEffect(() => {
246-
const normalizedLang = normalizeLanguage(language)
247-
248-
if (normalizedLang !== currentLanguage && !userChangedLanguageRef.current) {
249-
setCurrentLanguage(normalizedLang)
250-
}
251-
}, [language, currentLanguage])
252-
253194
// Syntax highlighting with cached Shiki instance and mounted state management
254195
useEffect(() => {
255196
// Set mounted state at the beginning of this effect
@@ -707,48 +648,6 @@ const CodeBlock = memo(
707648
ref={copyButtonWrapperRef}
708649
onMouseOver={() => updateCodeBlockButtonPosition()}
709650
style={{ gap: 0 }}>
710-
<LanguageSelect
711-
value={currentLanguage}
712-
style={{
713-
width: `calc(${currentLanguage?.length || 0}ch + 9px)`,
714-
}}
715-
onClick={(e) => {
716-
e.currentTarget.focus()
717-
}}
718-
onChange={(e) => {
719-
const newLang = normalizeLanguage(e.target.value)
720-
userChangedLanguageRef.current = true
721-
setCurrentLanguage(newLang)
722-
if (onLanguageChange) {
723-
onLanguageChange(newLang)
724-
}
725-
}}>
726-
<option
727-
value={normalizeLanguage(language)}
728-
style={{ fontWeight: "bold", textAlign: "left", fontSize: "1.2em" }}>
729-
{normalizeLanguage(language)}
730-
</option>
731-
{
732-
// Display all available languages in alphabetical order
733-
Object.keys(bundledLanguages)
734-
.sort()
735-
.map((lang) => {
736-
const normalizedLang = normalizeLanguage(lang)
737-
return (
738-
<option
739-
key={normalizedLang}
740-
value={normalizedLang}
741-
style={{
742-
fontWeight: normalizedLang === currentLanguage ? "bold" : "normal",
743-
textAlign: "left",
744-
fontSize: normalizedLang === currentLanguage ? "1.2em" : "inherit",
745-
}}>
746-
{normalizedLang}
747-
</option>
748-
)
749-
})
750-
}
751-
</LanguageSelect>
752651
{showCollapseButton && (
753652
<StandardTooltip
754653
content={t(`chat:codeblock.tooltips.${windowShade ? "expand" : "collapse"}`)}
@@ -787,13 +686,6 @@ const CodeBlock = memo(
787686
</CodeBlockButton>
788687
</StandardTooltip>
789688
)}
790-
<StandardTooltip
791-
content={t(`chat:codeblock.tooltips.${wordWrap ? "disable_wrap" : "enable_wrap"}`)}
792-
side="top">
793-
<CodeBlockButton onClick={() => setWordWrap(!wordWrap)}>
794-
{wordWrap ? <AlignJustify size={16} /> : <WrapText size={16} />}
795-
</CodeBlockButton>
796-
</StandardTooltip>
797689
<StandardTooltip content={t("chat:codeblock.tooltips.copy_code")} side="top">
798690
<CodeBlockButton onClick={handleCopy}>
799691
{showCopyFeedback ? <Check size={16} /> : <Copy size={16} />}

webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ vi.mock("../../../i18n/TranslationContext", () => ({
1313
"chat:codeblock.tooltips.copy_code": "Copy code",
1414
"chat:codeblock.tooltips.expand": "Expand code block",
1515
"chat:codeblock.tooltips.collapse": "Collapse code block",
16-
"chat:codeblock.tooltips.enable_wrap": "Enable word wrap",
17-
"chat:codeblock.tooltips.disable_wrap": "Disable word wrap",
1816
}
1917
return translations[key] || key
2018
},

webview-ui/src/i18n/locales/ca/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@
335335
"tooltips": {
336336
"expand": "Expand code block",
337337
"collapse": "Collapse code block",
338-
"enable_wrap": "Enable word wrap",
339-
"disable_wrap": "Disable word wrap",
340338
"copy_code": "Copy code"
341339
}
342340
},

webview-ui/src/i18n/locales/es/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/hi/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/id/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/it/chat.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)