Fix MM55258 (#7729)
* Fix MM55258 * Address feedback --------- Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
8bd9cac9f5
commit
9ea38cfb3f
1 changed files with 9 additions and 1 deletions
|
|
@ -29,6 +29,12 @@ const styles = StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
function getMaximumLineLength(code: string) {
|
||||
return code.split('\n').reduce((prev, v) => Math.max(prev, v.length), 0);
|
||||
}
|
||||
|
||||
const MAXIMUM_CODE_LINE_LENGTH = 300;
|
||||
|
||||
const Highlighter = ({code, language, textStyle, selectable = false}: SyntaxHiglightProps) => {
|
||||
const theme = useTheme();
|
||||
const style = codeTheme[theme.codeTheme] || github;
|
||||
|
|
@ -38,6 +44,8 @@ const Highlighter = ({code, language, textStyle, selectable = false}: SyntaxHigl
|
|||
{backgroundColor: style.hljs.background || theme.centerChannelBg},
|
||||
],
|
||||
[theme, selectable, style]);
|
||||
const maximumLineLength = useMemo(() => getMaximumLineLength(code), [code]);
|
||||
const languageToUse = maximumLineLength > MAXIMUM_CODE_LINE_LENGTH ? 'text' : language;
|
||||
|
||||
const nativeRenderer = useCallback(({rows, stylesheet}: rendererProps) => {
|
||||
const digits = rows.length.toString().length;
|
||||
|
|
@ -65,7 +73,7 @@ const Highlighter = ({code, language, textStyle, selectable = false}: SyntaxHigl
|
|||
return (
|
||||
<SyntaxHighlighter
|
||||
style={style}
|
||||
language={language}
|
||||
language={languageToUse}
|
||||
horizontal={true}
|
||||
showLineNumbers={true}
|
||||
renderer={nativeRenderer}
|
||||
|
|
|
|||
Loading…
Reference in a new issue