Browse Source

Send shortcut

master
morethanwords 4 years ago
parent
commit
aaff5e9948
  1. 15
      src/components/chat/input.ts
  2. 4
      src/components/inputField.ts
  3. 4
      src/components/popups/newMedia.ts
  4. 3
      src/components/sidebarLeft/tabs/generalSettings.ts
  5. 32
      src/helpers/dom.ts
  6. 4
      src/scss/partials/_selector.scss

15
src/components/chat/input.ts

@ -11,7 +11,7 @@ import apiManager from "../../lib/mtproto/mtprotoworker";
//import Recorder from '../opus-recorder/dist/recorder.min'; //import Recorder from '../opus-recorder/dist/recorder.min';
import opusDecodeController from "../../lib/opusDecodeController"; import opusDecodeController from "../../lib/opusDecodeController";
import RichTextProcessor from "../../lib/richtextprocessor"; import RichTextProcessor from "../../lib/richtextprocessor";
import { attachClickEvent, blurActiveElement, cancelEvent, cancelSelection, findUpClassName, getRichValue, getSelectedNodes, isInputEmpty, markdownTags, MarkdownType, placeCaretAtEnd } from "../../helpers/dom"; import { attachClickEvent, blurActiveElement, cancelEvent, cancelSelection, findUpClassName, getRichValue, getSelectedNodes, isInputEmpty, markdownTags, MarkdownType, placeCaretAtEnd, isSendShortcutPressed } from "../../helpers/dom";
import { ButtonMenuItemOptions } from '../buttonMenu'; import { ButtonMenuItemOptions } from '../buttonMenu';
import emoticonsDropdown from "../emoticonsDropdown"; import emoticonsDropdown from "../emoticonsDropdown";
import PopupCreatePoll from "../popups/createPoll"; import PopupCreatePoll from "../popups/createPoll";
@ -32,6 +32,7 @@ import PopupSchedule from '../popups/schedule';
import SendMenu from './sendContextMenu'; import SendMenu from './sendContextMenu';
import rootScope from '../../lib/rootScope'; import rootScope from '../../lib/rootScope';
import PopupPinMessage from '../popups/unpinMessage'; import PopupPinMessage from '../popups/unpinMessage';
import { isApple } from '../../helpers/userAgent';
const RECORD_MIN_TIME = 500; const RECORD_MIN_TIME = 500;
const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.'; const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.';
@ -560,17 +561,7 @@ export default class ChatInput {
private attachMessageInputListeners() { private attachMessageInputListeners() {
this.listenerSetter.add(this.messageInput, 'keydown', (e: KeyboardEvent) => { this.listenerSetter.add(this.messageInput, 'keydown', (e: KeyboardEvent) => {
if(e.key == 'Enter' && !isTouchSupported) { if(isSendShortcutPressed(e)) {
/* if(e.ctrlKey || e.metaKey) {
this.messageInput.innerHTML += '<br>';
placeCaretAtEnd(this.message)
return;
} */
if(e.shiftKey || e.ctrlKey || e.metaKey) {
return;
}
this.sendMessage(); this.sendMessage();
} else if(e.ctrlKey || e.metaKey) { } else if(e.ctrlKey || e.metaKey) {
this.handleMarkdownShortcut(e); this.handleMarkdownShortcut(e);

4
src/components/inputField.ts

@ -1,4 +1,4 @@
import { getRichValue } from "../helpers/dom"; import { getRichValue, isInputEmpty } from "../helpers/dom";
import { checkRTL } from "../helpers/string"; import { checkRTL } from "../helpers/string";
import RichTextProcessor from "../lib/richtextprocessor"; import RichTextProcessor from "../lib/richtextprocessor";
@ -95,7 +95,7 @@ class InputField {
// * because if delete all characters there will br left // * because if delete all characters there will br left
input.addEventListener('input', () => { input.addEventListener('input', () => {
if(!this.value.trim()) { if(isInputEmpty(input)) {
input.innerHTML = ''; input.innerHTML = '';
} }
}); });

4
src/components/popups/newMedia.ts

@ -1,6 +1,6 @@
import type Chat from "../chat/chat"; import type Chat from "../chat/chat";
import { isTouchSupported } from "../../helpers/touchSupport"; import { isTouchSupported } from "../../helpers/touchSupport";
import { calcImageInBox, placeCaretAtEnd } from "../../helpers/dom"; import { calcImageInBox, placeCaretAtEnd, isSendShortcutPressed } from "../../helpers/dom";
import InputField from "../inputField"; import InputField from "../inputField";
import PopupElement from "."; import PopupElement from ".";
import Scrollable from "../scrollable"; import Scrollable from "../scrollable";
@ -118,7 +118,7 @@ export default class PopupNewMedia extends PopupElement {
placeCaretAtEnd(this.input); placeCaretAtEnd(this.input);
} }
if(e.key == 'Enter' && !isTouchSupported) { if(isSendShortcutPressed(e)) {
this.btnConfirm.click(); this.btnConfirm.click();
} }
}; };

3
src/components/sidebarLeft/tabs/generalSettings.ts

@ -7,6 +7,7 @@ import CheckboxField from "../../checkbox";
import RadioField from "../../radioField"; import RadioField from "../../radioField";
import appStateManager from "../../../lib/appManagers/appStateManager"; import appStateManager from "../../../lib/appManagers/appStateManager";
import rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import { isApple } from "../../../helpers/userAgent";
export class RangeSettingSelector { export class RangeSettingSelector {
public container: HTMLDivElement; public container: HTMLDivElement;
@ -164,7 +165,7 @@ export default class AppGeneralSettingsTab extends SliderSuperTab {
}); });
const ctrlEnterRow = new Row({ const ctrlEnterRow = new Row({
radioField: RadioField('Send by Ctrl + Enter', 'send-shortcut', 'ctrlEnter', 'settings.sendShortcut'), radioField: RadioField(`Send by ${isApple ? '⌘' : 'Ctrl'} + Enter`, 'send-shortcut', 'ctrlEnter', 'settings.sendShortcut'),
subtitle: 'New line by Enter', subtitle: 'New line by Enter',
}); });

32
src/helpers/dom.ts

@ -3,7 +3,8 @@ import { MOUNT_CLASS_TO } from "../lib/mtproto/mtproto_config";
import RichTextProcessor from "../lib/richtextprocessor"; import RichTextProcessor from "../lib/richtextprocessor";
import ListenerSetter from "./listenerSetter"; import ListenerSetter from "./listenerSetter";
import { isTouchSupported } from "./touchSupport"; import { isTouchSupported } from "./touchSupport";
import { isSafari } from "./userAgent"; import { isSafari, isApple } from "./userAgent";
import rootScope from "../lib/rootScope";
/* export function isInDOM(element: Element, parentNode?: HTMLElement): boolean { /* export function isInDOM(element: Element, parentNode?: HTMLElement): boolean {
if(!element) { if(!element) {
@ -682,3 +683,32 @@ export function radiosHandleChange(inputs: HTMLInputElement[], onChange: (value:
}); });
}); });
} }
export function isSendShortcutPressed(e: KeyboardEvent) {
if(e.key == 'Enter' && !isTouchSupported) {
/* if(e.ctrlKey || e.metaKey) {
this.messageInput.innerHTML += '<br>';
placeCaretAtEnd(this.message)
return;
} */
if(rootScope.settings.sendShortcut === 'enter') {
if(e.shiftKey || e.ctrlKey || e.metaKey) {
return;
}
return true;
} else {
const secondaryKey = isApple ? e.metaKey : e.ctrlKey;
if(e.shiftKey || (isApple ? e.ctrlKey : e.metaKey)) {
return;
}
if(secondaryKey) {
return true;
}
}
}
return false;
}

4
src/scss/partials/_selector.scss

@ -147,9 +147,9 @@
margin: 0; margin: 0;
} }
html.is-safari & { /* html.is-safari & {
margin-right: 4px; margin-right: 4px;
} } */
} }
} }
} }

Loading…
Cancel
Save