mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 15:10:59 -07:00
fix(cli): improve link measurement and refactor LaTeX arrow mapping
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,8 @@ describe('InlineMarkdownRenderer', () => {
|
||||
['compile-time**', 14],
|
||||
['$\\rightarrow$', 1],
|
||||
['Sign Out $\\rightarrow$ Sign In', 18],
|
||||
['[Google](https://google.com)', 27],
|
||||
['Preceding [Link](url)', 20],
|
||||
])(
|
||||
'should measure markdown text length correctly for "%s"',
|
||||
(input, expected) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,13 @@ const INLINE_CODE_MARKER_LENGTH = 1; // For "`"
|
||||
const UNDERLINE_TAG_START_LENGTH = 3; // For "<u>"
|
||||
const UNDERLINE_TAG_END_LENGTH = 4; // For "</u>"
|
||||
|
||||
const LATEX_MAP: Record<string, string> = {
|
||||
'$\\rightarrow$': '→',
|
||||
'$\\leftarrow$': '←',
|
||||
'$\\uparrow$': '↑',
|
||||
'$\\downarrow$': '↓',
|
||||
};
|
||||
|
||||
interface RenderInlineProps {
|
||||
text: string;
|
||||
defaultColor?: string;
|
||||
@@ -144,13 +151,7 @@ const RenderInlineInternal: React.FC<RenderInlineProps> = ({
|
||||
</Text>
|
||||
);
|
||||
} else if (fullMatch.startsWith('$') && fullMatch.endsWith('$')) {
|
||||
const latexMap: Record<string, string> = {
|
||||
'$\\rightarrow$': '→',
|
||||
'$\\leftarrow$': '←',
|
||||
'$\\uparrow$': '↑',
|
||||
'$\\downarrow$': '↓',
|
||||
};
|
||||
const replacement = latexMap[fullMatch];
|
||||
const replacement = LATEX_MAP[fullMatch];
|
||||
if (replacement) {
|
||||
renderedNode = (
|
||||
<Text key={key} color={baseColor}>
|
||||
@@ -199,7 +200,10 @@ export const getPlainTextLength = (text: string): number => {
|
||||
.replace(/~~(.*?)~~/g, '$1')
|
||||
.replace(/`(.*?)`/g, '$1')
|
||||
.replace(/<u>(.*?)<\/u>/g, '$1')
|
||||
.replace(/.*\[(.*?)\]\(.*\)/g, '$1')
|
||||
.replace(/\$\\(rightarrow|leftarrow|uparrow|downarrow)\$/g, '→');
|
||||
.replace(/\[(.*?)\]\((.*?)\)/g, '$1 ($2)')
|
||||
.replace(
|
||||
/\$\\(rightarrow|leftarrow|uparrow|downarrow)\$/g,
|
||||
(match) => LATEX_MAP[match] ?? match,
|
||||
);
|
||||
return stringWidth(cleanText);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user