Submit on enter, start a new line on shift+enter

This commit is contained in:
eugenijm 2020-05-26 22:22:36 +03:00
parent 5fc9ef0bfb
commit fdef990c6a
5 changed files with 28 additions and 7 deletions

View file

@ -106,6 +106,10 @@
position: -webkit-sticky; position: -webkit-sticky;
position: sticky; position: sticky;
bottom: 0px; bottom: 0px;
textarea {
outline: none
}
} }
} }
} }

View file

@ -66,8 +66,8 @@
:disable-notice="true" :disable-notice="true"
:disable-polls="true" :disable-polls="true"
:poster="poster" :poster="poster"
:submit-on-enter="!isMobileLayout"
:preserve-focus="!isMobileLayout" :preserve-focus="!isMobileLayout"
:polls-available="false"
:auto-focus="!isMobileLayout" :auto-focus="!isMobileLayout"
:placeholder="formPlaceholder" :placeholder="formPlaceholder"
:file-limit="1" :file-limit="1"

View file

@ -162,6 +162,11 @@ const EmojiInput = {
input.elm.removeEventListener('input', this.onInput) input.elm.removeEventListener('input', this.onInput)
} }
}, },
watch: {
showSuggestions: function (newValue) {
this.$emit('shown', newValue)
}
},
methods: { methods: {
triggerShowPicker () { triggerShowPicker () {
this.showPicker = true this.showPicker = true

View file

@ -41,7 +41,8 @@ const PostStatusForm = {
'poster', 'poster',
'preserveFocus', 'preserveFocus',
'autoFocus', 'autoFocus',
'fileLimit' 'fileLimit',
'submitOnEnter'
], ],
components: { components: {
MediaUpload, MediaUpload,
@ -92,7 +93,8 @@ const PostStatusForm = {
contentType contentType
}, },
caret: 0, caret: 0,
pollFormVisible: false pollFormVisible: false,
emojiInputShown: false
} }
}, },
computed: { computed: {
@ -175,9 +177,14 @@ const PostStatusForm = {
...mapGetters(['mergedConfig']) ...mapGetters(['mergedConfig'])
}, },
methods: { methods: {
postStatus (newStatus) { postStatus (newStatus, opts = {}) {
if (this.posting) { return } if (this.posting) { return }
if (this.submitDisabled) { return } if (this.submitDisabled) { return }
if (this.emojiInputShown) { return }
if (opts.control && this.submitOnEnter) {
newStatus.status = `${newStatus.status}\n`
return
}
if (this.newStatus.status === '') { if (this.newStatus.status === '') {
if (this.newStatus.files.length === 0) { if (this.newStatus.files.length === 0) {
@ -405,6 +412,9 @@ const PostStatusForm = {
}, },
dismissScopeNotice () { dismissScopeNotice () {
this.$store.dispatch('setOption', { name: 'hideScopeNotice', value: true }) this.$store.dispatch('setOption', { name: 'hideScopeNotice', value: true })
},
handleEmojiInputShow (value) {
this.emojiInputShown = value
} }
} }
} }

View file

@ -86,6 +86,7 @@
@input="onEmojiInputInput" @input="onEmojiInputInput"
@sticker-uploaded="addMediaFile" @sticker-uploaded="addMediaFile"
@sticker-upload-failed="uploadFailed" @sticker-upload-failed="uploadFailed"
@shown="handleEmojiInputShow"
> >
<textarea <textarea
ref="textarea" ref="textarea"
@ -95,7 +96,8 @@
:disabled="posting" :disabled="posting"
class="form-post-body" class="form-post-body"
:class="{ 'scrollable-form': !!maxHeight }" :class="{ 'scrollable-form': !!maxHeight }"
@keydown.meta.enter="postStatus(newStatus)" @keydown.exact.stop.prevent.enter="submitOnEnter && postStatus(newStatus)"
@keydown.meta.enter="postStatus(newStatus, { control: true })"
@keyup.ctrl.enter="postStatus(newStatus)" @keyup.ctrl.enter="postStatus(newStatus)"
@drop="fileDrop" @drop="fileDrop"
@dragover.prevent="fileDrag" @dragover.prevent="fileDrag"
@ -214,10 +216,10 @@
</button> </button>
<button <button
v-else v-else
@touchstart.stop.prevent="postStatus(newStatus)"
@mousedown.stop.prevent="postStatus(newStatus)"
:disabled="submitDisabled" :disabled="submitDisabled"
class="btn btn-default" class="btn btn-default"
@touchstart.stop.prevent="postStatus(newStatus)"
@mousedown.stop.prevent="postStatus(newStatus)"
> >
{{ $t('general.submit') }} {{ $t('general.submit') }}
</button> </button>