Skip to content

Commit f93c3b3

Browse files
committed
added mouse support to the command line
changed the behaviour of the escape key to now go back to a previous command list
1 parent 47e72f1 commit f93c3b3

3 files changed

Lines changed: 119 additions & 77 deletions

File tree

public/css/style.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ a:hover {
185185
color: var(--bg-color);
186186
background: var(--main-color);
187187
}
188+
&:hover{
189+
color: var(--bg-color);
190+
background: var(--main-color);
191+
cursor: pointer;
192+
}
188193
}
189194
}
190195
}

public/js/commandline.js

Lines changed: 114 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let commands = {
5454
display: "Change theme...",
5555
subgroup: true,
5656
exec: () => {
57-
currentCommands = commandsThemes;
57+
currentCommands.push(commandsThemes);
5858
showCommandLine();
5959
}
6060
},
@@ -63,7 +63,7 @@ let commands = {
6363
display: "Change language...",
6464
subgroup: true,
6565
exec: () => {
66-
currentCommands = commandsLanguages;
66+
currentCommands.push(commandsLanguages);
6767
showCommandLine();
6868
}
6969
},
@@ -72,7 +72,7 @@ let commands = {
7272
display: "Change font size...",
7373
subgroup: true,
7474
exec: () => {
75-
currentCommands = commandsFontSize;
75+
currentCommands.push(commandsFontSize);
7676
showCommandLine();
7777
}
7878
},
@@ -81,7 +81,7 @@ let commands = {
8181
display: "Change mode...",
8282
subgroup: true,
8383
exec: () => {
84-
currentCommands = commandsMode;
84+
currentCommands.push(commandsMode);
8585
showCommandLine();
8686
}
8787
},
@@ -90,7 +90,7 @@ let commands = {
9090
display: "Change time config...",
9191
subgroup: true,
9292
exec: () => {
93-
currentCommands = commandsTimeConfig;
93+
currentCommands.push(commandsTimeConfig);
9494
showCommandLine();
9595
}
9696
},
@@ -99,7 +99,7 @@ let commands = {
9999
display: "Change word count...",
100100
subgroup: true,
101101
exec: () => {
102-
currentCommands = commandsWordCount;
102+
currentCommands.push(commandsWordCount);
103103
showCommandLine();
104104
}
105105
},
@@ -115,7 +115,7 @@ let commands = {
115115
display: "Send a message ( bug report / feature request / feedback )...",
116116
subgroup: true,
117117
exec: () => {
118-
currentCommands = commandsSendDevMessage;
118+
currentCommands.push(commandsSendDevMessage);
119119
showCommandLine();
120120
}
121121
}
@@ -342,6 +342,7 @@ let commandsLanguages = {
342342
]
343343
};
344344

