From 20b31d577cc42337671d3941f38311907b88e055 Mon Sep 17 00:00:00 2001 From: Phillip Date: Fri, 13 Jan 2023 00:03:40 -0500 Subject: [PATCH] add enter disabled enabled --- qortal-ui-core/language/us.json | 4 +- .../plugins/core/components/ChatPage.js | 41 +++++++++++++++---- .../plugins/core/components/ChatTextEditor.js | 36 ++++++++++------ 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/qortal-ui-core/language/us.json b/qortal-ui-core/language/us.json index a293712d..bf044ecf 100644 --- a/qortal-ui-core/language/us.json +++ b/qortal-ui-core/language/us.json @@ -565,7 +565,9 @@ "cchange56": "Transaction Failed!", "cchange57": "User Info", "cchange58": "SEND MESSAGE", - "cchange59": "TIP USER" + "cchange59": "TIP USER", + "cchange60": "Enter Enabled", + "cchange61": "Enter Disabled" }, "welcomepage": { "wcchange1": "Welcome to Q-Chat", diff --git a/qortal-ui-plugins/plugins/core/components/ChatPage.js b/qortal-ui-plugins/plugins/core/components/ChatPage.js index 2d0e6aa5..6f06ec3e 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatPage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatPage.js @@ -96,7 +96,8 @@ class ChatPage extends LitElement { webWorkerImage: { type: Object }, myTrimmedMeassage: { type: String }, editor: {type: Object}, - currentEditor: {type: String} + currentEditor: {type: String}, + isEnabledChatEnter: {type: Boolean} } } @@ -824,6 +825,7 @@ class ChatPage extends LitElement { this.getOldMessage = this.getOldMessage.bind(this) this._sendMessage = this._sendMessage.bind(this) this.insertImage = this.insertImage.bind(this) + this.toggleEnableChatEnter = this.toggleEnableChatEnter.bind(this) this._downObserverhandler = this._downObserverhandler.bind(this) this.selectedAddress = {} this.chatId = '' @@ -877,12 +879,18 @@ class ChatPage extends LitElement { this.webWorkerImage = null; this.currentEditor = '_chatEditorDOM' this.initialChat = this.initialChat.bind(this) + this.isEnabledChatEnter = true } _toggle(value) { this.shifted = value === (false || true) ? value : !this.shifted; this.requestUpdate() } + + toggleEnableChatEnter(){ + localStorage.setItem('isEnabledChatEnter', !this.isEnabledChatEnter ) + this.isEnabledChatEnter = !this.isEnabledChatEnter + } render() { return html` @@ -998,6 +1006,8 @@ class ChatPage extends LitElement { .updatePlaceholder=${(editor, value)=> this.updatePlaceholder(editor, value)} id="_chatEditorDOM" .repliedToMessageObj=${this.repliedToMessageObj} + .toggleEnableChatEnter=${this.toggleEnableChatEnter} + ?isEnabledChatEnter=${this.isEnabledChatEnter} > @@ -1277,18 +1287,27 @@ class ChatPage extends LitElement { placeholder: 'Write something …', }), Extension.create({ + name: 'shortcuts', addKeyboardShortcuts:()=> { return { 'Enter': ()=> { - const chatTextEditor = this.shadowRoot.getElementById('_chatEditorDOM') - chatTextEditor.sendMessageFunc({ - }) - return true + if(this.isEnabledChatEnter){ + const chatTextEditor = this.shadowRoot.getElementById('_chatEditorDOM') + chatTextEditor.sendMessageFunc({ + }) + return true + } + }, - "Shift-Enter": () => - this.editor.commands.first(() => [ - this.editor.commands.newlineInCode() - ]), + "Shift-Enter": () => { + if(this.isEnabledChatEnter){ + this.editor.commands.first(() => [ + this.editor.commands.newlineInCode() + ]) + } + + } + } }}) @@ -1561,7 +1580,11 @@ class ChatPage extends LitElement { }) parentEpml.imReady(); + const isEnabledChatEnter = localStorage.getItem('isEnabledChatEnter') + if(isEnabledChatEnter){ + this.isEnabledChatEnter = isEnabledChatEnter === 'false' ? false : true + } await this.initUpdate() } diff --git a/qortal-ui-plugins/plugins/core/components/ChatTextEditor.js b/qortal-ui-plugins/plugins/core/components/ChatTextEditor.js index e1f76dae..53d86d5d 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatTextEditor.js +++ b/qortal-ui-plugins/plugins/core/components/ChatTextEditor.js @@ -1,5 +1,5 @@ import { LitElement, html, css } from "lit"; -import { get } from 'lit-translate'; +import { get, translate } from 'lit-translate'; import { EmojiPicker } from 'emoji-picker-js'; import { Epml } from '../../../epml.js'; @@ -27,7 +27,9 @@ class ChatTextEditor extends LitElement { theme: { type: String, reflect: true - } + }, + toggleEnableChatEnter: {attribute: false}, + isEnabledChatEnter: {type: Boolean} } } @@ -387,30 +389,40 @@ class ChatTextEditor extends LitElement { } class=${["chatbar-button-single", (this.editedMessageObj || this.repliedToMessageObj) && 'show-chatbar-buttons', this.editor && this.editor.isActive('italic') ? 'is-active' : ''].join(' ')} > - - + + + +