fix: ignore rapid Ctrl-Enter inputs when composing (#1488)

fixes #421
This commit is contained in:
Nolan Lawson 2019-09-15 10:45:52 -07:00 committed by GitHub
parent 35058ed965
commit d5fb6c568c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -145,7 +145,8 @@
autoFocus: false, autoFocus: false,
hideBottomBorder: false, hideBottomBorder: false,
hidden: false, hidden: false,
dialogId: undefined dialogId: undefined,
aboutToPostStatus: false
}), }),
store: () => store, store: () => store,
computed: { computed: {
@ -184,12 +185,22 @@
slide slide
}, },
methods: { methods: {
doPostStatus () { async doPostStatus () {
const { aboutToPostStatus } = this.get()
const { postingStatus } = this.store.get()
if (aboutToPostStatus || postingStatus) { // do nothing if the user rapidly taps the Ctrl-Enter key
console.log('ignored post command', { aboutToPostStatus, postingStatus })
return
}
// The reason we add a scheduleIdleTask delay here is because we also use scheduleIdleTask // The reason we add a scheduleIdleTask delay here is because we also use scheduleIdleTask
// in ComposeInput.html to debounce the input events. If the user is very fast at typing // in ComposeInput.html to debounce the input events. If the user is very fast at typing
// at their keyboard and quickly presses Ctrl+Enter or the "Toot" button then there could // at their keyboard and quickly presses Ctrl+Enter or the "Toot" button then there could
// be a race condition where not all of their status is posted. // be a race condition where not all of their status is posted.
scheduleIdleTask(() => this.doPostStatusAfterDelay()) this.set({ aboutToPostStatus: true })
scheduleIdleTask(() => {
this.set({ aboutToPostStatus: false })
this.doPostStatusAfterDelay()
})
}, },
doPostStatusAfterDelay () { doPostStatusAfterDelay () {
const { const {
@ -228,8 +239,7 @@
options: poll.options options: poll.options
} }
/* no await */ /* no await */ postStatus(realm, text, inReplyTo, mediaIds,
postStatus(realm, text, inReplyTo, mediaIds,
sensitive, contentWarning, postPrivacyKey, sensitive, contentWarning, postPrivacyKey,
mediaDescriptions, inReplyToUuid, pollToPost, mediaDescriptions, inReplyToUuid, pollToPost,
mediaFocalPoints) mediaFocalPoints)