Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/webapp/app/components/code/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,35 +221,35 @@ export const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
const [modalCopied, setModalCopied] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isWrapped, setIsWrapped] = useState(wrap);
const normalizedCode = code?.trim() ?? "";

const onCopied = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
event.stopPropagation();
navigator.clipboard.writeText(code);
navigator.clipboard.writeText(normalizedCode);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 1500);
},
[code]
[normalizedCode]
);

const onModalCopied = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
event.stopPropagation();
navigator.clipboard.writeText(code);
navigator.clipboard.writeText(normalizedCode);
setModalCopied(true);
setTimeout(() => {
setModalCopied(false);
}, 1500);
},
[code]
[normalizedCode]
);

code = code?.trim() ?? "";
const lineCount = code.split("\n").length;
const lineCount = normalizedCode.split("\n").length;
const maxLineWidth = lineCount.toString().length;
let maxHeight: string | undefined = undefined;
if (maxLines && lineCount > maxLines) {
Expand Down Expand Up @@ -345,7 +345,7 @@ export const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
{shouldHighlight ? (
<HighlightCode
theme={theme}
code={code}
code={normalizedCode}
language={language}
showLineNumbers={showLineNumbers}
highlightLines={highlightLines}
Expand Down Expand Up @@ -373,7 +373,7 @@ export const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
)}
dir="ltr"
>
{highlightSearchText(code, searchTerm)}
{highlightSearchText(normalizedCode, searchTerm)}
</pre>
</div>
)}
Expand All @@ -400,7 +400,7 @@ export const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
{shouldHighlight ? (
<HighlightCode
theme={theme}
code={code}
code={normalizedCode}
language={language}
showLineNumbers={showLineNumbers}
highlightLines={highlightLines}
Expand All @@ -415,7 +415,7 @@ export const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
className="overflow-auto px-3 py-3 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-surface-control"
>
<pre className="relative mr-2 p-2 font-mono text-base leading-relaxed" dir="ltr">
{highlightSearchText(code, searchTerm)}
{highlightSearchText(normalizedCode, searchTerm)}
</pre>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function ReportFindingLine({
* entities mono, verdict phrases bright and medium, everything else dimmed.
* Colour stays reserved for severity, so emphasis here is weight only.
*/
const QUANTITY_RE = /~?\d[\d,.]*\s?(?:%|×|\/min|ms\b|s\b|min\b|h\b)?/g;
const QUANTITY_RE = /~?\d[\d,.]*\s?(?:%|×|\/min|ms\b|s\b|min\b|h\b)?/;

const VERDICT_PHRASES = [
"not your code",
Expand Down Expand Up @@ -249,7 +249,6 @@ export function ReportProse({ text, entities }: { text: string; entities?: strin
segments = splitBy(
segments,
(t) => {
QUANTITY_RE.lastIndex = 0;
const m = QUANTITY_RE.exec(t);
return m && m[0].trim().length > 0 ? { start: m.index, end: m.index + m[0].length } : null;
},
Expand Down
9 changes: 5 additions & 4 deletions apps/webapp/app/components/primitives/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,20 @@ function SelectGroupedRenderer<TItem>({
) => React.ReactNode;
enableItemShortcuts: boolean;
}) {
let count = 0;
return (
<>
{items.map((section, index) => {
const previousItem = items.at(index - 1);
count += previousItem ? previousItem.items.length : 0;
const startIndex = items
.slice(0, index)
.reduce((count, previousSection) => count + previousSection.items.length, 0);

return (
<Fragment key={index}>
{children(section.items as ItemFromSection<TItem>[], {
shortcutsEnabled: enableItemShortcuts,
section: {
title: section.title,
startIndex: count - 1,
startIndex,
Comment thread
carderne marked this conversation as resolved.
count: section.items.length,
},
})}
Expand Down