From 7feb284e4d15861daf485db6d5a0c7d11b228ec5 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 14 Jun 2021 09:37:40 +0200 Subject: [PATCH] Implement new shortcuts: - "s" and "/" for Focus search bar - "h" - clear highlighted text Fixes #691. --- sphinx/themes/basic/static/doctools.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js index 8cbf1b161a..70bbfe940b 100644 --- a/sphinx/themes/basic/static/doctools.js +++ b/sphinx/themes/basic/static/doctools.js @@ -294,21 +294,28 @@ var Documentation = { if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT' && activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) { - switch (event.keyCode) { - case 37: // left + switch (event.key) { + case 'ArrowLeft': var prevHref = $('link[rel="prev"]').prop('href'); if (prevHref) { window.location.href = prevHref; return false; } - break; - case 39: // right + case 'ArrowRight': var nextHref = $('link[rel="next"]').prop('href'); if (nextHref) { window.location.href = nextHref; return false; } - break; + case '/': + case 's': + $('input[name=q]').focus(); + return false; + case 'h': + newurl = window.location.href.replace(new RegExp('\\?highlight=[^#]*'), ''); + history.pushState({}, null, newurl); + Documentation.hideSearchWords(); + return false; } } });