Browse Source

Ignore page direction buttons

Fix pushing page from view by PageUp
master
Eduard Kuzmenko 3 years ago
parent
commit
904f9df459
  1. 15
      src/components/chat/input.ts
  2. 17
      src/lib/appManagers/appImManager.ts

15
src/components/chat/input.ts

@ -747,6 +747,21 @@ export default class ChatInput { @@ -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);
}
}
});

17
src/lib/appManagers/appImManager.ts

@ -429,8 +429,9 @@ export class AppImManager { @@ -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 { @@ -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 { @@ -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);
}

Loading…
Cancel
Save