Merge branch 'develop' into fix/6020_docker_build_failure

This commit is contained in:
Vishnu Narayanan 2022-12-06 13:31:33 +05:30 committed by GitHub
commit 04371c0197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 1 deletions

View file

@ -39,10 +39,14 @@ const TYPING_INDICATOR_IDLE_TIME = 4000;
import '@chatwoot/prosemirror-schema/src/woot-editor.css'; import '@chatwoot/prosemirror-schema/src/woot-editor.css';
import { import {
hasPressedEnterAndNotCmdOrShift,
hasPressedCommandAndEnter,
hasPressedAltAndPKey, hasPressedAltAndPKey,
hasPressedAltAndLKey, hasPressedAltAndLKey,
} from 'shared/helpers/KeyboardHelpers'; } from 'shared/helpers/KeyboardHelpers';
import eventListenerMixins from 'shared/mixins/eventListenerMixins'; import eventListenerMixins from 'shared/mixins/eventListenerMixins';
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
import { isEditorHotKeyEnabled } from 'dashboard/mixins/uiSettings';
const createState = (content, placeholder, plugins = []) => { const createState = (content, placeholder, plugins = []) => {
return EditorState.create({ return EditorState.create({
@ -58,13 +62,14 @@ const createState = (content, placeholder, plugins = []) => {
export default { export default {
name: 'WootMessageEditor', name: 'WootMessageEditor',
components: { TagAgents, CannedResponse }, components: { TagAgents, CannedResponse },
mixins: [eventListenerMixins], mixins: [eventListenerMixins, uiSettingsMixin],
props: { props: {
value: { type: String, default: '' }, value: { type: String, default: '' },
editorId: { type: String, default: '' }, editorId: { type: String, default: '' },
placeholder: { type: String, default: '' }, placeholder: { type: String, default: '' },
isPrivate: { type: Boolean, default: false }, isPrivate: { type: Boolean, default: false },
enableSuggestions: { type: Boolean, default: true }, enableSuggestions: { type: Boolean, default: true },
overrideLineBreaks: { type: Boolean, default: false },
updateSelectionWith: { type: String, default: '' }, updateSelectionWith: { type: String, default: '' },
}, },
data() { data() {
@ -208,6 +213,9 @@ export default {
keyup: () => { keyup: () => {
this.onKeyup(); this.onKeyup();
}, },
keydown: (view, event) => {
this.onKeydown(event);
},
focus: () => { focus: () => {
this.onFocus(); this.onFocus();
}, },
@ -223,6 +231,12 @@ export default {
}, },
}); });
}, },
isEnterToSendEnabled() {
return isEditorHotKeyEnabled(this.uiSettings, 'enter');
},
isCmdPlusEnterToSendEnabled() {
return isEditorHotKeyEnabled(this.uiSettings, 'cmd_enter');
},
handleKeyEvents(e) { handleKeyEvents(e) {
if (hasPressedAltAndPKey(e)) { if (hasPressedAltAndPKey(e)) {
this.focusEditorInputField(); this.focusEditorInputField();
@ -304,6 +318,24 @@ export default {
clearTimeout(this.idleTimer); clearTimeout(this.idleTimer);
} }
}, },
handleLineBreakWhenEnterToSendEnabled(event) {
if (
hasPressedEnterAndNotCmdOrShift(event) &&
this.isEnterToSendEnabled() &&
!this.overrideLineBreaks
) {
event.preventDefault();
}
},
handleLineBreakWhenCmdAndEnterToSendEnabled(event) {
if (
hasPressedCommandAndEnter(event) &&
this.isCmdPlusEnterToSendEnabled() &&
!this.overrideLineBreaks
) {
event.preventDefault();
}
},
onKeyup() { onKeyup() {
if (!this.idleTimer) { if (!this.idleTimer) {
this.$emit('typing-on'); this.$emit('typing-on');
@ -314,6 +346,14 @@ export default {
TYPING_INDICATOR_IDLE_TIME TYPING_INDICATOR_IDLE_TIME
); );
}, },
onKeydown(event) {
if (this.isEnterToSendEnabled()) {
this.handleLineBreakWhenEnterToSendEnabled(event);
}
if (this.isCmdPlusEnterToSendEnabled()) {
this.handleLineBreakWhenCmdAndEnterToSendEnabled(event);
}
},
onBlur() { onBlur() {
this.turnOffIdleTimer(); this.turnOffIdleTimer();
this.resetTyping(); this.resetTyping();

View file

@ -590,6 +590,7 @@ export default {
e.preventDefault(); e.preventDefault();
} else if (keyCode === 'enter' && this.isAValidEvent('enter')) { } else if (keyCode === 'enter' && this.isAValidEvent('enter')) {
this.onSendReply(); this.onSendReply();
e.preventDefault();
} else if ( } else if (
['meta+enter', 'ctrl+enter'].includes(keyCode) && ['meta+enter', 'ctrl+enter'].includes(keyCode) &&
this.isAValidEvent('cmd_enter') this.isAValidEvent('cmd_enter')

View file

@ -15,6 +15,7 @@
class="article-content" class="article-content"
:placeholder="$t('HELP_CENTER.EDIT_ARTICLE.CONTENT_PLACEHOLDER')" :placeholder="$t('HELP_CENTER.EDIT_ARTICLE.CONTENT_PLACEHOLDER')"
:is-format-mode="true" :is-format-mode="true"
:override-line-breaks="true"
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
@input="onContentInput" @input="onContentInput"

View file

@ -14,6 +14,10 @@ export const hasPressedCommand = e => {
return e.metaKey; return e.metaKey;
}; };
export const hasPressedEnterAndNotCmdOrShift = e => {
return isEnter(e) && !hasPressedCommand(e) && !hasPressedShift(e);
};
export const hasPressedCommandAndEnter = e => { export const hasPressedCommandAndEnter = e => {
return e.metaKey && e.keyCode === 13; return e.metaKey && e.keyCode === 13;
}; };