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