Fix shortcuts on non QWERTY keyboards (#715)

* Use key instead of keyCode or code

* Use key for Escape
This commit is contained in:
ginnyTheCat 2022-08-05 15:42:25 +02:00 committed by GitHub
parent 1d90f7588b
commit 5e527e434a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View file

@ -162,8 +162,8 @@ const MessageReplyWrapper = React.memo(({ roomTimeline, eventId }) => {
}, []); }, []);
const focusReply = (ev) => { const focusReply = (ev) => {
if (!ev.keyCode || ev.keyCode === 32 || ev.keyCode === 13) { if (!ev.key || ev.key === ' ' || ev.key === 'Enter') {
if (ev.keyCode) ev.preventDefault(); if (ev.key) ev.preventDefault();
if (reply?.event === null) return; if (reply?.event === null) return;
if (reply?.event.isRedacted()) return; if (reply?.event.isRedacted()) return;
roomTimeline.loadEventTimeline(eventId); roomTimeline.loadEventTimeline(eventId);
@ -277,7 +277,7 @@ function MessageEdit({ body, onSave, onCancel }) {
}, []); }, []);
const handleKeyDown = (e) => { const handleKeyDown = (e) => {
if (e.keyCode === 13 && e.shiftKey === false) { if (e.key === 'Enter' && e.shiftKey === false) {
e.preventDefault(); e.preventDefault();
onSave(editInputRef.current.value); onSave(editInputRef.current.value);
} }

View file

@ -256,11 +256,11 @@ function RoomViewCmdBar({ roomId, roomTimeline, viewEvent }) {
function listenKeyboard(event) { function listenKeyboard(event) {
const { activeElement } = document; const { activeElement } = document;
const lastCmdItem = document.activeElement.parentNode.lastElementChild; const lastCmdItem = document.activeElement.parentNode.lastElementChild;
if (event.keyCode === 27) { if (event.key === 'Escape') {
if (activeElement.className !== 'cmd-item') return; if (activeElement.className !== 'cmd-item') return;
viewEvent.emit('focus_msg_input'); viewEvent.emit('focus_msg_input');
} }
if (event.keyCode === 9) { if (event.key === 'Tab') {
if (lastCmdItem.className !== 'cmd-item') return; if (lastCmdItem.className !== 'cmd-item') return;
if (lastCmdItem !== activeElement) return; if (lastCmdItem !== activeElement) return;
if (event.shiftKey) return; if (event.shiftKey) return;

View file

@ -128,9 +128,7 @@ function RoomViewInput({
} }
function firedCmd(cmdData) { function firedCmd(cmdData) {
const msg = textAreaRef.current.value; const msg = textAreaRef.current.value;
textAreaRef.current.value = replaceCmdWith( textAreaRef.current.value = replaceCmdWith(msg, cmdCursorPos, typeof cmdData?.replace !== 'undefined' ? cmdData.replace : '');
msg, cmdCursorPos, typeof cmdData?.replace !== 'undefined' ? cmdData.replace : '',
);
deactivateCmd(); deactivateCmd();
} }
@ -254,7 +252,7 @@ function RoomViewInput({
}; };
const handleKeyDown = (e) => { const handleKeyDown = (e) => {
if (e.keyCode === 13 && e.shiftKey === false) { if (e.key === 'Enter' && e.shiftKey === false) {
e.preventDefault(); e.preventDefault();
sendMessage(); sendMessage();
} }

View file

@ -31,14 +31,14 @@ function listenKeyboard(event) {
// Ctrl/Cmd + // Ctrl/Cmd +
if (event.ctrlKey || event.metaKey) { if (event.ctrlKey || event.metaKey) {
// open search modal // open search modal
if (event.code === 'KeyK') { if (event.key === 'k') {
event.preventDefault(); event.preventDefault();
if (navigation.isRawModalVisible) return; if (navigation.isRawModalVisible) return;
openSearch(); openSearch();
} }
// focus message field on paste // focus message field on paste
if (event.code === 'KeyV') { if (event.key === 'v') {
if (navigation.isRawModalVisible) return; if (navigation.isRawModalVisible) return;
const msgTextarea = document.getElementById('message-textarea'); const msgTextarea = document.getElementById('message-textarea');
const { activeElement } = document; const { activeElement } = document;
@ -52,7 +52,7 @@ function listenKeyboard(event) {
if (!event.ctrlKey && !event.altKey && !event.metaKey) { if (!event.ctrlKey && !event.altKey && !event.metaKey) {
if (navigation.isRawModalVisible) return; if (navigation.isRawModalVisible) return;
if (event.code === 'Escape') { if (event.key === 'Escape') {
if (navigation.isRoomSettings) { if (navigation.isRoomSettings) {
toggleRoomSettings(); toggleRoomSettings();
return; return;