From 3b61cd355feed53af9edb21d0165fab38b7a46ac Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Thu, 8 Aug 2024 17:43:57 -0400 Subject: [PATCH] Fix edge case where string was emitting `data:` twice. Also, a case where the input is right around 50 chars. It can be truncated twice, leading to a long `.....` --- shared/naturalcrit/codeEditor/codeEditor.jsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 9080379a1..bc6b2b8dd 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -417,7 +417,7 @@ const CodeEditor = createClass({ widget : (from, to)=>{ let text = ''; let currentLine = from.line; - const maxLength = 50; + let maxLength = 50; let foldPreviewText = ''; while (currentLine <= to.line && text.length <= maxLength) { @@ -432,23 +432,16 @@ const CodeEditor = createClass({ } } text = foldPreviewText || `Lines ${from.line+1}-${to.line+1}`; - - text = text.replace('{', '').trim(); - // Extra data url chomping - // Try to make it pretty... - const startOfData = text.indexOf('data:') > 0 ? text.indexOf('data:') : false; - if(startOfData) { - text = (startOfData > maxLength) ? - `${text.slice(0, text.indexOf(':') + 1)} ... ${text.slice(startOfData, startOfData + 5)} ...` : - `${text.slice(0, text.indexOf('data:') + 5)} ...`; - } + // Truncate data URLs + const startOfData = text.indexOf('data:'); + if(startOfData > 0) + maxLength = Math.min(startOfData + 5, maxLength); if(text.length > maxLength) text = `${text.slice(0, maxLength)}...`; - return `\u21A4 ${text} \u21A6`; } };