mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-07-02 10:33:00 +08:00
* fix(shell): hide prompt options on desktop * fix(chat): group continuous same-tool runs more consistently Consecutive tool calls (Edit, Read, Grep, etc.) grouped inconsistently: - The group threshold was 3, so a run of only 2 calls stayed ungrouped while a run of 3 collapsed — making two back-to-back edits look different from three. - A run was broken by any interleaved message, including ones that render nothing (reasoning hidden when showThinking is off). Providers like Codex interleave hidden reasoning between tool calls, so visually continuous edits intermittently failed to group. Lower TOOL_GROUP_THRESHOLD to 2 and skip non-rendered messages when extending a run, so any 2+ consecutive same-tool calls collapse reliably. ChatMessagesPane now passes showThinking into groupConsecutiveTools. * fix(chat): stabilize message scroll controls * fix: update command menu positioning * fix(chat): refine load all overlay behavior * fix(chat): hide load all prompt after final page * fix(chat): remove auto scroll quick setting * fix(chat): unify messages and composer into centered column Constrain both ChatMessagesPane content and ChatComposer to the same max-w-3xl centered column. Previously only the composer had a max-width, causing messages to fill the full width while the input stayed narrow, making them visually misaligned with large empty gutters on either side. * style(ui): rework light/dark theme to make it visually consistent Rework the color system around warm neutrals and route hardcoded surfaces through theme tokens for consistency. - Theme tokens (index.css, ThemeContext): warm cream light mode and neutral charcoal dark mode, replacing the pure-white/blue-tinted palette; update PWA theme-color meta - Code blocks: soft grey background in light mode via oneLight/oneDark, and drop the Tailwind Typography <pre> shell that framed the highlighter in a dark box - Dropdowns/panels: convert CommandMenu, Quick Settings, and the JSON response block from hardcoded gray/slate to popover/muted/border tokens - Git panel: Publish button purple -> primary blue - Composer: drop top padding so the input sits flush with the thread * fix: use app theme for code editor * style(chat): unify composer toolbar heights and declutter slash-command modal - Composer: give the permission-mode and token-usage buttons a fixed h-8 so every bottom-toolbar control shares one height - CommandResultModal: replace the blue gradient header (gradient fill, glow blobs, blue eyebrow + icon chip) with a clean neutral header on popover/muted tokens * fix(chat): header ellipsis, Codex logo on light theme, portal copy menu - MainContentTitle: truncate the session title with an ellipsis instead of horizontal-scrolling it - MessageComponent: use text-foreground for the provider logo chip so the currentColor Codex/OpenAI mark is visible on the light theme - MessageCopyControl: render the copy-format dropdown in a portal so it escapes the chat message's `contain: paint` clip box; anchor it to the trigger, flip above near the viewport bottom, close on scroll/resize * style(mcp): remove purple accents and portal the server form modal - Replace the purple provider-button colors, heading icon, and form submit button with the primary token (no purple in the MCP UI) - Portal the add/edit MCP server modal to document.body so its fixed overlay covers the full viewport, fixing the white band at the top caused by the Settings dialog's transformed tab content becoming the containing block * style(ui): use Merriweather serif for chat text and Encode Sans for the rest of the UI * fix: align activity indicator with composer input width Wrap ActivityIndicator in the same mx-auto max-w-3xl container as the text input so the "Analyzing…" label and Stop button stay within the input's boundaries instead of spanning the full window width. * style: improve thinking and stop button placements * style(auth): modernize login, setup, and onboarding screens * fix(chat): correct invalid dark-mode hover on AskUserQuestion options * fix: remove unnecessary auto expand tools * fix: resolve coderabbit comments * fix(chat): widen chat layout and sidebar titles * fix(branding): update CloudCLI wordmark styling --------- Co-authored-by: Simos Mikelatos <simosmik@gmail.com>
312 lines
10 KiB
TypeScript
312 lines
10 KiB
TypeScript
import { EditorView } from '@codemirror/view';
|
|
import { unifiedMergeView } from '@codemirror/merge';
|
|
import type { Extension } from '@codemirror/state';
|
|
import { useCallback, useMemo, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
|
|
import { useTheme } from '../../../contexts/ThemeContext';
|
|
import { useCodeEditorDocument } from '../hooks/useCodeEditorDocument';
|
|
import { useCodeEditorSettings } from '../hooks/useCodeEditorSettings';
|
|
import { useEditorKeyboardShortcuts } from '../hooks/useEditorKeyboardShortcuts';
|
|
import type { CodeEditorFile } from '../types/types';
|
|
import { createMinimapExtension, createScrollToFirstChunkExtension, getLanguageExtensions } from '../utils/editorExtensions';
|
|
import { getEditorStyles } from '../utils/editorStyles';
|
|
import { createEditorToolbarPanelExtension } from '../utils/editorToolbarPanel';
|
|
|
|
import CodeEditorFooter from './subcomponents/CodeEditorFooter';
|
|
import CodeEditorHeader from './subcomponents/CodeEditorHeader';
|
|
import CodeEditorLoadingState from './subcomponents/CodeEditorLoadingState';
|
|
import CodeEditorSurface from './subcomponents/CodeEditorSurface';
|
|
import CodeEditorBinaryFile from './subcomponents/CodeEditorBinaryFile';
|
|
import CodeEditorMediaPreview from './subcomponents/CodeEditorMediaPreview';
|
|
|
|
type CodeEditorProps = {
|
|
file: CodeEditorFile;
|
|
onClose: () => void;
|
|
projectPath?: string;
|
|
isSidebar?: boolean;
|
|
isExpanded?: boolean;
|
|
onToggleExpand?: (() => void) | null;
|
|
onPopOut?: (() => void) | null;
|
|
};
|
|
|
|
export default function CodeEditor({
|
|
file,
|
|
onClose,
|
|
projectPath,
|
|
isSidebar = false,
|
|
isExpanded = false,
|
|
onToggleExpand = null,
|
|
onPopOut = null,
|
|
}: CodeEditorProps) {
|
|
const { t } = useTranslation('codeEditor');
|
|
const paletteOps = usePaletteOps();
|
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
const [showDiff, setShowDiff] = useState(Boolean(file.diffInfo));
|
|
const [markdownPreview, setMarkdownPreview] = useState(false);
|
|
|
|
// The code editor follows the app-wide theme; it has no theme of its own.
|
|
const { isDarkMode } = useTheme();
|
|
|
|
const {
|
|
wordWrap,
|
|
minimapEnabled,
|
|
showLineNumbers,
|
|
fontSize,
|
|
} = useCodeEditorSettings();
|
|
|
|
const {
|
|
content,
|
|
setContent,
|
|
loading,
|
|
saving,
|
|
saveSuccess,
|
|
saveError,
|
|
isBinary,
|
|
previewKind,
|
|
fileProjectId,
|
|
handleSave,
|
|
handleDownload,
|
|
} = useCodeEditorDocument({
|
|
file,
|
|
projectPath,
|
|
});
|
|
|
|
const isMarkdownFile = useMemo(() => {
|
|
const extension = file.name.split('.').pop()?.toLowerCase();
|
|
return extension === 'md' || extension === 'markdown';
|
|
}, [file.name]);
|
|
|
|
const isHtmlPreviewFile = useMemo(() => {
|
|
const extension = file.name.split('.').pop()?.toLowerCase();
|
|
return extension === 'html' || extension === 'htm';
|
|
}, [file.name]);
|
|
|
|
const openHtmlPreview = useCallback(() => {
|
|
const previewWindow = window.open('', '_blank');
|
|
if (!previewWindow) return;
|
|
|
|
previewWindow.opener = null;
|
|
previewWindow.document.title = file.name;
|
|
previewWindow.document.body.style.margin = '0';
|
|
|
|
const iframe = previewWindow.document.createElement('iframe');
|
|
iframe.title = file.name;
|
|
iframe.sandbox.add('allow-forms', 'allow-modals', 'allow-popups', 'allow-scripts');
|
|
iframe.style.cssText = 'position:fixed;inset:0;width:100%;height:100%;border:0;background:white';
|
|
|
|
iframe.srcdoc = content;
|
|
|
|
previewWindow.document.body.appendChild(iframe);
|
|
}, [content, file.name]);
|
|
|
|
const minimapExtension = useMemo(
|
|
() => (
|
|
createMinimapExtension({
|
|
file,
|
|
showDiff,
|
|
minimapEnabled,
|
|
isDarkMode,
|
|
})
|
|
),
|
|
[file, isDarkMode, minimapEnabled, showDiff],
|
|
);
|
|
|
|
const scrollToFirstChunkExtension = useMemo(
|
|
() => createScrollToFirstChunkExtension({ file, showDiff }),
|
|
[file, showDiff],
|
|
);
|
|
|
|
const toolbarPanelExtension = useMemo(
|
|
() => (
|
|
createEditorToolbarPanelExtension({
|
|
file,
|
|
showDiff,
|
|
isSidebar,
|
|
isExpanded,
|
|
onToggleDiff: () => setShowDiff((previous) => !previous),
|
|
onPopOut,
|
|
onToggleExpand,
|
|
labels: {
|
|
changes: t('toolbar.changes'),
|
|
previousChange: t('toolbar.previousChange'),
|
|
nextChange: t('toolbar.nextChange'),
|
|
hideDiff: t('toolbar.hideDiff'),
|
|
showDiff: t('toolbar.showDiff'),
|
|
collapse: t('toolbar.collapse'),
|
|
expand: t('toolbar.expand'),
|
|
},
|
|
})
|
|
),
|
|
[file, isExpanded, isSidebar, onPopOut, onToggleExpand, showDiff, t],
|
|
);
|
|
|
|
const extensions = useMemo(() => {
|
|
const allExtensions: Extension[] = [
|
|
...getLanguageExtensions(file.name),
|
|
...toolbarPanelExtension,
|
|
];
|
|
|
|
if (file.diffInfo && showDiff && file.diffInfo.old_string !== undefined) {
|
|
allExtensions.push(
|
|
unifiedMergeView({
|
|
original: file.diffInfo.old_string,
|
|
mergeControls: false,
|
|
highlightChanges: true,
|
|
syntaxHighlightDeletions: false,
|
|
gutter: true,
|
|
}),
|
|
);
|
|
allExtensions.push(...minimapExtension);
|
|
allExtensions.push(...scrollToFirstChunkExtension);
|
|
}
|
|
|
|
if (wordWrap) {
|
|
allExtensions.push(EditorView.lineWrapping);
|
|
}
|
|
|
|
return allExtensions;
|
|
}, [
|
|
file.diffInfo,
|
|
file.name,
|
|
minimapExtension,
|
|
scrollToFirstChunkExtension,
|
|
showDiff,
|
|
toolbarPanelExtension,
|
|
wordWrap,
|
|
]);
|
|
|
|
useEditorKeyboardShortcuts({
|
|
onSave: handleSave,
|
|
onClose,
|
|
dependency: content,
|
|
});
|
|
|
|
if (loading) {
|
|
return (
|
|
<CodeEditorLoadingState
|
|
isDarkMode={isDarkMode}
|
|
isSidebar={isSidebar}
|
|
loadingText={t('loading', { fileName: file.name })}
|
|
/>
|
|
);
|
|
}
|
|
|
|
// Natively previewable media (image/pdf/audio/video) is rendered inline
|
|
// instead of showing the generic "cannot be displayed" placeholder.
|
|
if (previewKind) {
|
|
return (
|
|
<CodeEditorMediaPreview
|
|
file={file}
|
|
kind={previewKind}
|
|
projectId={fileProjectId}
|
|
isSidebar={isSidebar}
|
|
isFullscreen={isFullscreen}
|
|
onClose={onClose}
|
|
onToggleFullscreen={() => setIsFullscreen((previous) => !previous)}
|
|
labels={{
|
|
loading: t('filePreview.loading', 'Loading preview...'),
|
|
error: t('filePreview.error', 'Unable to display this file.'),
|
|
openInNewTab: t('filePreview.openInNewTab', 'Open in new tab'),
|
|
fullscreen: t('actions.fullscreen', 'Fullscreen'),
|
|
exitFullscreen: t('actions.exitFullscreen', 'Exit fullscreen'),
|
|
close: t('actions.close', 'Close'),
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
// Binary file display
|
|
if (isBinary) {
|
|
return (
|
|
<CodeEditorBinaryFile
|
|
file={file}
|
|
isSidebar={isSidebar}
|
|
isFullscreen={isFullscreen}
|
|
onClose={onClose}
|
|
onToggleFullscreen={() => setIsFullscreen((previous) => !previous)}
|
|
title={t('binaryFile.title', 'Binary File')}
|
|
message={t('binaryFile.message', 'The file "{{fileName}}" cannot be displayed in the text editor because it is a binary file.', { fileName: file.name })}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const outerContainerClassName = isSidebar
|
|
? 'w-full h-full flex flex-col'
|
|
: `fixed inset-0 z-[9999] md:bg-black/50 md:flex md:items-center md:justify-center md:p-4 ${isFullscreen ? 'md:p-0' : ''}`;
|
|
|
|
const innerContainerClassName = isSidebar
|
|
? 'bg-background flex flex-col w-full h-full'
|
|
: `bg-background shadow-2xl flex flex-col w-full h-full md:rounded-lg md:shadow-2xl${
|
|
isFullscreen ? ' md:w-full md:h-full md:rounded-none' : ' md:w-full md:max-w-6xl md:h-[80vh] md:max-h-[80vh]'
|
|
}`;
|
|
|
|
return (
|
|
<>
|
|
<style>{getEditorStyles(isDarkMode)}</style>
|
|
<div className={outerContainerClassName}>
|
|
<div className={innerContainerClassName}>
|
|
<CodeEditorHeader
|
|
file={file}
|
|
isSidebar={isSidebar}
|
|
isFullscreen={isFullscreen}
|
|
isMarkdownFile={isMarkdownFile}
|
|
isHtmlPreviewFile={isHtmlPreviewFile}
|
|
markdownPreview={markdownPreview}
|
|
saving={saving}
|
|
saveSuccess={saveSuccess}
|
|
onToggleMarkdownPreview={() => setMarkdownPreview((previous) => !previous)}
|
|
onOpenHtmlPreview={openHtmlPreview}
|
|
onOpenSettings={() => paletteOps.openSettings('appearance')}
|
|
onDownload={handleDownload}
|
|
onSave={handleSave}
|
|
onToggleFullscreen={() => setIsFullscreen((previous) => !previous)}
|
|
onClose={onClose}
|
|
labels={{
|
|
showingChanges: t('header.showingChanges'),
|
|
editMarkdown: t('actions.editMarkdown'),
|
|
previewMarkdown: t('actions.previewMarkdown'),
|
|
previewHtml: t('actions.previewHtml', 'Open HTML preview in new tab'),
|
|
settings: t('toolbar.settings'),
|
|
download: t('actions.download'),
|
|
save: t('actions.save'),
|
|
saving: t('actions.saving'),
|
|
saved: t('actions.saved'),
|
|
fullscreen: t('actions.fullscreen'),
|
|
exitFullscreen: t('actions.exitFullscreen'),
|
|
close: t('actions.close'),
|
|
}}
|
|
/>
|
|
|
|
{saveError && (
|
|
<div className="border-b border-red-200 bg-red-50 px-3 py-1.5 text-xs text-red-700 dark:border-red-900/40 dark:bg-red-900/20 dark:text-red-300">
|
|
{saveError}
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex-1 overflow-hidden">
|
|
<CodeEditorSurface
|
|
content={content}
|
|
onChange={setContent}
|
|
markdownPreview={markdownPreview}
|
|
isMarkdownFile={isMarkdownFile}
|
|
isDarkMode={isDarkMode}
|
|
fontSize={fontSize}
|
|
showLineNumbers={showLineNumbers}
|
|
extensions={extensions}
|
|
/>
|
|
</div>
|
|
|
|
<CodeEditorFooter
|
|
content={content}
|
|
linesLabel={t('footer.lines')}
|
|
charactersLabel={t('footer.characters')}
|
|
shortcutsLabel={t('footer.shortcuts')}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|