mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 20:20:57 +00:00
feat: add tabWidth support for code highlighting and replace tabs with spaces in CodeColorizer
(cherry picked from commit 2849f907f68022ed2879216a764668878a0bb282)
This commit is contained in:
parent
9d8921db5f
commit
2819c7d887
3 changed files with 8 additions and 1 deletions
|
|
@ -157,6 +157,7 @@ export const DiffRenderer: React.FC<DiffRendererProps> = ({
|
|||
renderedOutput = colorizeCode(
|
||||
addedContent,
|
||||
language,
|
||||
tabWidth,
|
||||
availableTerminalHeight,
|
||||
contentWidth,
|
||||
theme,
|
||||
|
|
|
|||
|
|
@ -125,17 +125,21 @@ export function colorizeLine(
|
|||
*
|
||||
* @param code The code string to highlight.
|
||||
* @param language The language identifier (e.g., 'javascript', 'css', 'html')
|
||||
* @param tabWidth The tabWidth of the language, default is 4
|
||||
* @returns A React.ReactNode containing Ink <Text> elements for the highlighted code.
|
||||
*/
|
||||
export function colorizeCode(
|
||||
code: string,
|
||||
language: string | null,
|
||||
tabWidth = 4,
|
||||
availableHeight?: number,
|
||||
maxWidth?: number,
|
||||
theme?: Theme,
|
||||
settings?: LoadedSettings,
|
||||
): React.ReactNode {
|
||||
const codeToHighlight = code.replace(/\n$/, '');
|
||||
const codeToHighlight = code
|
||||
.replace(/\n$/, '')
|
||||
.replace(/\t/g, ' '.repeat(tabWidth));
|
||||
const activeTheme = theme || themeManager.getActiveTheme();
|
||||
const showLineNumbers = settings?.merged.ui?.showLineNumbers ?? true;
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ const RenderCodeBlockInternal: React.FC<RenderCodeBlockProps> = ({
|
|||
const colorizedTruncatedCode = colorizeCode(
|
||||
truncatedContent.join('\n'),
|
||||
lang,
|
||||
4,
|
||||
availableTerminalHeight,
|
||||
contentWidth - CODE_BLOCK_PREFIX_PADDING,
|
||||
undefined,
|
||||
|
|
@ -346,6 +347,7 @@ const RenderCodeBlockInternal: React.FC<RenderCodeBlockProps> = ({
|
|||
const colorizedCode = colorizeCode(
|
||||
fullContent,
|
||||
lang,
|
||||
4,
|
||||
availableTerminalHeight,
|
||||
contentWidth - CODE_BLOCK_PREFIX_PADDING,
|
||||
undefined,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue