Skip to content

Commit 8148d3b

Browse files
committed
Allow selection of diff using keyboard
Add overflow to the keyhelp as it it more likely to overflow on screens now.
1 parent 7b5b65d commit 8148d3b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

webapp/public/js/domjudge.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ $(function () {
965965
function initializeKeyboardShortcuts() {
966966
var $body = $('body');
967967
var ignore = false;
968+
const validKeys = new Set(['c', 'd', 'j', 'p', 's', 't']);
968969
$body.on('keydown', function(e) {
969970
var keysCookie = getCookie('domjudge_keys');
970971
if (keysCookie != 1 && keysCookie != "") {
@@ -1010,7 +1011,7 @@ function initializeKeyboardShortcuts() {
10101011
parts[parts.length - 1] += '?' + params[1];
10111012
}
10121013
window.location = parts.join('/');
1013-
} else if (!ignore && (key === 's' || key === 't' || key === 'p' || key === 'j' || key === 'c')) {
1014+
} else if (!ignore && validKeys.has(key)) {
10141015
if (e.shiftKey && key === 's') {
10151016
window.location = domjudge_base_url + '/jury/scoreboard';
10161017
return;
@@ -1053,6 +1054,27 @@ function initializeKeyboardShortcuts() {
10531054
$body.on('keydown', oldFunc);
10541055
if (e.key === 'Enter') {
10551056
switch (type) {
1057+
case 'd':
1058+
if (editors) {
1059+
const editorId = Object.keys(editors)[0];
1060+
const diffEditor = editors[editorId];
1061+
const select = diffEditor.submissionSelect;
1062+
if (typedSequence.length === 0) {
1063+
// Reset to no-diff.
1064+
select.selectedIndex = 0;
1065+
select.dispatchEvent(new Event('change'));
1066+
return;
1067+
}
1068+
const url = domjudge_base_url + `/jury/submissions/${typedSequence}`;
1069+
for (let i = 0; i < select.options.length; i++) {
1070+
if (select.options[i].dataset.url === url) {
1071+
select.selectedIndex = i;
1072+
select.dispatchEvent(new Event('change'));
1073+
return;
1074+
}
1075+
}
1076+
}
1077+
return;
10561078
case 's':
10571079
type = 'submissions';
10581080
break;
@@ -1360,6 +1382,7 @@ function initDiffEditor(editorId) {
13601382
const diffLink = diffTitle.querySelector('a.diff-link');
13611383

13621384
const editor = {
1385+
'submissionSelect': select[0],
13631386
'getDiffMode': () => {
13641387
for (let radio of radios) {
13651388
if (radio.checked) {

webapp/public/style_domjudge.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ blockquote {
722722
padding: 20px;
723723
border-radius: 5px;
724724
z-index: 1001;
725+
overflow: auto;
725726
}
726727

727728
#keyhelp code {

webapp/templates/jury/base.html.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
<code>k</code> go to the previous item, e.g. previous submission <br/>
7171
<br/>
7272

73+
<code>d</code> <code>↵</code> switch diff viewer to no diff <br/>
74+
<code>d</code> <code>[0-9]+</code> <code>↵</code> switch to diff against a submission, e.g. <code>d42↵</code> shows diff against submission 42 <br/>
75+
<br/>
76+
7377
<code>s</code> <code>↵</code> open the list of submissions <br/>
7478
<code>s</code> <code>[0-9]+</code> <code>↵</code> open a specific submission, e.g. <code>s42↵</code> to go to submission 42 <br/>
7579
<br/>

0 commit comments

Comments
 (0)