diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d34fef..4ebc442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +### Fixed + +- Broken shortcut behaviour when ctrl/meta is pressed. + This was previously handled correctly for c but not for the others. +- Use the paste key to correctly set the window target, i.e. going to raw view + from Markdown view works. + ## 3.6.1 diff --git a/crates/wastebin_server/src/javascript/paste.js b/crates/wastebin_server/src/javascript/paste.js index ca91342..feb39af 100644 --- a/crates/wastebin_server/src/javascript/paste.js +++ b/crates/wastebin_server/src/javascript/paste.js @@ -77,26 +77,40 @@ function copy() { } function onKey(e) { + if (e.keyCode == 27) { + const overlay = document.getElementById("overlay"); + if (overlay && overlay.style.display == "block") { + overlay.style.display = "none"; + } + return; + } + + if (e.ctrlKey || e.metaKey) { + return; + } + + const pasteId = document.body.dataset.pasteId; + if (e.key == 'n') { window.location.href = "/"; } - else if (e.key == 'r') { - window.location.href = "/raw" + window.location.pathname; + else if (e.key == 'r' && pasteId) { + window.location.href = "/raw/" + pasteId; } else if (e.key == 'y') { navigator.clipboard.writeText(window.location.href); showToast("Copied URL", 1500); } - else if (e.key == 'd') { - window.location.href = "/dl" + window.location.pathname; + else if (e.key == 'd' && pasteId) { + window.location.href = "/dl/" + pasteId; } - else if (e.key == 'q') { - window.location.href = "/qr" + window.location.pathname; + else if (e.key == 'q' && pasteId) { + window.location.href = "/qr/" + pasteId; } else if (e.key == 'p') { window.location.href = window.location.href.split("?")[0]; } - else if (e.key == 'c' && !(e.ctrlKey || e.metaKey)) { + else if (e.key == 'c') { copy(); } else if (e.key == 'w') { @@ -109,13 +123,6 @@ function onKey(e) { else if (e.key == '?') { toggleOverlay(); } - - if (e.keyCode == 27) { - const overlay = document.getElementById("overlay"); - if (overlay && overlay.style.display == "block") { - overlay.style.display = "none"; - } - } } function buildOverlay() { diff --git a/crates/wastebin_server/templates/base.html b/crates/wastebin_server/templates/base.html index 8e88e2e..36abe32 100644 --- a/crates/wastebin_server/templates/base.html +++ b/crates/wastebin_server/templates/base.html @@ -22,7 +22,7 @@ {% block head %}{% endblock %} - + {% block body %}
diff --git a/crates/wastebin_server/templates/paste.html b/crates/wastebin_server/templates/paste.html index 2bcabc4..ec92608 100644 --- a/crates/wastebin_server/templates/paste.html +++ b/crates/wastebin_server/templates/paste.html @@ -15,6 +15,8 @@ {% endblock %} +{% block body_attrs %} data-paste-id="{{ key }}"{% endblock %} + {% block nav_actions %} {% if is_available %} {% if can_delete %}