Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit aa5fd97

Browse files
Allow fast publish and cancel actions when previewing posts.
Addresses #1285 by adding a key handler to the preview sheet. It also put the focus on the cancel button. The result is that after entering preview with `<Ctrl/Cmd> + <Return>` ... * `<Return>` OR `<Escape>` will cancel the publish and go back to editing * `<Ctrl/Cmd> + <Return>` once more will publish the message.
1 parent d9a9176 commit aa5fd97

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/depject/message/sheet/preview.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports.create = function (api) {
4646
// allow inspecting of raw message that is about to be sent
4747
messageElement.msg = msg
4848

49+
const cancelButton = h('button -cancel', { 'ev-click': cancel }, i18n('Cancel'))
4950
return {
5051
content: [
5152
messageElement
@@ -73,8 +74,22 @@ exports.create = function (api) {
7374
])
7475
),
7576
h('button -save', { 'ev-click': publish }, i18n('Confirm')),
76-
h('button -cancel', { 'ev-click': cancel }, i18n('Cancel'))
77-
]
77+
cancelButton
78+
],
79+
onMount: () => {
80+
cancelButton.focus()
81+
},
82+
attributes: {
83+
'ev-keydown': ev => {
84+
if (ev.key === 'Enter' && (ev.ctrlKey || ev.metaKey)) {
85+
publish()
86+
ev.preventDefault()
87+
} else if (ev.key === 'Escape') {
88+
cancel()
89+
ev.preventDefault()
90+
}
91+
}
92+
}
7893
}
7994

8095
function publish () {

0 commit comments

Comments
 (0)