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:
		
							parent
							
								
									a150613b53
								
							
						
					
					
						commit
						8e08d08712
					
				
					 2 changed files with 33 additions and 22 deletions
				
			
		|  | @ -9,7 +9,7 @@ | |||
|       <ComposeContentWarning :realm :contentWarning /> | ||||
|     </div> | ||||
|   {{/if}} | ||||
|   <ComposeInput :realm :text :autoFocus /> | ||||
|   <ComposeInput :realm :text :autoFocus on:postAction="onPostAction()" /> | ||||
|   <ComposeLengthGauge :length :overLimit /> | ||||
|   <ComposeToolbar :realm :postPrivacy :media :contentWarningShown :text /> | ||||
|   <ComposeLengthIndicator :length :overLimit /> | ||||
|  | @ -188,26 +188,29 @@ | |||
|           dialogs.showComposeDialog() | ||||
|         } else { | ||||
|           // else we're actually posting a new toot | ||||
|           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) | ||||
|           this.onPostAction(); | ||||
|         } | ||||
|       }, | ||||
|       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() { | ||||
|         this.__stickyObserver = new IntersectionObserver(entries => { | ||||
|           this.set({sticky: !entries[0].isIntersecting}) | ||||
|  |  | |||
|  | @ -101,11 +101,18 @@ | |||
|       }, | ||||
|       onKeydown(e) { | ||||
|         let { keyCode } = e | ||||
|         const ctrlPressed = | ||||
|           e.getModifierState('Control') || e.getModifierState('Meta') | ||||
|         switch (keyCode) { | ||||
|           case 9: // tab | ||||
|           case 13: //enter | ||||
|             this.clickSelectedAutosuggestion(e) | ||||
|             break | ||||
|           case 13: //enter | ||||
|             const autosuggestionClicked = this.clickSelectedAutosuggestion(e) | ||||
|             if (!autosuggestionClicked && ctrlPressed) { | ||||
|               this.fire('postAction') | ||||
|             } | ||||
|             break | ||||
|           case 38: // up | ||||
|             this.incrementAutosuggestSelected(-1, e) | ||||
|             break | ||||
|  | @ -121,7 +128,7 @@ | |||
|       clickSelectedAutosuggestion(event) { | ||||
|         let autosuggestionShown = this.store.get('composeAutosuggestionShown') | ||||
|         if (!autosuggestionShown) { | ||||
|           return | ||||
|           return false | ||||
|         } | ||||
|         let type = this.store.get('composeAutosuggestionType') | ||||
|         if (type === 'account') { | ||||
|  | @ -131,6 +138,7 @@ | |||
|         } | ||||
|         event.preventDefault() | ||||
|         event.stopPropagation() | ||||
|         return true | ||||
|       }, | ||||
|       incrementAutosuggestSelected(increment, event) { | ||||
|         let autosuggestionShown = this.store.get('composeAutosuggestionShown') | ||||
|  | @ -170,4 +178,4 @@ | |||
|       selectionChange | ||||
|     } | ||||
|   } | ||||
| </script> | ||||
| </script> | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue