send status on ctrl+enter (#81)

* send status on ctrl+enter (#24)

* don't check for floating post button when pressing ctrl+enter

oops, I was too eager. it doesn't matter too much, except that if the
main compose form is off-screen but still focused, ctrl+enter would open
the compose modal instead of posting
This commit is contained in:
codl 2018-04-12 05:01:17 +02:00 committed by Nolan Lawson
parent a150613b53
commit 8e08d08712
2 changed files with 33 additions and 22 deletions

View file

@ -9,7 +9,7 @@
<ComposeContentWarning :realm :contentWarning /> <ComposeContentWarning :realm :contentWarning />
</div> </div>
{{/if}} {{/if}}
<ComposeInput :realm :text :autoFocus /> <ComposeInput :realm :text :autoFocus on:postAction="onPostAction()" />
<ComposeLengthGauge :length :overLimit /> <ComposeLengthGauge :length :overLimit />
<ComposeToolbar :realm :postPrivacy :media :contentWarningShown :text /> <ComposeToolbar :realm :postPrivacy :media :contentWarningShown :text />
<ComposeLengthIndicator :length :overLimit /> <ComposeLengthIndicator :length :overLimit />
@ -188,26 +188,29 @@
dialogs.showComposeDialog() dialogs.showComposeDialog()
} else { } else {
// else we're actually posting a new toot // else we're actually posting a new toot
let text = this.get('text') this.onPostAction();
let media = this.get('media')
let postPrivacyKey = this.get('postPrivacyKey')
let contentWarning = this.get('contentWarning')
let sensitive = media.length && !!contentWarning
let realm = this.get('realm')
let mediaIds = media.map(_ => _.data.id)
let inReplyTo = (realm === 'home' || realm === 'dialog') ? null : realm
let overLimit = this.get('overLimit')
let mediaDescriptions = this.get('mediaDescriptions')
if (!text || overLimit) {
return // do nothing if invalid
}
/* no await */
postStatus(realm, text, inReplyTo, mediaIds,
sensitive, contentWarning, postPrivacyKey, mediaDescriptions)
} }
}, },
onPostAction() {
let text = this.get('text')
let media = this.get('media')
let postPrivacyKey = this.get('postPrivacyKey')
let contentWarning = this.get('contentWarning')
let sensitive = media.length && !!contentWarning
let realm = this.get('realm')
let mediaIds = media.map(_ => _.data.id)
let inReplyTo = (realm === 'home' || realm === 'dialog') ? null : realm
let overLimit = this.get('overLimit')
let mediaDescriptions = this.get('mediaDescriptions')
if (!text || overLimit) {
return // do nothing if invalid
}
/* no await */
postStatus(realm, text, inReplyTo, mediaIds,
sensitive, contentWarning, postPrivacyKey, mediaDescriptions)
},
setupStickyObserver() { setupStickyObserver() {
this.__stickyObserver = new IntersectionObserver(entries => { this.__stickyObserver = new IntersectionObserver(entries => {
this.set({sticky: !entries[0].isIntersecting}) this.set({sticky: !entries[0].isIntersecting})

View file

@ -101,11 +101,18 @@
}, },
onKeydown(e) { onKeydown(e) {
let { keyCode } = e let { keyCode } = e
const ctrlPressed =
e.getModifierState('Control') || e.getModifierState('Meta')
switch (keyCode) { switch (keyCode) {
case 9: // tab case 9: // tab
case 13: //enter
this.clickSelectedAutosuggestion(e) this.clickSelectedAutosuggestion(e)
break break
case 13: //enter
const autosuggestionClicked = this.clickSelectedAutosuggestion(e)
if (!autosuggestionClicked && ctrlPressed) {
this.fire('postAction')
}
break
case 38: // up case 38: // up
this.incrementAutosuggestSelected(-1, e) this.incrementAutosuggestSelected(-1, e)
break break
@ -121,7 +128,7 @@
clickSelectedAutosuggestion(event) { clickSelectedAutosuggestion(event) {
let autosuggestionShown = this.store.get('composeAutosuggestionShown') let autosuggestionShown = this.store.get('composeAutosuggestionShown')
if (!autosuggestionShown) { if (!autosuggestionShown) {
return return false
} }
let type = this.store.get('composeAutosuggestionType') let type = this.store.get('composeAutosuggestionType')
if (type === 'account') { if (type === 'account') {
@ -131,6 +138,7 @@
} }
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return true
}, },
incrementAutosuggestSelected(increment, event) { incrementAutosuggestSelected(increment, event) {
let autosuggestionShown = this.store.get('composeAutosuggestionShown') let autosuggestionShown = this.store.get('composeAutosuggestionShown')