diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index 1ccb3577..eea2941e 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -747,6 +747,21 @@ export default class ChatInput { this.sendMessage(); } else if(e.ctrlKey || e.metaKey) { this.handleMarkdownShortcut(e); + } else if((e.key === 'PageUp' || e.key === 'PageDown') && !e.shiftKey) { // * fix pushing page to left (Chrome Windows) + e.preventDefault(); + + if(e.key === 'PageUp') { + const range = document.createRange(); + const sel = window.getSelection(); + + range.setStart(this.messageInput.childNodes[0] || this.messageInput, 0); + range.collapse(true); + + sel.removeAllRanges(); + sel.addRange(range); + } else { + placeCaretAtEnd(this.messageInput); + } } }); diff --git a/src/lib/appManagers/appImManager.ts b/src/lib/appManagers/appImManager.ts index e476d4b2..0d22c8b1 100644 --- a/src/lib/appManagers/appImManager.ts +++ b/src/lib/appManagers/appImManager.ts @@ -429,8 +429,9 @@ export class AppImManager { private init() { document.addEventListener('paste', this.onDocumentPaste, true); + const IGNORE_KEYS = new Set(['PageUp', 'PageDown', 'Meta', 'Control']); const onKeyDown = (e: KeyboardEvent) => { - if(rootScope.overlayIsActive) return; + if(rootScope.overlayIsActive || IGNORE_KEYS.has(e.key)) return; const target = e.target as HTMLElement; @@ -440,9 +441,7 @@ export class AppImManager { const chat = this.chat; - if(e.key === 'Meta' || e.key === 'Control') { - return; - } else if(e.code === "KeyC" && (e.ctrlKey || e.metaKey) && target.tagName !== 'INPUT') { + if(e.code === 'KeyC' && (e.ctrlKey || e.metaKey) && target.tagName !== 'INPUT') { return; } else if(e.code === 'ArrowUp') { if(!chat.input.editMsgId && chat.input.isInputEmpty()) { @@ -469,10 +468,18 @@ export class AppImManager { cancelEvent(e); // * prevent from scrolling } } + } else { + return; } + } else if(e.code === 'ArrowDown') { + return; } - if(chat.input.messageInput && e.target !== chat.input.messageInput && target.tagName !== 'INPUT' && !target.hasAttribute('contenteditable') && !isTouchSupported) { + if(chat.input.messageInput && + e.target !== chat.input.messageInput && + target.tagName !== 'INPUT' && + !target.hasAttribute('contenteditable') && + !isTouchSupported) { chat.input.messageInput.focus(); placeCaretAtEnd(chat.input.messageInput); }