345+
345346
if (Object.keys(words).length > 0) {
346347
commandsLanguages.list = [];
347348
Object.keys(words).forEach(language => {
@@ -367,10 +368,15 @@ $(document).ready(e => {
367368
//escape
368369
if (event.keyCode == 27) {
369370
if ($("#commandLineWrapper").hasClass("hidden")) {
370-
currentCommands = commands;
371+
currentCommands = [commands];
371372
showCommandLine();
372373
} else {
373-
hideCommandLine();
374+
if(currentCommands.length > 1){
375+
currentCommands.pop();
376+
showCommandLine();
377+
}else{
378+
hideCommandLine();
379+
}
374380
setTheme(config.theme);
375381
}
376382
}
@@ -383,7 +389,8 @@ $("#commandInput textarea").keydown((e) => {
383389
e.preventDefault();
384390
let command = $("#commandInput textarea").attr("command");
385391
let value = $("#commandInput textarea").val();
386-
$.each(currentCommands.list, (i, obj) => {
392+
let list = currentCommands[currentCommands.length-1];
393+
$.each(list.list, (i, obj) => {
387394
if (obj.id == command) {
388395
obj.exec(value);
389396
if (obj.subgroup !== null && obj.subgroup !== undefined) {
@@ -403,79 +410,108 @@ $("#commandInput textarea").keydown((e) => {
403410
return;
404411
});
405412

406-
$("#commandLine input").keydown((e) => {
407-
if (e.keyCode == 13) {
408-
//enter
409-
e.preventDefault();
410-
let command = $(".suggestions .entry.active").attr("command");
411-
let subgroup = false;
412-
let input = false;
413-
$.each(currentCommands.list, (i, obj) => {
414-
if (obj.id == command) {
415-
if (obj.input) {
416-
input = true;
417-
showCommandInput(obj.id, obj.display);
413+
414+
$("#commandLineWrapper #commandLine .suggestions").on('mouseover', e => {
415+
$("#commandLineWrapper #commandLine .suggestions .entry").removeClass('active');
416+
let hoverId = $(e.target).attr('command');
417+
try {
418+
let list = currentCommands[currentCommands.length-1];
419+
$.each(list.list, (index, obj) => {
420+
if (obj.id == hoverId) {
421+
obj.hover();
422+
}
423+
});
424+
} catch (e) { }
425+
})
426+
427+
428+
429+
$("#commandLineWrapper #commandLine .suggestions").click(e =>{
430+
triggerCommand($(e.target).attr('command'));
431+
})
432+
433+
$(document).keydown((e) => {
434+
if(!$("#commandLineWrapper").hasClass("hidden")){
435+
$("#commandLine input").focus();
436+
if (e.keyCode == 13) {
437+
//enter
438+
e.preventDefault();
439+
let command = $(".suggestions .entry.active").attr("command");
440+
triggerCommand(command);
441+
return;
442+
}
443+
if (e.keyCode == 38 || e.keyCode == 40) {
444+
$("#commandLineWrapper #commandLine .suggestions .entry").unbind("mouseenter mouseleave");
445+
let entries = $(".suggestions .entry");
446+
let activenum = -1;
447+
let hoverId;
448+
$.each(entries, (index, obj) => {
449+
if ($(obj).hasClass("active")) activenum = index;
450+
});
451+
if (e.keyCode == 38) {
452+
entries.removeClass("active");
453+
if (activenum == 0) {
454+
$(entries[entries.length - 1]).addClass("active");
455+
hoverId = $(entries[entries.length - 1]).attr('command');
418456
} else {
419-
obj.exec();
420-
if (obj.subgroup !== null && obj.subgroup !== undefined) {
421-
subgroup = obj.subgroup;
422-
}
457+
$(entries[--activenum]).addClass("active");
458+
hoverId = $(entries[activenum]).attr('command');
423459
}
424460
}
425-
});
426-
if (!subgroup && !input) {
427-
try{
428-
firebase.analytics().logEvent('usedCommandLine', {
429-
command: command
430-
});
431-
}catch(e){
432-
console.log("Analytics unavailable");
461+
if (e.keyCode == 40) {
462+
entries.removeClass("active");
463+
if (activenum + 1 == entries.length) {
464+
$(entries[0]).addClass("active");
465+
hoverId = $(entries[0]).attr('command');
466+
} else {
467+
$(entries[++activenum]).addClass("active");
468+
hoverId = $(entries[activenum]).attr('command');
469+
}
433470
}
434-
hideCommandLine();
471+
try {
472+
let list = currentCommands[currentCommands.length-1];
473+
$.each(list.list, (index, obj) => {
474+
if (obj.id == hoverId) {
475+
obj.hover();
476+
}
477+
});
478+
} catch (e) { }
479+
480+
return false;
435481
}
436-
return;
437482
}
438-
if (e.keyCode == 38 || e.keyCode == 40) {
439-
//up
440-
let entries = $(".suggestions .entry");
441-
let activenum = -1;
442-
let hoverId;
443-
$.each(entries, (index, obj) => {
444-
if ($(obj).hasClass("active")) activenum = index;
445-
});
446-
if (e.keyCode == 38) {
447-
entries.removeClass("active");
448-
if (activenum == 0) {
449-
$(entries[entries.length - 1]).addClass("active");
450-
hoverId = $(entries[entries.length - 1]).attr('command');
451-
} else {
452-
$(entries[--activenum]).addClass("active");
453-
hoverId = $(entries[activenum]).attr('command');
454-
}
455-
}
456-
if (e.keyCode == 40) {
457-
entries.removeClass("active");
458-
if (activenum + 1 == entries.length) {
459-
$(entries[0]).addClass("active");
460-
hoverId = $(entries[0]).attr('command');
483+
});
484+
485+
let currentCommands = [commands];
486+
487+
function triggerCommand(command){
488+
let subgroup = false;
489+
let input = false;
490+
let list = currentCommands[currentCommands.length-1];
491+
$.each(list.list, (i, obj) => {
492+
if (obj.id == command) {
493+
if (obj.input) {
494+
input = true;
495+
showCommandInput(obj.id, obj.display);
461496
} else {
462-
$(entries[++activenum]).addClass("active");
463-
hoverId = $(entries[activenum]).attr('command');
497+
obj.exec();
498+
if (obj.subgroup !== null && obj.subgroup !== undefined) {
499+
subgroup = obj.subgroup;
500+
}
464501
}
465502
}
466-
try {
467-
$.each(currentCommands.list, (index, obj) => {
468-
if (obj.id == hoverId) {
469-
obj.hover();
470-
}
503+
});
504+
if (!subgroup && !input) {
505+
try{
506+
firebase.analytics().logEvent('usedCommandLine', {
507+
command: command
471508
});
472-
} catch (e) { }
473-
474-
return false;
509+
}catch(e){
510+
console.log("Analytics unavailable");
511+
}
512+
hideCommandLine();
475513
}
476-
});
477-
478-
514+
}
479515

480516
function hideCommandLine() {
481517
$("#commandLineWrapper")
@@ -526,12 +562,13 @@ function hideCommandLine() {
526562

527563
function updateSuggestedCommands() {
528564
let inputVal = $("#commandLine input").val().toLowerCase().split(" ");
565+
let list = currentCommands[currentCommands.length-1];
529566
if (inputVal[0] == "") {
530-
$.each(currentCommands.list, (index, obj) => {
567+
$.each(list.list, (index, obj) => {
531568
obj.found = true;
532569
});
533570
} else {
534-
$.each(currentCommands.list, (index, obj) => {
571+
$.each(list.list, (index, obj) => {
535572
let foundcount = 0;
536573
$.each(inputVal, (index2, obj2) => {
537574
if (obj2 == "") return;
@@ -555,7 +592,8 @@ function hideCommandLine() {
555592

556593
function displayFoundCommands() {
557594
$("#commandLine .suggestions").empty();
558-
$.each(currentCommands.list, (index, obj) => {
595+
let list = currentCommands[currentCommands.length-1];
596+
$.each(list.list, (index, obj) => {
559597
if (obj.found) {
560598
$("#commandLine .suggestions").append(
561599
'<div class="entry" command="' + obj.id + '">' + obj.display + "</div>"
@@ -574,7 +612,7 @@ function hideCommandLine() {
574612
if (entries.length > 0) {
575613
$(entries[0]).addClass("active");
576614
try{
577-
$.each(currentCommands.list, (index, obj) => {
615+
$.each(list.list, (index, obj) => {
578616
if (obj.found) {
579617
obj.hover();
580618
return false;

public/js/script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let timers = [];
77
let testActive = false;
88
let testStart, testEnd;
99
let wpmHistory = [];
10-
let currentCommands = commands;
1110
let restartCount = 0;
1211
let currentTestLine = 0;
1312
let pageTransition = false;

0 commit comments

Comments
 (0)