Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a toggle to enable side-by-side diff viewer #2880

Merged
merged 1 commit into from
Dec 14, 2024
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
14 changes: 14 additions & 0 deletions webapp/public/js/domjudge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@ protected function parseSourceDiff(string $difftext): string
public function showDiff(string $id, SubmissionFile $newFile, SubmissionFile $oldFile): string
{
$editor = <<<HTML
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="__EDITOR__SBS">
<label class="form-check-label" for="__EDITOR__SBS">Use side-by-side diff viewer</label>
</div>
<div class="editor" id="__EDITOR__"></div>
<script>
$(function() {
Expand All @@ -943,6 +947,17 @@ public function showDiff(string $id, SubmissionFile $newFile, SubmissionFile $ol
undefined,
monaco.Uri.parse("diff-new/%s")
);

const sideBySide = isDiffSideBySide()
sideBySideSwitch = $("#__EDITOR__SBS");
sideBySideSwitch.prop('checked', sideBySide);
sideBySideSwitch.change(function(e) {
setDiffSideBySide(e.target.checked);
diffEditor.updateOptions({
renderSideBySide: e.target.checked,
});
});

const diffEditor = monaco.editor.createDiffEditor(
document.getElementById("__EDITOR__"), {
scrollbar: {
Expand All @@ -952,6 +967,7 @@ public function showDiff(string $id, SubmissionFile $newFile, SubmissionFile $ol
scrollBeyondLastLine: false,
automaticLayout: true,
readOnly: true,
renderSideBySide: sideBySide,
theme: getCurrentEditorTheme(),
});
diffEditor.setModel({
Expand Down
Loading