add cmd/ctrl + arrow key shortcuts to first/last slides

edit
Hakim El Hattab 2018-11-13 10:48:23 +01:00
parent b6ce0a9724
commit f042a8c394
2 changed files with 25 additions and 17 deletions

View File

@ -318,17 +318,17 @@
// Holds information about the keyboard shortcuts // Holds information about the keyboard shortcuts
keyboardShortcuts = { keyboardShortcuts = {
'N , SPACE': 'Next slide', 'N , SPACE': 'Next slide',
'P': 'Previous slide', 'P': 'Previous slide',
'← , H': 'Navigate left', '← , H': 'Navigate left',
'→ , L': 'Navigate right', '→ , L': 'Navigate right',
'↑ , K': 'Navigate up', '↑ , K': 'Navigate up',
'↓ , J': 'Navigate down', '↓ , J': 'Navigate down',
'Home': 'First slide', 'Home , ⌘/CTRL ←': 'First slide',
'End': 'Last slide', 'End , ⌘/CTRL →': 'Last slide',
'B , .': 'Pause', 'B , .': 'Pause',
'F': 'Fullscreen', 'F': 'Fullscreen',
'ESC, O': 'Slide overview' 'ESC, O': 'Slide overview'
}, },
// Holds custom key code mappings // Holds custom key code mappings
@ -4865,15 +4865,23 @@
onUserInput( event ); onUserInput( event );
// Check if there's a focused element that could be using // Is there a focused element that could be using the keyboard?
// the keyboard
var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit'; var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName ); var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className); var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className);
// Whitelist specific modified + keycode combinations
var prevSlideShortcut = event.shiftKey && event.keyCode === 32;
var firstSlideShortcut = ( event.metaKey || event.ctrlKey ) && event.keyCode === 37;
var lastSlideShortcut = ( event.metaKey || event.ctrlKey ) && event.keyCode === 39;
// Prevent all other events when a modifier is pressed
var unusedModifier = !prevSlideShortcut && !firstSlideShortcut && !lastSlideShortcut &&
( event.shiftKey || event.altKey || event.ctrlKey || event.metaKey );
// Disregard the event if there's a focused element or a // Disregard the event if there's a focused element or a
// keyboard modifier key is present // keyboard modifier key is present
if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return; if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || unusedModifier ) return;
// While paused only allow resume keyboard events; 'b', 'v', '.' // While paused only allow resume keyboard events; 'b', 'v', '.'
var resumeKeyCodes = [66,86,190,191]; var resumeKeyCodes = [66,86,190,191];
@ -4957,9 +4965,9 @@
// n, page down // n, page down
case 78: case 34: navigateNext(); break; case 78: case 34: navigateNext(); break;
// h, left // h, left
case 72: case 37: navigateLeft(); break; case 72: case 37: firstSlideShortcut ? slide( 0 ) : navigateLeft(); break;
// l, right // l, right
case 76: case 39: navigateRight(); break; case 76: case 39: lastSlideShortcut ? slide( Number.MAX_VALUE ) : navigateRight(); break;
// k, up // k, up
case 75: case 38: navigateUp(); break; case 75: case 38: navigateUp(); break;
// j, down // j, down

View File

@ -200,7 +200,7 @@ function Hilitor(id, tag)
toggleSearch(); toggleSearch();
} }
}, false ); }, false );
if( window.Reveal ) Reveal.registerKeyboardShortcut( 'Ctrl-Shift-F', 'Search' ); if( window.Reveal ) Reveal.registerKeyboardShortcut( 'CTRL + Shift + F', 'Search' );
closeSearch(); closeSearch();
return { open: openSearch }; return { open: openSearch };
})(); })();