Skip to content

Commit 29857ce

Browse files
committed
Filter ctrl/meta modifier and use paste key for window targets
Fixes #208.
1 parent b63022b commit 29857ce

4 files changed

Lines changed: 31 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
- Broken shortcut behaviour when <kbd>ctrl</kbd>/<kbd>meta</kbd> is pressed.
8+
This was previously handled correctly for <kbd>c</kbd> but not for the others.
9+
- Use the paste key to correctly set the window target, i.e. going to raw view
10+
from Markdown view works.
11+
512

613
## 3.6.1
714

crates/wastebin_server/src/javascript/paste.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,40 @@ function copy() {
7777
}
7878

7979
function onKey(e) {
80+
if (e.keyCode == 27) {
81+
const overlay = document.getElementById("overlay");
82+
if (overlay && overlay.style.display == "block") {
83+
overlay.style.display = "none";
84+
}
85+
return;
86+
}
87+
88+
if (e.ctrlKey || e.metaKey) {
89+
return;
90+
}
91+
92+
const pasteId = document.body.dataset.pasteId;
93+
8094
if (e.key == 'n') {
8195
window.location.href = "/";
8296
}
83-
else if (e.key == 'r') {
84-
window.location.href = "/raw" + window.location.pathname;
97+
else if (e.key == 'r' && pasteId) {
98+
window.location.href = "/raw/" + pasteId;
8599
}
86100
else if (e.key == 'y') {
87101
navigator.clipboard.writeText(window.location.href);
88102
showToast("Copied URL", 1500);
89103
}
90-
else if (e.key == 'd') {
91-
window.location.href = "/dl" + window.location.pathname;
104+
else if (e.key == 'd' && pasteId) {
105+
window.location.href = "/dl/" + pasteId;
92106
}
93-
else if (e.key == 'q') {
94-
window.location.href = "/qr" + window.location.pathname;
107+
else if (e.key == 'q' && pasteId) {
108+
window.location.href = "/qr/" + pasteId;
95109
}
96110
else if (e.key == 'p') {
97111
window.location.href = window.location.href.split("?")[0];
98112
}
99-
else if (e.key == 'c' && !(e.ctrlKey || e.metaKey)) {
113+
else if (e.key == 'c') {
100114
copy();
101115
}
102116
else if (e.key == 'w') {
@@ -109,13 +123,6 @@ function onKey(e) {
109123
else if (e.key == '?') {
110124
toggleOverlay();
111125
}
112-
113-
if (e.keyCode == 27) {
114-
const overlay = document.getElementById("overlay");
115-
if (overlay && overlay.style.display == "block") {
116-
overlay.style.display = "none";
117-
}
118-
}
119126
}
120127

121128
function buildOverlay() {

crates/wastebin_server/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<noscript><link rel="stylesheet" href="{{ page.assets.css.no_js.route() }}"></noscript>
2323
{% block head %}{% endblock %}
2424
</head>
25-
<body>
25+
<body{% block body_attrs %}{% endblock %}>
2626
{% block body %}
2727
<div id="main-container">
2828
<header>

crates/wastebin_server/templates/paste.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<script defer src="{{ page.assets.paste_js.route() }}"></script>
1616
{% endblock %}
1717

18+
{% block body_attrs %} data-paste-id="{{ key }}"{% endblock %}
19+
1820
{% block nav_actions %}
1921
{% if is_available %}
2022
{% if can_delete %}

0 commit comments

Comments
 (0)