diff --git a/webview-ui/src/components/common/CodeBlock.tsx b/webview-ui/src/components/common/CodeBlock.tsx index b9621381ef1..b13a6ec24d8 100644 --- a/webview-ui/src/components/common/CodeBlock.tsx +++ b/webview-ui/src/components/common/CodeBlock.tsx @@ -1,12 +1,11 @@ import { memo, useEffect, useRef, useCallback, useState } from "react" import styled from "styled-components" import { useCopyToClipboard } from "@src/utils/clipboard" -import { getHighlighter, isLanguageLoaded, normalizeLanguage, ExtendedLanguage } from "@src/utils/highlighter" -import { bundledLanguages } from "shiki" +import { getHighlighter, isLanguageLoaded, normalizeLanguage } from "@src/utils/highlighter" import type { ShikiTransformer } from "shiki" import { toJsxRuntime } from "hast-util-to-jsx-runtime" import { Fragment, jsx, jsxs } from "react/jsx-runtime" -import { ChevronDown, ChevronUp, WrapText, AlignJustify, Copy, Check } from "lucide-react" +import { ChevronDown, ChevronUp, Copy, Check } from "lucide-react" import { useAppTranslation } from "@src/i18n/TranslationContext" import { StandardTooltip } from "@/components/ui" @@ -38,7 +37,6 @@ interface CodeBlockProps { initialWordWrap?: boolean collapsedHeight?: number initialWindowShade?: boolean - onLanguageChange?: (language: string) => void } const CodeBlockButton = styled.button` @@ -167,52 +165,6 @@ export const StyledPre = styled.div<{ } ` -const LanguageSelect = styled.select` - font-size: 12px; - color: var(--vscode-foreground); - opacity: 0.4; - font-family: monospace; - appearance: none; - background: transparent; - border: none; - cursor: pointer; - padding: 4px; - margin: 0; - vertical-align: middle; - height: 24px; - - & option { - background: var(--vscode-editor-background); - color: var(--vscode-foreground); - padding: 0; - margin: 0; - } - - &::-webkit-scrollbar { - width: 6px; - } - - &::-webkit-scrollbar-thumb { - background: var(--vscode-scrollbarSlider-background); - } - - &::-webkit-scrollbar-track { - background: var(--vscode-editor-background); - } - - &:hover { - opacity: 1; - background: var(--vscode-toolbar-hoverBackground); - border-radius: 3px; - } - - &:focus { - opacity: 1; - outline: none; - border-radius: 3px; - } -` - const CodeBlock = memo( ({ source, @@ -222,12 +174,11 @@ const CodeBlock = memo( initialWordWrap = true, initialWindowShade = true, collapsedHeight, - onLanguageChange, }: CodeBlockProps) => { - const [wordWrap, setWordWrap] = useState(initialWordWrap) + // Use word wrap from props, default to true + const wordWrap = initialWordWrap const [windowShade, setWindowShade] = useState(initialWindowShade) - const [currentLanguage, setCurrentLanguage] = useState(() => normalizeLanguage(language)) - const userChangedLanguageRef = useRef(false) + const currentLanguage = normalizeLanguage(language) const [highlightedCode, setHighlightedCode] = useState(null) const [showCollapseButton, setShowCollapseButton] = useState(true) const codeBlockRef = useRef(null) @@ -240,16 +191,6 @@ const CodeBlock = memo( const collapseTimeout1Ref = useRef(null) const collapseTimeout2Ref = useRef(null) - // Update current language when prop changes, but only if user hasn't - // made a selection. - useEffect(() => { - const normalizedLang = normalizeLanguage(language) - - if (normalizedLang !== currentLanguage && !userChangedLanguageRef.current) { - setCurrentLanguage(normalizedLang) - } - }, [language, currentLanguage]) - // Syntax highlighting with cached Shiki instance and mounted state management useEffect(() => { // Set mounted state at the beginning of this effect @@ -707,48 +648,6 @@ const CodeBlock = memo( ref={copyButtonWrapperRef} onMouseOver={() => updateCodeBlockButtonPosition()} style={{ gap: 0 }}> - { - e.currentTarget.focus() - }} - onChange={(e) => { - const newLang = normalizeLanguage(e.target.value) - userChangedLanguageRef.current = true - setCurrentLanguage(newLang) - if (onLanguageChange) { - onLanguageChange(newLang) - } - }}> - - { - // Display all available languages in alphabetical order - Object.keys(bundledLanguages) - .sort() - .map((lang) => { - const normalizedLang = normalizeLanguage(lang) - return ( - - ) - }) - } - {showCollapseButton && ( )} - - setWordWrap(!wordWrap)}> - {wordWrap ? : } - - {showCopyFeedback ? : } diff --git a/webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx b/webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx index f413745b617..2a9a8ff12af 100644 --- a/webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx +++ b/webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx @@ -13,8 +13,6 @@ vi.mock("../../../i18n/TranslationContext", () => ({ "chat:codeblock.tooltips.copy_code": "Copy code", "chat:codeblock.tooltips.expand": "Expand code block", "chat:codeblock.tooltips.collapse": "Collapse code block", - "chat:codeblock.tooltips.enable_wrap": "Enable word wrap", - "chat:codeblock.tooltips.disable_wrap": "Disable word wrap", } return translations[key] || key }, diff --git a/webview-ui/src/i18n/locales/ca/chat.json b/webview-ui/src/i18n/locales/ca/chat.json index 50da3fe503c..338b10232fd 100644 --- a/webview-ui/src/i18n/locales/ca/chat.json +++ b/webview-ui/src/i18n/locales/ca/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Expandir bloc de codi", "collapse": "Contraure bloc de codi", - "enable_wrap": "Activar ajustament de línia", - "disable_wrap": "Desactivar ajustament de línia", "copy_code": "Copiar codi" } }, diff --git a/webview-ui/src/i18n/locales/de/chat.json b/webview-ui/src/i18n/locales/de/chat.json index 76d29209bb7..76356ce9f9e 100644 --- a/webview-ui/src/i18n/locales/de/chat.json +++ b/webview-ui/src/i18n/locales/de/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Code-Block erweitern", "collapse": "Code-Block reduzieren", - "enable_wrap": "Zeilenumbruch aktivieren", - "disable_wrap": "Zeilenumbruch deaktivieren", "copy_code": "Code kopieren" } }, diff --git a/webview-ui/src/i18n/locales/en/chat.json b/webview-ui/src/i18n/locales/en/chat.json index aad4e961871..99464dfb607 100644 --- a/webview-ui/src/i18n/locales/en/chat.json +++ b/webview-ui/src/i18n/locales/en/chat.json @@ -335,8 +335,6 @@ "tooltips": { "expand": "Expand code block", "collapse": "Collapse code block", - "enable_wrap": "Enable word wrap", - "disable_wrap": "Disable word wrap", "copy_code": "Copy code" } }, diff --git a/webview-ui/src/i18n/locales/es/chat.json b/webview-ui/src/i18n/locales/es/chat.json index c3a73e63377..785dcfe7d9e 100644 --- a/webview-ui/src/i18n/locales/es/chat.json +++ b/webview-ui/src/i18n/locales/es/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Expandir bloque de código", "collapse": "Contraer bloque de código", - "enable_wrap": "Activar ajuste de línea", - "disable_wrap": "Desactivar ajuste de línea", "copy_code": "Copiar código" } }, diff --git a/webview-ui/src/i18n/locales/fr/chat.json b/webview-ui/src/i18n/locales/fr/chat.json index 33d6178a681..f04ee15b0c4 100644 --- a/webview-ui/src/i18n/locales/fr/chat.json +++ b/webview-ui/src/i18n/locales/fr/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Développer le bloc de code", "collapse": "Réduire le bloc de code", - "enable_wrap": "Activer le retour à la ligne", - "disable_wrap": "Désactiver le retour à la ligne", "copy_code": "Copier le code" } }, diff --git a/webview-ui/src/i18n/locales/hi/chat.json b/webview-ui/src/i18n/locales/hi/chat.json index c7d5e5d37ff..c0c9a9c9a69 100644 --- a/webview-ui/src/i18n/locales/hi/chat.json +++ b/webview-ui/src/i18n/locales/hi/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "कोड ब्लॉक का विस्तार करें", "collapse": "कोड ब्लॉक को संकुचित करें", - "enable_wrap": "वर्ड रैप सक्षम करें", - "disable_wrap": "वर्ड रैप अक्षम करें", "copy_code": "कोड कॉपी करें" } }, diff --git a/webview-ui/src/i18n/locales/id/chat.json b/webview-ui/src/i18n/locales/id/chat.json index e1c2130073b..a400767e1b8 100644 --- a/webview-ui/src/i18n/locales/id/chat.json +++ b/webview-ui/src/i18n/locales/id/chat.json @@ -338,8 +338,6 @@ "tooltips": { "expand": "Perluas blok kode", "collapse": "Tutup blok kode", - "enable_wrap": "Aktifkan word wrap", - "disable_wrap": "Nonaktifkan word wrap", "copy_code": "Salin kode" } }, diff --git a/webview-ui/src/i18n/locales/it/chat.json b/webview-ui/src/i18n/locales/it/chat.json index ecb9c8706ac..2d4a9a57d1c 100644 --- a/webview-ui/src/i18n/locales/it/chat.json +++ b/webview-ui/src/i18n/locales/it/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Espandi blocco di codice", "collapse": "Comprimi blocco di codice", - "enable_wrap": "Attiva a capo automatico", - "disable_wrap": "Disattiva a capo automatico", "copy_code": "Copia codice" } }, diff --git a/webview-ui/src/i18n/locales/ja/chat.json b/webview-ui/src/i18n/locales/ja/chat.json index 1a4666f6d56..6e81074ebd4 100644 --- a/webview-ui/src/i18n/locales/ja/chat.json +++ b/webview-ui/src/i18n/locales/ja/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "コードブロックを展開", "collapse": "コードブロックを折りたたむ", - "enable_wrap": "折り返しを有効化", - "disable_wrap": "折り返しを無効化", "copy_code": "コードをコピー" } }, diff --git a/webview-ui/src/i18n/locales/ko/chat.json b/webview-ui/src/i18n/locales/ko/chat.json index 9d54aaee111..4c4d83cfe85 100644 --- a/webview-ui/src/i18n/locales/ko/chat.json +++ b/webview-ui/src/i18n/locales/ko/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "코드 블록 확장", "collapse": "코드 블록 축소", - "enable_wrap": "자동 줄바꿈 활성화", - "disable_wrap": "자동 줄바꿈 비활성화", "copy_code": "코드 복사" } }, diff --git a/webview-ui/src/i18n/locales/nl/chat.json b/webview-ui/src/i18n/locales/nl/chat.json index 5bfa8b3def0..c927481e9ea 100644 --- a/webview-ui/src/i18n/locales/nl/chat.json +++ b/webview-ui/src/i18n/locales/nl/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Codeblok uitvouwen", "collapse": "Codeblok samenvouwen", - "enable_wrap": "Regelafbreking inschakelen", - "disable_wrap": "Regelafbreking uitschakelen", "copy_code": "Code kopiëren" } }, diff --git a/webview-ui/src/i18n/locales/pl/chat.json b/webview-ui/src/i18n/locales/pl/chat.json index a9099cb5353..eabe46a7144 100644 --- a/webview-ui/src/i18n/locales/pl/chat.json +++ b/webview-ui/src/i18n/locales/pl/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Rozwiń blok kodu", "collapse": "Zwiń blok kodu", - "enable_wrap": "Włącz zawijanie wierszy", - "disable_wrap": "Wyłącz zawijanie wierszy", "copy_code": "Kopiuj kod" } }, diff --git a/webview-ui/src/i18n/locales/pt-BR/chat.json b/webview-ui/src/i18n/locales/pt-BR/chat.json index 19baec98bd0..1f75abf9290 100644 --- a/webview-ui/src/i18n/locales/pt-BR/chat.json +++ b/webview-ui/src/i18n/locales/pt-BR/chat.json @@ -317,8 +317,6 @@ "tooltips": { "expand": "Expandir bloco de código", "collapse": "Recolher bloco de código", - "enable_wrap": "Ativar quebra de linha", - "disable_wrap": "Desativar quebra de linha", "copy_code": "Copiar código" } }, diff --git a/webview-ui/src/i18n/locales/ru/chat.json b/webview-ui/src/i18n/locales/ru/chat.json index b6475b5034a..55bfa65e0b0 100644 --- a/webview-ui/src/i18n/locales/ru/chat.json +++ b/webview-ui/src/i18n/locales/ru/chat.json @@ -318,8 +318,6 @@ "tooltips": { "expand": "Развернуть блок кода", "collapse": "Свернуть блок кода", - "enable_wrap": "Включить перенос строк", - "disable_wrap": "Отключить перенос строк", "copy_code": "Копировать код" } }, diff --git a/webview-ui/src/i18n/locales/tr/chat.json b/webview-ui/src/i18n/locales/tr/chat.json index 69f8bc042da..f5ce61b98f5 100644 --- a/webview-ui/src/i18n/locales/tr/chat.json +++ b/webview-ui/src/i18n/locales/tr/chat.json @@ -318,8 +318,6 @@ "tooltips": { "expand": "Kod bloğunu genişlet", "collapse": "Kod bloğunu daralt", - "enable_wrap": "Satır kaydırmayı etkinleştir", - "disable_wrap": "Satır kaydırmayı devre dışı bırak", "copy_code": "Kodu kopyala" } }, diff --git a/webview-ui/src/i18n/locales/vi/chat.json b/webview-ui/src/i18n/locales/vi/chat.json index 3acd6a4e46b..27e836c7b4a 100644 --- a/webview-ui/src/i18n/locales/vi/chat.json +++ b/webview-ui/src/i18n/locales/vi/chat.json @@ -318,8 +318,6 @@ "tooltips": { "expand": "Mở rộng khối mã", "collapse": "Thu gọn khối mã", - "enable_wrap": "Bật tự động xuống dòng", - "disable_wrap": "Tắt tự động xuống dòng", "copy_code": "Sao chép mã" } }, diff --git a/webview-ui/src/i18n/locales/zh-CN/chat.json b/webview-ui/src/i18n/locales/zh-CN/chat.json index bfc99972334..ad3df7d0be0 100644 --- a/webview-ui/src/i18n/locales/zh-CN/chat.json +++ b/webview-ui/src/i18n/locales/zh-CN/chat.json @@ -318,8 +318,6 @@ "tooltips": { "expand": "展开代码块", "collapse": "收起代码块", - "enable_wrap": "启用自动换行", - "disable_wrap": "禁用自动换行", "copy_code": "复制代码" } }, diff --git a/webview-ui/src/i18n/locales/zh-TW/chat.json b/webview-ui/src/i18n/locales/zh-TW/chat.json index 9a862a545ea..e5ed5815384 100644 --- a/webview-ui/src/i18n/locales/zh-TW/chat.json +++ b/webview-ui/src/i18n/locales/zh-TW/chat.json @@ -336,8 +336,6 @@ "tooltips": { "expand": "展開程式碼區塊", "collapse": "摺疊程式碼區塊", - "enable_wrap": "啟用自動換行", - "disable_wrap": "停用自動換行", "copy_code": "複製程式碼" } },