This was worrying, an LLM used an event.shiftKey
to check if the Shift key was pressed as per the documentation
but it didn’t work? In fact, after a console.log(event)
, it was apparent that no such variable existed.
Problem
switch(event.key) {
case 'z':
event.preventDefault();
if (event.shiftKey) {
redo(); // Ctrl+Shift+Z for Redo
} else {
undo(); // Ctrl+Z for Undo
}
break;
...
Wait so the documentation was wrong? Probably not, for all we know the Browser may be at fault here.
Solution
switch(event.key) {
case 'z':
event.preventDefault();
if (event.shiftKey) {
redo(); // Ctrl+Shift+Z for Redo
} else {
undo(); // Ctrl+Z for Undo
}
break;
case 'Z':
event.preventDefault();
redo(); // Ctrl+Shift+Z for Redo
break;
...
The solution is easy, even obvious, but add this to the pile of things that LLMs will fail at.