From d6e591df1fcbb0a6852aff7908b062ae45eb638f Mon Sep 17 00:00:00 2001 From: Jordan Rome Date: Fri, 7 Nov 2025 20:12:25 -0500 Subject: [PATCH 1/2] Add ability to paste c-source files The pasted C source files need to match up with what the verifier has or else we don't allow the contents to be overwritten. --- src/App.tsx | 42 ++++++++++++++ src/components.tsx | 141 ++++++++++++++++++++++++++++++++++++++++++++- src/index.css | 67 ++++++++++++++++++++- 3 files changed, 247 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 70222da..ca574e0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -62,6 +62,8 @@ function getVisibleLogLines( function getVisibleCLines( verifierLogState: VerifierLogState, + fileName: string = "", + pastedLines: string[] = [], ): [CSourceRow[], Map] { const cLineIdToVisualIdx: Map = new Map(); const cLines: CSourceRow[] = []; @@ -74,6 +76,24 @@ function getVisibleCLines( }); ++j; + if (file === fileName && pastedLines.length > 0) { + pastedLines.forEach((lineText, i) => { + const lineNum = i + 1; + const sourceId = getCLineId(file, lineNum); + cLines.push({ + type: "c_line", + file, + lineNum: i + 1, + lineText, + sourceId, + ignore: false, + }); + cLineIdToVisualIdx.set(sourceId, j); + ++j; + }); + continue; + } + let unknownStart = 0; for (let i = range[0]; i < range[1]; ++i) { const sourceId = getCLineId(file, i); @@ -144,6 +164,7 @@ const ContentRaw = ({ handleLogLinesOut, handleFullLogToggle, testListHeight, + addPastedCSourceFile, }: { loadError: string | null; visualLogState: VisualLogState; @@ -154,6 +175,7 @@ const ContentRaw = ({ handleLogLinesOut: (event: React.MouseEvent) => void; handleFullLogToggle: () => void; testListHeight: number | undefined; + addPastedCSourceFile: (fileName: string, pastedLines: string[]) => void; }) => { if (loadError) { return
{loadError}
; @@ -167,6 +189,7 @@ const ContentRaw = ({ handleLogLinesOut={handleLogLinesOut} handleFullLogToggle={handleFullLogToggle} testListHeight={testListHeight} + addPastedCSourceFile={addPastedCSourceFile} /> ); } else { @@ -268,6 +291,24 @@ function App({ testListHeight }: { testListHeight?: number }) { setIsLoading(false); }, []); + const addPastedCSourceFile = useCallback( + (fileName: string, pastedLines: string[]) => { + setVisualLogState((prevState) => { + const [cLines, cLineIdToVisualIdx] = getVisibleCLines( + verifierLogState, + fileName, + pastedLines, + ); + return { + ...prevState, + cLines, + cLineIdToVisualIdx, + }; + }); + }, + [verifierLogState], + ); + const loadInputText = useCallback( (text: string) => { const rawLines = text.split("\n"); @@ -452,6 +493,7 @@ function App({ testListHeight }: { testListHeight?: number }) { handleLogLinesOut={handleLogLinesOut} handleFullLogToggle={handleFullLogToggle} testListHeight={testListHeight} + addPastedCSourceFile={addPastedCSourceFile} />
void; + addPastedCSourceFile: (fileName: string, pastedLines: string[]) => void; +}) { + const [pastedContent, setPastedContent] = useState(""); + const [mismatchError, setMismatcError] = useState(false); + + const handleChange = useCallback( + (event: ChangeEvent) => { + setMismatcError(false); + const pastedText = event.target.value; + setPastedContent(pastedText); + const pastedLines: string[] = pastedText.split("\n"); + for (const [file] of verifierLogState.cSourceMap.fileRange) { + if (file !== fileName) { + continue; + } + pastedLines.some((lineText, i) => { + const lineNum = i + 1; + const sourceId = getCLineId(file, lineNum); + const sourceLine = + verifierLogState.cSourceMap.cSourceLines.get(sourceId); + if (sourceLine && !sourceLine.ignore) { + if (!lineText.includes(sourceLine.content)) { + setMismatcError(true); + return true; + } + } + return false; + }); + } + }, + [], + ); + + const handleConfirm = useCallback(() => { + addPastedCSourceFile(fileName, pastedContent.split("\n")); + onHideCSourcePaste(); + }, [pastedContent]); + + const handleClear = useCallback(() => { + setPastedContent(""); + setMismatcError(false); + }, []); + + const onContentClick = useCallback( + (event: React.MouseEvent) => { + event.stopPropagation(); + }, + [], + ); + + return ( +
+
+

Paste contents of {fileName}

+