Merge pull request #3914 from danielyxie/dev

Fix expr
This commit is contained in:
hydroflame 2022-07-16 01:25:26 -04:00 committed by GitHub
commit 736bb2877a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

4
dist/main.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -56,11 +56,12 @@ const lineClass = (classes: Record<string, string>, s: string): string => {
}; };
interface IProps { interface IProps {
text: string; text: unknown;
color: "primary" | "error" | "success" | "info" | "warn"; color: "primary" | "error" | "success" | "info" | "warn";
} }
export const ANSIITypography = React.memo((props: IProps): React.ReactElement => { export const ANSIITypography = React.memo((props: IProps): React.ReactElement => {
const text = String(props.text);
const classes = useStyles(); const classes = useStyles();
const parts = []; const parts = [];
@ -70,7 +71,7 @@ export const ANSIITypography = React.memo((props: IProps): React.ReactElement =>
index: 0, index: 0,
groups: { code: null }, groups: { code: null },
}; };
const matches = [INITIAL, ...props.text.matchAll(ANSI_ESCAPE), null]; const matches = [INITIAL, ...text.matchAll(ANSI_ESCAPE), null];
if (matches.length > 2) { if (matches.length > 2) {
matches.slice(0, -1).forEach((m, i) => { matches.slice(0, -1).forEach((m, i) => {
const n = matches[i + 1]; const n = matches[i + 1];
@ -78,8 +79,8 @@ export const ANSIITypography = React.memo((props: IProps): React.ReactElement =>
return; return;
} }
const startIndex = m.index + m[0].length; const startIndex = m.index + m[0].length;
const stopIndex = n ? n.index : props.text.length; const stopIndex = n ? n.index : text.length;
const partText = props.text.slice(startIndex, stopIndex); const partText = text.slice(startIndex, stopIndex);
if (startIndex !== stopIndex) { if (startIndex !== stopIndex) {
// Don't generate "empty" spans // Don't generate "empty" spans
parts.push({ code: m.groups.code, text: partText }); parts.push({ code: m.groups.code, text: partText });
@ -88,7 +89,7 @@ export const ANSIITypography = React.memo((props: IProps): React.ReactElement =>
} }
if (parts.length === 0) { if (parts.length === 0) {
// For example, if the string was empty or there were no escape sequence matches // For example, if the string was empty or there were no escape sequence matches
parts.push({ code: null, text: props.text }); parts.push({ code: null, text: text });
} }
return ( return (
<Typography classes={{ root: lineClass(classes, props.color) }} paragraph={false}> <Typography classes={{ root: lineClass(classes, props.color) }} paragraph={false}>