From 678d7a0b9beb4c9de24120639e6c263faf713ba9 Mon Sep 17 00:00:00 2001 From: Kevin Jilissen Date: Sat, 14 Dec 2024 00:18:02 +0100 Subject: [PATCH] Add a toggle to enable side-by-side diff viewer Store the last toggled diff viewer state in the local storage. The way diffs are viewed is mostly a user preference, but depending on the file and type of changes, the option to quickly toggle it can come in handy. Note that for multi-file submissions, a per-file toggle is included in the tab, but on reload all tabs will have the state of the last toggled switch. --- webapp/public/js/domjudge.js | 14 ++++++++++++++ webapp/src/Twig/TwigExtension.php | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/webapp/public/js/domjudge.js b/webapp/public/js/domjudge.js index 05b6550e82..3cc63a31f5 100644 --- a/webapp/public/js/domjudge.js +++ b/webapp/public/js/domjudge.js @@ -124,6 +124,20 @@ function applyEditorTheme(theme = undefined, isExternal = false) }); } +function isDiffSideBySide() +{ + let sideBySide = localStorage.getItem('domjudge_editor_side_by_side'); + if (sideBySide === undefined) { + return true; + } + return sideBySide == 'true'; +} + +function setDiffSideBySide(value) +{ + localStorage.setItem('domjudge_editor_side_by_side', value); +} + // Send a notification if notifications have been enabled. // The options argument is passed to the Notification constructor, // except that the following tags (if found) are interpreted and diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php index 3a20dd765f..5ed73d6f14 100644 --- a/webapp/src/Twig/TwigExtension.php +++ b/webapp/src/Twig/TwigExtension.php @@ -929,6 +929,10 @@ protected function parseSourceDiff(string $difftext): string public function showDiff(string $id, SubmissionFile $newFile, SubmissionFile $oldFile): string { $editor = << + + +